Is mmap a built in function?

北战南征 提交于 2019-12-07 16:40:58

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/10684381/is-mmap-a-built-in-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!