Re: sbrk vs mmap (FreeBSD)
- From: Chewy509@xxxxxxxxxxxxxxxx
- Date: 16 Nov 2006 17:43:57 -0800
T.M. Sommers wrote:
Chewy509 wrote:
I'm having some issues with rewriting a simple malloc() function to be
with FreeBSD (AMD64). This is part of porting an application from Linux
to FreeBSD.
After pulling my hair out for a while, I've found that the sbrk()
system call just returns "45 - Operation Not Supported" error,
irrespective of the parameters passed to it. (I can't locate the actual
kernel source file that does the actual implementation of sbrk(), so a
pointer to the source file would be great - one of the benefits of Open
Source(tm) is having the source, but it's useless if you can't find the
source file your after! j/k).
sbrk() is not part of POSIX, so who knows what it does. I would
suggest looking at the source of malloc() in libc to see what it
does.
The source for the sbrk kernel function is in
/usr/src/sys/kern/vm/vm_mmap.c, and as you found it just returns
an error code. If you disassemble the sbrk() function in libc,
it uses syscall number 0x11, which is called break. The kernel
function used by this syscall is obreak, in .../vm/vm_unix.c.
You really should be using malloc (or mmap, as you mentioned
later), since it is the real, documented, official POSIX memory
allocation interface. It also has the advantage of being portable.
Hi Thomas,
Thanks for the info (esp the source file location). My preferred option
is to use mmap() (as per the FreeBSD kernel maintainers advice), but
can't work why my call is failing... guess I'll hunt through the source
to find out why.
How come I'm not using libc? Well, I have and do. The app is currently
portable to Windows x64, Linux, Solaris and now working on FreeBSD. The
Solaris, Linux and FreeBSD versions can use libc for OS calls
(different build option via a #define)... But am working on porting the
app so that it's native to the OS (Solaris and Linux already done).
Why? Because I can, and having done so, have found bugs that weren't
apparent under a single OS, or when using libc.
Seriously, porting an app to different OS's (even though most are POSIX
compatible) brings out all the bugs... And who said asm isn't portable?
PS. There are about 5 OS dependent calls that my app makes, and while
I've had no issues porting the others to different OS's the malloc()
code seems to be the most difficult.
--
Darran (aka Chewy509) brought to you by Google Groups!
.
- Follow-Ups:
- Re: sbrk vs mmap (FreeBSD)
- From: T.M. Sommers
- Re: sbrk vs mmap (FreeBSD)
- References:
- sbrk vs mmap (FreeBSD)
- From: Chewy509
- Re: sbrk vs mmap (FreeBSD)
- From: T.M. Sommers
- sbrk vs mmap (FreeBSD)
- Prev by Date: Re: NGs
- Next by Date: Re: sbrk vs mmap (FreeBSD)
- Previous by thread: Re: sbrk vs mmap (FreeBSD)
- Next by thread: Re: sbrk vs mmap (FreeBSD)
- Index(es):
Relevant Pages
|
|