this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[xtrace] Add support for i386

+81 -5
+2 -2
src/kernel/emulation/linux/mach/darling_mach_syscall.S
··· 51 51 negl %eax 52 52 Lpositive: 53 53 Lentry_hook: 54 - .space 6, 0x90 54 + .space 7, 0x90 55 55 calll 1f 56 56 1: 57 57 popl %ecx ··· 82 82 addl $56, %esp 83 83 .std_ret: 84 84 Lexit_hook: 85 - .space 6, 0x90 85 + .space 7, 0x90 86 86 ret 87 87 .no_sys: 88 88 pushl %ecx
+2 -2
src/kernel/emulation/linux/syscalls-table.S
··· 43 43 44 44 __darling_bsd_syscall: 45 45 Lentry_hook: 46 - .space 6, 0x90 46 + .space 7, 0x90 47 47 calll 1f 48 48 1: 49 49 popl %ecx ··· 73 73 addl $56, %esp 74 74 .std_ret: 75 75 Lexit_hook: 76 - .space 6, 0x90 76 + .space 7, 0x90 77 77 ret 78 78 .no_sys: 79 79 pushl %ecx
-1
src/xtrace/CMakeLists.txt
··· 21 21 ) 22 22 23 23 if (TARGET_x86_64) 24 - set(DARLING_LIB_64BIT_ONLY TRUE) 25 24 set(DYLIB_INSTALL_NAME "/usr/lib/darling/libxtrace.dylib") 26 25 add_darling_library(xtracelib SHARED ${xtrace_sources}) 27 26 set_target_properties(xtracelib PROPERTIES OUTPUT_NAME "xtrace")
+5
src/xtrace/bsd_trace.cpp
··· 1057 1057 extern "C" 1058 1058 void darling_bsd_syscall_entry_print(int nr, void* args[]) 1059 1059 { 1060 + #if __i386__ 1061 + // get rid of some info in the upper bytes that we don't need 1062 + nr = (int)((unsigned int)nr & 0xffff); 1063 + #endif 1064 + 1060 1065 handle_generic_entry(bsd_defs, "bsd", nr, args); 1061 1066 1062 1067 if (nr == 1 || nr == 59)
+5
src/xtrace/mach_trace.cpp
··· 209 209 extern "C" 210 210 void darling_mach_syscall_entry_print(int nr, void* args[]) 211 211 { 212 + #if __i386__ 213 + // get rid of some info in the upper bytes that we don't need 214 + nr = (int)((unsigned int)nr & 0xffff); 215 + #endif 216 + 212 217 set_mach_call_nr(nr); 213 218 handle_generic_entry(mach_defs, "mach", nr, args); 214 219 if (nr == 31 || nr == 32)
+50
src/xtrace/trampoline.S
··· 1 + #if defined(__x86_64__) 2 + 1 3 .macro trampoline_enter 2 4 pushq %rbp 3 5 movq %rsp, %rbp ··· 40 42 leave 41 43 ret 42 44 .endmacro 45 + 46 + #elif defined(__i386__) 47 + 48 + .macro trampoline_enter 49 + pushl %ebp 50 + movl %esp, %ebp 51 + 52 + # align the stack 53 + andl $$~15, %esp 54 + 55 + #define copy_arg(off) \ 56 + movl 16+off(%ebp), %ecx ;\ 57 + movl %ecx, -56+off(%esp) 58 + 59 + // copy the arguments (same as in syscalls-table.S and darling_mach_syscall.S) 60 + copy_arg(0) 61 + copy_arg(4) 62 + copy_arg(8) 63 + copy_arg(12) 64 + copy_arg(16) 65 + copy_arg(20) 66 + copy_arg(24) 67 + copy_arg(28) 68 + copy_arg(32) 69 + copy_arg(36) 70 + copy_arg(40) 71 + copy_arg(44) 72 + copy_arg(48) 73 + copy_arg(52) 74 + 75 + # make space on the stack now for the arguments we just copied 76 + subl $$56, %esp 77 + 78 + # push the address of the argument area as the second argument 79 + pushl %esp 80 + 81 + # push the call number or return value as the first argument 82 + pushl %eax 83 + .endmacro 84 + 85 + .macro trampoline_leave 86 + # restore eax (i.e. the call number or return value) 87 + popl %eax 88 + leave 89 + ret 90 + .endmacro 91 + 92 + #endif 43 93 44 94 .private_extern _darling_mach_syscall_entry_trampoline 45 95 _darling_mach_syscall_entry_trampoline:
+17
src/xtrace/xtracelib.c
··· 35 35 uint8_t call[3]; 36 36 } 37 37 __attribute__((packed)); 38 + #elif defined(__i386__) 39 + struct hook { 40 + uint8_t mov; 41 + uint32_t addr; 42 + uint8_t call[2]; 43 + } __attribute__((packed)); 38 44 #endif 39 45 40 46 // Defined in libsystem_kernel ··· 142 148 143 149 static void setup_hook(struct hook* hook, void* fnptr, bool jump) 144 150 { 151 + #if defined(__x86_64__) 145 152 // this hook is (in GAS syntax): 146 153 // movq $<fnptr value>, %r10 147 154 // call *%r10 ··· 152 159 hook->call[1] = 0xff; 153 160 hook->call[2] = jump ? 0xe2 : 0xd2; 154 161 hook->addr = (uintptr_t)fnptr; 162 + #elif defined(__i386__) 163 + // this hook is (in GAS syntax): 164 + // mov $<fnptr value>, %ecx 165 + // call *%ecx 166 + // the call turns into a jump if `jump` is true 167 + hook->mov = 0xb9; 168 + hook->addr = (uintptr_t)fnptr; 169 + hook->call[0] = 0xff; 170 + hook->call[1] = jump ? 0xe1 : 0xd1; 171 + #endif 155 172 } 156 173 157 174 static void xtrace_setup_mach(void)