Mmap source

I'm new to kernels and C, and I am tinkering around trying to understand OpenBSD's secure memory management. I'm stumped on a couple points.

I've read up on malloc() which was apparently modified years ago to allocate memory using mmap. First question, that would be this here, right?

map_pages(size_t pages)
{
struct pdinfo *pi, *spi;
struct pginfo **pd;
u_long pidx,lidx;
void *result, *tail;
u_long index;

pages <<=malloc_pageshift;
result = MMAP(pages + malloc_guard);

For the life of me, I can't track down source code for mmap(). I know that this is a kernel system call, but where is that source? In particular, I'm interested to see how mmap() now returns a randomized location in memory.

I'll simplify my question. Can anyone direct me to the mmap code in the kernel?

Thanks.

I am not familiar with the source tree for openBSD however that MMAP call may be a macro. If you've downloaded the source tree for openbsd maye there is a macro sub-directory or you can use the hammer approach and do something like

find <directory-where-src-is> -xdev -exec egrep -l MMAP {} \;

The mmap kernel syscall implementation is in src/sys/uvm/uvm_mmap.c and the mmap syscall libc wrapper is in src/lib/libc/sys/mmap.c

Regards,
Alister

1 Like

Thanks for the help. Just what I needed.

1 Like