123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349 |
- #ifndef _LINUX_X86_64_SYSDEP_H
- #define _LINUX_X86_64_SYSDEP_H 1
- #include <sys/syscall.h>
- #include <common/sysdep.h>
- #ifdef __ASSEMBLER__
- #ifdef HAVE_ELF
- #define ALIGNARG(log2) 1<<log2
- #define ASM_TYPE_DIRECTIVE(name,typearg) .type name,typearg;
- #define ASM_SIZE_DIRECTIVE(name) .size name,.-name;
- #undef NO_UNDERSCORES
- #define NO_UNDERSCORES
- #else
- #define ALIGNARG(log2) log2
- #define ASM_TYPE_DIRECTIVE(name,type)
- #define ASM_SIZE_DIRECTIVE(name)
- #endif
- #define ENTRY(name) \
- ASM_GLOBAL_DIRECTIVE C_SYMBOL_NAME(name)
- ASM_TYPE_DIRECTIVE (C_SYMBOL_NAME(name),@function) \
- .align ALIGNARG(4)
- C_LABEL(name) \
- cfi_startproc
- CALL_MCOUNT
- #undef END
- #define END(name) \
- cfi_endproc
- ASM_SIZE_DIRECTIVE(name)
- #ifdef PROF
- #define CALL_MCOUNT \
- pushq %rbp
- cfi_adjust_cfa_offset(8)
- movq %rsp, %rbp
- cfi_def_cfa_register(%rbp)
- call JUMPTARGET(mcount)
- popq %rbp
- cfi_def_cfa(rsp,8)
- #else
- #define CALL_MCOUNT
- #endif
- #ifdef NO_UNDERSCORES
- #define syscall_error __syscall_error
- #define mcount _mcount
- #endif
- #define PSEUDO(name, syscall_name, args) \
- lose: \
- jmp JUMPTARGET(syscall_error) \
- .globl syscall_error
- ENTRY (name) \
- DO_CALL (syscall_name, args)
- jb lose
- #undef PSEUDO_END
- #define PSEUDO_END(name) \
- END (name)
- #undef JUMPTARGET
- #ifdef __PIC__
- #define JUMPTARGET(name) name##@PLT
- #else
- #define JUMPTARGET(name) name
- #endif
- #ifndef L
- # ifdef HAVE_ELF
- # define L(name) .L##name
- # else
- # define L(name) name
- # endif
- #endif
- #endif
- #undef SYS_ify
- #define SYS_ify(syscall_name) __NR_##syscall_name
- #if !defined __NR_pread && defined __NR_pread64
- # define __NR_pread __NR_pread64
- #endif
- #if !defined __NR_pwrite && defined __NR_pwrite64
- # define __NR_pwrite __NR_pwrite64
- #endif
- #ifndef __NR_semtimedop
- # define __NR_semtimedop 220
- #endif
- #ifdef __ASSEMBLER__
- # ifdef __PIC__
- # define SYSCALL_ERROR_LABEL 0f
- # else
- # define SYSCALL_ERROR_LABEL syscall_error
- # endif
- # undef PSEUDO
- # define PSEUDO(name, syscall_name, args) \
- .text
- ENTRY (name) \
- DO_CALL (syscall_name, args)
- cmpq $-4095, %rax
- jae SYSCALL_ERROR_LABEL
- L(pseudo_end):
- # undef PSEUDO_END
- # define PSEUDO_END(name) \
- SYSCALL_ERROR_HANDLER \
- END (name)
- # undef PSEUDO_NOERRNO
- # define PSEUDO_NOERRNO(name, syscall_name, args) \
- .text
- ENTRY (name) \
- DO_CALL (syscall_name, args)
- # undef PSEUDO_END_NOERRNO
- # define PSEUDO_END_NOERRNO(name) \
- END (name)
- # define ret_NOERRNO ret
- # undef PSEUDO_ERRVAL
- # define PSEUDO_ERRVAL(name, syscall_name, args) \
- .text
- ENTRY (name) \
- DO_CALL (syscall_name, args)
- negq %rax
- # undef PSEUDO_END_ERRVAL
- # define PSEUDO_END_ERRVAL(name) \
- END (name)
- # define ret_ERRVAL ret
- # ifndef __PIC__
- # define SYSCALL_ERROR_HANDLER
- # elif defined(RTLD_PRIVATE_ERRNO)
- # define SYSCALL_ERROR_HANDLER \
- 0: \
- leaq rtld_errno(%rip), %rcx
- xorl %edx, %edx
- subq %rax, %rdx
- movl %edx, (%rcx)
- orq $-1, %rax
- jmp L(pseudo_end)
- # elif USE___THREAD
- # ifndef NOT_IN_libc
- # define SYSCALL_ERROR_ERRNO __libc_errno
- # else
- # define SYSCALL_ERROR_ERRNO errno
- # endif
- # define SYSCALL_ERROR_HANDLER \
- 0: \
- movq SYSCALL_ERROR_ERRNO@GOTTPOFF(%rip), %rcx
- xorl %edx, %edx
- subq %rax, %rdx
- movl %edx, %fs:(%rcx)
- orq $-1, %rax
- jmp L(pseudo_end)
- # elif defined _LIBC_REENTRANT
- # define SYSCALL_ERROR_HANDLER \
- 0: \
- xorl %edx, %edx
- subq %rax, %rdx
- pushq %rdx
- cfi_adjust_cfa_offset(8)
- call __errno_location@PLT
- popq %rdx
- cfi_adjust_cfa_offset(-8)
- movl %edx, (%rax)
- orq $-1, %rax
- jmp L(pseudo_end)
- # else
- # define SYSCALL_ERROR_HANDLER \
- 0:movq errno@GOTPCREL(%RIP), %rcx
- xorl %edx, %edx
- subq %rax, %rdx
- movl %edx, (%rcx)
- orq $-1, %rax
- jmp L(pseudo_end)
- # endif
- # undef DO_CALL
- # define DO_CALL(syscall_name, args) \
- DOARGS_##args \
- movl $SYS_ify (syscall_name), %eax
- syscall
- # define DOARGS_0
- # define DOARGS_1
- # define DOARGS_2
- # define DOARGS_3
- # define DOARGS_4 movq %rcx, %r10;
- # define DOARGS_5 DOARGS_4
- # define DOARGS_6 DOARGS_5
- #endif
- #if defined NOT_IN_libc && defined IS_IN_rtld
- # ifdef __ASSEMBLER__
- # define PTR_MANGLE(reg) xorq __pointer_chk_guard_local(%rip), reg; \
- rolq $17, reg
- # define PTR_DEMANGLE(reg) rorq $17, reg; \
- xorq __pointer_chk_guard_local(%rip), reg
- # else
- # define PTR_MANGLE(reg) __asm__ ("xorq __pointer_chk_guard_local(%%rip), %0\n" \
- "rolq $17, %0" \
- : "=r" (reg) : "0" (reg))
- # define PTR_DEMANGLE(reg) __asm__ ("rorq $17, %0\n" \
- "xorq __pointer_chk_guard_local(%%rip), %0" \
- : "=r" (reg) : "0" (reg))
- # endif
- #else
- # ifdef __ASSEMBLER__
- # define PTR_MANGLE(reg) xorq %fs:POINTER_GUARD, reg; \
- rolq $17, reg
- # define PTR_DEMANGLE(reg) rorq $17, reg; \
- xorq %fs:POINTER_GUARD, reg
- # else
- # define PTR_MANGLE(var) __asm__ ("xorq %%fs:%c2, %0\n" \
- "rolq $17, %0" \
- : "=r" (var) \
- : "0" (var), \
- "i" (offsetof (tcbhead_t, \
- pointer_guard)))
- # define PTR_DEMANGLE(var) __asm__ ("rorq $17, %0\n" \
- "xorq %%fs:%c2, %0" \
- : "=r" (var) \
- : "0" (var), \
- "i" (offsetof (tcbhead_t, \
- pointer_guard)))
- # endif
- #endif
- #endif
|