Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is mmap a built in function?

Tags:

c

linux

gcc

gdb

glibc

I know that mmap is a system call, but there must be some wrapper in glibc that does the system call. Yet when I try to use gdb to step through the mmap function in my program, gdb ignores it as it can't find any source file for it (Note I compile my own glibc from source). I can step through other glibc library functions such as printf and malloc but not mmap. I also use the flag -fno-builtin so that gcc doesn't use built in functions. Any help on this will be greatly appreciated.

like image 862
pythonic Avatar asked Mar 05 '26 16:03

pythonic


1 Answers

I don't know what your problem is. It works perfectly fine for me.

Using system libc.so.6, with debug symbols installed:

// mmap.c
#include <sys/mman.h>

int main()
{
  void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
  return 0;
}

gcc -g mmap.c


$ gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40052c: file mmap.c, line 5.

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82      ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:83
83      in ../sysdeps/unix/syscall-template.S
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q

Using my own glibc build:

gdb -q a.out
Reading symbols from /tmp/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x40056c: file mmap.c, line 5.
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?

Temporary breakpoint 1, main () at mmap.c:5
5         void *p = mmap(0, 4096, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
(gdb) step
mmap64 () at ../sysdeps/unix/syscall-template.S:81
81      T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
(gdb) 
mmap64 () at ../sysdeps/unix/syscall-template.S:82
82              ret
(gdb) 
main () at mmap.c:6
6         return 0;
(gdb) q
like image 87
Employed Russian Avatar answered Mar 07 '26 09:03

Employed Russian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!