⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux_syscall_support.h

📁 能把所有线程的数据和环境记录到文件,方便调试.
💻 H
📖 第 1 页 / 共 4 页
字号:
                          type5 arg5) {                                       \          long __res;                                                         \          __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; syscall" :       \            "=a" (__res) : "0" (__NR_##name),                                 \            "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)),       \            "g" ((long)(arg4)), "g" ((long)(arg5)) :                          \            "r8", "r10", "r11", "rcx", "memory");                             \          LSS_RETURN(type, __res);                                            \      }    #undef _syscall6    #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \                      type5,arg5,type6,arg6)                                  \      type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \                          type5 arg5, type6 arg6) {                           \          long __res;                                                         \          __asm__ __volatile__("movq %5,%%r10; movq %6,%%r8; movq %7,%%r9;"   \                               "syscall" :                                    \            "=a" (__res) : "0" (__NR_##name),                                 \            "D" ((long)(arg1)), "S" ((long)(arg2)), "d" ((long)(arg3)),       \            "g" ((long)(arg4)), "g" ((long)(arg5)), "g" ((long)(arg6)) :      \            "r8", "r9", "r10", "r11", "rcx", "memory");                       \          LSS_RETURN(type, __res);                                            \      }    LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,                                   int flags, void *arg, int *parent_tidptr,                                   void *newtls, int *child_tidptr) {      long __res;      {        register void *__tls  __asm__("r8")  = newtls;        register int  *__ctid __asm__("r10") = child_tidptr;        __asm__ __volatile__(/* if (fn == NULL)                              *   return -EINVAL;                              */                             "testq  %4,%4\n"                             "jz     1f\n"                             /* if (child_stack == NULL)                              *   return -EINVAL;                              */                             "testq  %5,%5\n"                             "jz     1f\n"                             /* childstack -= 2*sizeof(void *);                              */                             "subq   $16,%5\n"                             /* Push "arg" and "fn" onto the stack that will be                              * used by the child.                              */                             "movq   %7,8(%5)\n"                             "movq   %4,0(%5)\n"                             /* %rax = syscall(%rax = __NR_clone,                              *                %rdi = flags,                              *                %rsi = child_stack,                              *                %rdx = parent_tidptr,                              *                %r8  = new_tls,                              *                %r10 = child_tidptr)                              */                             "movq   %2,%%rax\n"                             "syscall\n"                             /* if (%rax != 0)                              *   return;                              */                             "testq  %%rax,%%rax\n"                             "jnz    1f\n"                             /* In the child. Terminate frame pointer chain.                              */                             "xorq   %%rbp,%%rbp\n"                             /* Call "fn(arg)".                              */                             "popq   %%rax\n"                             "popq   %%rdi\n"                             "call   *%%rax\n"                             /* Call _exit(%ebx).                              */                             "movq   %%rax,%%rdi\n"                             "movq   %3,%%rax\n"                             "syscall\n"                             /* Return to parent.                              */                           "1:\n"                             : "=a" (__res)                             : "0"(-EINVAL), "i"(__NR_clone), "i"(__NR_exit),                               "r"(fn), "S"(child_stack), "D"(flags), "r"(arg),                               "d"(parent_tidptr), "r"(__tls), "r"(__ctid)                             : "memory", "r11", "rcx");      }      LSS_RETURN(int, __res);    }  #elif defined(__ARM_ARCH_3__)    /* Most definitions of _syscallX() neglect to mark "memory" as being     * clobbered. This causes problems with compilers, that do a better job     * at optimizing across __asm__ calls.     * So, we just have to redefine all fo the _syscallX() macros.     */    #undef LSS_REG    #define LSS_REG(r,a) register long __r##r __asm__("r"#r) = (long)a    #undef  LSS_BODY    #define LSS_BODY(type,name,args...)                                       \          register long __res_r0 __asm__("r0");                               \          long __res;                                                         \          __asm__ __volatile__ (__syscall(name)                               \                                : "=r"(__res_r0) : args : "lr", "memory");    \          __res = __res_r0;                                                   \          LSS_RETURN(type, __res)    #undef _syscall0    #define _syscall0(type, name)                                             \      type LSS_NAME(name)() {                                                 \        LSS_BODY(type, name);                                                 \      }    #undef _syscall1    #define _syscall1(type, name, type1, arg1)                                \      type LSS_NAME(name)(type1 arg1) {                                       \        LSS_REG(0, arg1); LSS_BODY(type, name, "r"(__r0));                    \      }    #undef _syscall2    #define _syscall2(type, name, type1, arg1, type2, arg2)                   \      type LSS_NAME(name)(type1 arg1, type2 arg2) {                           \        LSS_REG(0, arg1); LSS_REG(1, arg2);                                   \        LSS_BODY(type, name, "r"(__r0), "r"(__r1));                           \      }    #undef _syscall3    #define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)      \      type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3) {               \        LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \        LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2));                \      }    #undef _syscall4    #define _syscall4(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4)  \      type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4) {   \        LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \        LSS_REG(3, arg4);                                                     \        LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3));     \      }    #undef _syscall5    #define _syscall5(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \                      type5,arg5)                                             \      type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \                          type5 arg5) {                                       \        LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \        LSS_REG(3, arg4); LSS_REG(4, arg5);                                   \        LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \                             "r"(__r4));                                      \      }    #undef _syscall6    #define _syscall6(type,name,type1,arg1,type2,arg2,type3,arg3,type4,arg4,  \                      type5,arg5,type6,arg6)                                  \      type LSS_NAME(name)(type1 arg1, type2 arg2, type3 arg3, type4 arg4,     \                          type5 arg5, type6 arg6) {                           \        LSS_REG(0, arg1); LSS_REG(1, arg2); LSS_REG(2, arg3);                 \        LSS_REG(3, arg4); LSS_REG(4, arg5); LSS_REG(5, arg6);                 \        LSS_BODY(type, name, "r"(__r0), "r"(__r1), "r"(__r2), "r"(__r3),      \                             "r"(__r4), "r"(__r5));                           \      }    LSS_INLINE int LSS_NAME(clone)(int (*fn)(void *), void *child_stack,                                   int flags, void *arg, int *parent_tidptr,                                   void *newtls, int *child_tidptr) {      long __res;      {        register int   __flags __asm__("r0") = flags;        register void *__stack __asm__("r1") = child_stack;        register void *__ptid  __asm__("r2") = parent_tidptr;        register void *__tls   __asm__("r3") = newtls;        register int  *__ctid  __asm__("r4") = child_tidptr;        __asm__ __volatile__(/* if (fn == NULL || child_stack == NULL)                              *   return -EINVAL;                              */                             "cmp   %2,#0\n"                             "cmpne %3,#0\n"                             "moveq %0,%1\n"                             "beq   1f\n"                             /* Push "arg" and "fn" onto the stack that will be                              * used by the child.                              */                             "str   %5,[%3,#-4]!\n"                             "str   %2,[%3,#-4]!\n"                             /* %r0 = syscall(%r0 = flags,                              *               %r1 = child_stack,                              *               %r2 = parent_tidptr,                              *               %r3 = newtls,                              *               %r4 = child_tidptr)                              */                             __syscall(clone)"\n"                             /* if (%r0 != 0)                              *   return %r0;                              */                             "movs  r0,r0\n"                             "bne   1f\n"                             /* In the child, now. Call "fn(arg)".                              */                             "ldr   r0,[sp, #4]\n"                             "mov   lr,pc\n"                             "ldr   pc,[sp]\n"                             /* Call _exit(%r0).                              */                             __syscall(exit)"\n"                           "1:\n"                             : "=r" (__res)                             : "i"(-EINVAL),                               "r"(fn), "r"(__stack), "r"(__flags), "r"(arg),                               "r"(__ptid), "r"(__tls), "r"(__ctid)                             : "lr", "memory");      }      LSS_RETURN(int, __res);    }  #endif  #define __NR__exit   __NR_exit  #define __NR__gettid __NR_gettid  LSS_INLINE _syscall1(int,     chdir,           const char *,p)  LSS_INLINE _syscall1(int,     close,           int,         f)  LSS_INLINE _syscall1(int,     dup,             int,         f)  LSS_INLINE _syscall2(int,     dup2,            int,         s,                       int,            d)  LSS_INLINE _syscall3(int,     execve,          const char*, f,                       const char*const*,a,const char*const*, e)  LSS_INLINE _syscall1(int,     _exit,           int,         e)  LSS_INLINE _syscall3(int,     fcntl,           int,         f,                       int,            c, long,   a)  LSS_INLINE _syscall0(pid_t,   fork)  LSS_INLINE _syscall2(int,     fstat,           int,         f,                       struct stat*,   b)  LSS_INLINE _syscall4(int,     futex,           int*,        a,                       int,            o, int,    v, struct timespec *, t)  LSS_INLINE _syscall3(int,     getdents,        int,         f,                       struct dirent*, d, int,    c)  LSS_INLINE _syscall3(int,     getdents64,      int,         f,                       struct dirent64*, d, int,    c)  LSS_INLINE _syscall0(gid_t,   getegid)  LSS_INLINE _syscall0(uid_t,   geteuid)  LSS_INLINE _syscall0(pid_t,   getpgrp)  LSS_INLINE _syscall0(pid_t,   getpid)  LSS_INLINE _syscall0(pid_t,   getppid)  LSS_INLINE _syscall2(int,     getpriority,     int,         a,                       int,            b)  LSS_INLINE _syscall2(int,     getrlimit,       int,         r,                       struct rlimit*, l)  LSS_INLINE _syscall1(pid_t,   getsid,          pid_t,       p)  LSS_INLINE _syscall0(pid_t,   _gettid)  LSS_INLINE _syscall2(int,     kill,            pid_t,       p,                       int,            s)  LSS_INLINE _syscall3(off_t,   lseek,           int,         f,                       off_t,          o, int,    w)  LSS_INLINE _syscall2(int,     munmap,          void*,       s,                       size_t,         l)  LSS_INLINE _syscall4(void*,   mremap,          void*,       o,                       size_t,         os,       size_t,      ns,                       unsigned long,  f)  LSS_INLINE _syscall3(int,     open,            const char*, p,                       int,            f, int,    m)  LSS_INLINE _syscall1(int,     pipe,            int*,        p)  LSS_INLINE _syscall3(int,     poll,            struct pollfd*, u,                       unsigned int,   n, int,    t)  LSS_INLINE _syscall2(int,     prctl,           int,         o,                       long,           a)  LSS_INLINE _syscall4(long,    ptrace,          int,         r,                       pid_t,          p, void *, a, void *, d)  LSS_INLINE _syscall3(ssize_t, read,            int,         f,                       void *,         b, size_t, c)  LSS_INLINE _syscall3(int,     readlink,        const char*, p,                       char*,          b, size_t, s)  LSS_INLINE _syscall3(int,     sched_getaffinity,pid_t,      p,                       unsigned int,   l, unsigned long *, m)  LSS_INLINE _syscall3(int,     sched_setaffinity,pid_t,      p,                       unsigned int,   l, unsigned long *, m)  LSS_INLINE _syscall0(int,     sched_yield)  LSS_INLINE _syscall1(long,    set_tid_address, int *,       t)  LSS_INLINE _syscall1(int,     setfsgid,        gid_t,       g)  LSS_INLINE _syscall1(int,     setfsuid,        uid_t,       u)  LSS_INLINE _syscall2(int,     setpgid,         pid_t,       p,                       pid_t,          g)  LSS_INLINE _syscall3(int,     setpriority,     int,         a,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -