在GLIBC里查找系统调用

有些系统调用在GLIBC里是找不到相应的函数的. 这一类函数会按照 sysdeps/unix/syscall-template.S 里的参数要求在 sysdeps/unix/syscall.S里定义每一个系统调用. 编译的时候,sysdev/unix/make-syscalls.sh 会根据上面的文件生成每个函数的汇编代码到 glibc库里面.

比如, 如果查看 mmap 的反汇编)(MIPS),你会看到:

(gdb) disass mmap
Dump of assembler code for function mmap:
   0x77f3107c <+0>:	lui	gp,0xa
   0x77f31080 <+4>:	addiu	gp,gp,-29292
   0x77f31084 <+8>:	addu	gp,gp,t9
   0x77f31088 <+12>:	li	v0,4090
   0x77f3108c <+16>:	syscall
   0x77f31090 <+20>:	bnez	a3,0x77f31070
   0x77f31094 <+24>:	nop
   0x77f31098 <+28>:	jr	ra
   0x77f3109c <+32>:	nop
   0x77f310a0 <+36>:	nop
查看  mmap的源码:

(gdb) list mmap
76	#else
77	
78	/* This is a "normal" system call stub: if there is an error,
79	   it returns -1 and sets errno.  */
80	
81	T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
82		ret
83	T_PSEUDO_END (SYSCALL_SYMBOL)
84	
85	#endif
../sysdeps/unix/syscall-template.S:82

其中, T_PSEUDO定义为:

# define PSEUDO(name, syscall_name, args)                     \
  .align 2;                                   \
  99: la t9,__syscall_error;                              \
  jr t9;                                      \
  ENTRY (name)                                    \
    .set noreorder;                               \
    .cpload t9;                                   \
    .set reorder;                                 \
    SINGLE_THREAD_P(t0);                              \
    bne zero, t0, L(pseudo_cancel);                       \
    .set noreorder;                               \
    li v0, SYS_ify(syscall_name);                         \
    syscall;                                      \
    .set reorder;                                 \
    bne a3, zero, SYSCALL_ERROR_LABEL;                            \
    ret;                                      \

基本上和前面的反汇编代码是一致的.


你可能感兴趣的:(在GLIBC里查找系统调用)