···10571057extern "C"
10581058void darling_bsd_syscall_entry_print(int nr, void* args[])
10591059{
10601060+#if __i386__
10611061+ // get rid of some info in the upper bytes that we don't need
10621062+ nr = (int)((unsigned int)nr & 0xffff);
10631063+#endif
10641064+10601065 handle_generic_entry(bsd_defs, "bsd", nr, args);
1061106610621067 if (nr == 1 || nr == 59)
+5
src/xtrace/mach_trace.cpp
···209209extern "C"
210210void darling_mach_syscall_entry_print(int nr, void* args[])
211211{
212212+#if __i386__
213213+ // get rid of some info in the upper bytes that we don't need
214214+ nr = (int)((unsigned int)nr & 0xffff);
215215+#endif
216216+212217 set_mach_call_nr(nr);
213218 handle_generic_entry(mach_defs, "mach", nr, args);
214219 if (nr == 31 || nr == 32)
+50
src/xtrace/trampoline.S
···11+#if defined(__x86_64__)
22+13.macro trampoline_enter
24pushq %rbp
35movq %rsp, %rbp
···4042leave
4143ret
4244.endmacro
4545+4646+#elif defined(__i386__)
4747+4848+.macro trampoline_enter
4949+pushl %ebp
5050+movl %esp, %ebp
5151+5252+# align the stack
5353+andl $$~15, %esp
5454+5555+#define copy_arg(off) \
5656+ movl 16+off(%ebp), %ecx ;\
5757+ movl %ecx, -56+off(%esp)
5858+5959+// copy the arguments (same as in syscalls-table.S and darling_mach_syscall.S)
6060+copy_arg(0)
6161+copy_arg(4)
6262+copy_arg(8)
6363+copy_arg(12)
6464+copy_arg(16)
6565+copy_arg(20)
6666+copy_arg(24)
6767+copy_arg(28)
6868+copy_arg(32)
6969+copy_arg(36)
7070+copy_arg(40)
7171+copy_arg(44)
7272+copy_arg(48)
7373+copy_arg(52)
7474+7575+# make space on the stack now for the arguments we just copied
7676+subl $$56, %esp
7777+7878+# push the address of the argument area as the second argument
7979+pushl %esp
8080+8181+# push the call number or return value as the first argument
8282+pushl %eax
8383+.endmacro
8484+8585+.macro trampoline_leave
8686+# restore eax (i.e. the call number or return value)
8787+popl %eax
8888+leave
8989+ret
9090+.endmacro
9191+9292+#endif
43934494.private_extern _darling_mach_syscall_entry_trampoline
4595_darling_mach_syscall_entry_trampoline:
+17
src/xtrace/xtracelib.c
···3535 uint8_t call[3];
3636}
3737__attribute__((packed));
3838+#elif defined(__i386__)
3939+struct hook {
4040+ uint8_t mov;
4141+ uint32_t addr;
4242+ uint8_t call[2];
4343+} __attribute__((packed));
3844#endif
39454046// Defined in libsystem_kernel
···142148143149static void setup_hook(struct hook* hook, void* fnptr, bool jump)
144150{
151151+#if defined(__x86_64__)
145152 // this hook is (in GAS syntax):
146153 // movq $<fnptr value>, %r10
147154 // call *%r10
···152159 hook->call[1] = 0xff;
153160 hook->call[2] = jump ? 0xe2 : 0xd2;
154161 hook->addr = (uintptr_t)fnptr;
162162+#elif defined(__i386__)
163163+ // this hook is (in GAS syntax):
164164+ // mov $<fnptr value>, %ecx
165165+ // call *%ecx
166166+ // the call turns into a jump if `jump` is true
167167+ hook->mov = 0xb9;
168168+ hook->addr = (uintptr_t)fnptr;
169169+ hook->call[0] = 0xff;
170170+ hook->call[1] = jump ? 0xe1 : 0xd1;
171171+#endif
155172}
156173157174static void xtrace_setup_mach(void)