.text .globl __darling_mach_syscall .private_extern __darling_mach_syscall #if defined(__x86_64__) __darling_mach_syscall: cmpl $0, %eax jnl Lpositive negl %eax Lpositive: Lentry_hook: .space 13, 0x90 movq ___mach_syscall_table@GOTPCREL(%rip), %r10 movq (%r10,%rax,8), %r10 test %r10, %r10 jz .no_sys # Re-push possible 7th and 8th arg movq 24(%rsp), %r11 pushq %r11 movq 24(%rsp), %r11 pushq %r11 call *%r10 addq $16, %rsp .std_ret: Lexit_hook: .space 13, 0x90 ret .no_sys: movq %rax, %rdi call ___unknown_mach_syscall jmp .std_ret .section __DATA,__data .globl __darling_mach_syscall_entry .globl __darling_mach_syscall_exit __darling_mach_syscall_entry: .quad Lentry_hook __darling_mach_syscall_exit: .quad Lexit_hook #elif defined(__i386__) #define copy_arg(off) \ movl 8+off(%esp), %ecx ;\ movl %ecx, -32+off(%esp) __darling_mach_syscall: cmpl $0, %eax jnl Lpositive negl %eax Lpositive: Lentry_hook: .space 6, 0x90 calll 1f 1: popl %ecx 2: movl L___mach_syscall_table$non_lazy_ptr-1b(%ecx), %ecx andl $0xffff, %eax // Because there is some extra stuff in upper bytes we don't need movl (%ecx,%eax,4), %eax test %eax, %eax jz .no_sys // Copy arguments copy_arg(0) copy_arg(4) copy_arg(8) copy_arg(12) copy_arg(16) copy_arg(20) copy_arg(24) copy_arg(28) subl $32, %esp call *%eax addl $32, %esp .std_ret: Lexit_hook: .space 6, 0x90 ret .no_sys: pushl %ecx call ___unknown_mach_syscall addl $4, %esp jmp .std_ret .section __IMPORT,__pointers,non_lazy_symbol_pointers L___mach_syscall_table$non_lazy_ptr: .indirect_symbol ___mach_syscall_table .long 0 .section __DATA,__data .globl __darling_mach_syscall_entry .globl __darling_mach_syscall_exit __darling_mach_syscall_entry: .long Lentry_hook __darling_mach_syscall_exit: .long Lexit_hook .subsections_via_symbols #else # error Missing assembly #endif