Re: sbrk vs mmap (FreeBSD)
- From: "T.M. Sommers" <tms@xxxxxx>
- Date: Fri, 17 Nov 2006 06:05:49 -0500
Chewy509@xxxxxxxxxxxxxxxx wrote:
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.
I don't know the AMD64 ABI, so I can't help. I hesitate to suggest this, not meaning to give any offense, but are you sure you are sticking the right values in the right registers?
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).
My point was that malloc *is* the native memory allocation method under POSIX, which is defined in terms of its C interface. I know that I am alone in that thought on this newsgroup.
--
Thomas M. Sommers -- tms@xxxxxx -- AB2SB
.
- Follow-Ups:
- Re: sbrk vs mmap (FreeBSD)
- From: Chewy509
- Re: sbrk vs mmap (FreeBSD)
- From: rhyde
- Re: sbrk vs mmap (FreeBSD)
- References:
- sbrk vs mmap (FreeBSD)
- From: Chewy509
- Re: sbrk vs mmap (FreeBSD)
- From: T.M. Sommers
- Re: sbrk vs mmap (FreeBSD)
- From: Chewy509
- sbrk vs mmap (FreeBSD)
- Prev by Date: Re: NGs
- Next by Date: Re: NGs
- Previous by thread: Re: sbrk vs mmap (FreeBSD)
- Next by thread: Re: sbrk vs mmap (FreeBSD)
- Index(es):
Relevant Pages
|
|