wiki:LibcSystemCall

对Libc对系统调用的封装方式分析

  • glibc-2.14/sysdeps/i386/brk.h line34
    int
    __brk (void *addr)
    {
      void *__unbounded newbrk;
    
      INTERNAL_SYSCALL_DECL (err);
      newbrk = (void *__unbounded) INTERNAL_SYSCALL (brk, err, 1,
    						 __ptrvalue (addr));
    
      __curbrk = newbrk;
    
      if (newbrk < addr)
        {
          __set_errno (ENOMEM);
          return -1;
        }
    
      return 0;
    }
    weak_alias (__brk, brk)
    
    
  • glibc-2.14/sysdeps/i386/sysdep.h line416
    # define INTERNAL_SYSCALL(name, err, nr, args...) \
      ({									      \
        register unsigned int resultvar;					      \
        EXTRAVAR_##nr							      \
        asm volatile (							      \
        LOADARGS_##nr							      \
        "movl %1, %%eax\n\t"						      \
        "int $0x80\n\t"							      \
        RESTOREARGS_##nr							      \
        : "=a" (resultvar)							      \
        : "i" (__NR_##name) ASMFMT_##nr(args) : "memory", "cc");		      \
        (int) resultvar; })
    

参考资料

Last modified 6 years ago Last modified on 02/15/12 18:21:14