Re: sbrk vs mmap (FreeBSD)



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

.



Relevant Pages

  • Re: Freebsd vs. linux
    ... > Linux is only a kernel, whereas FreeBSD is a complete OS. ... > Windows-like desktop behavior are made at the expense of server ...
    (freebsd-questions)
  • Re: Newbie Experience
    ... I've only been around since FreeBSD 5.4 ... FreeBSD kernel too. ... always sunshine and linux is farts. ... in the hey day of AT&T Unix I'm ...
    (freebsd-questions)
  • Re: Review of FreeBSD 5.4
    ... but not less problems compared to FreeBSD. ... If you like to have a bleeding edge system using debian --- just go ... > the linux kernel suffers. ... When the kernel suffers, everyone who uses ...
    (comp.unix.bsd.freebsd.misc)
  • Re: FreeBSD 4.x Opteron Question
    ... the FreeBSD developers told everyone that 5.3 was da ... initially over linux not because there's a bunch of good guys on the ... My tests measure kernel performance; ... > a networking device is a key performance indicator. ...
    (freebsd-questions)
  • PLIP transmit timeouts -- any solutions?
    ... I currently have a PLIP link to an old laptop running Linux (I tried to ... install FreeBSD, but it freezes at the USB detection -- yes, I tried ... FreeBSD desktop. ... I'm running 5.1-R on the FreeBSD system and a 2.4.18 Linux kernel as is ...
    (freebsd-current)