···106106107107.subsections_via_symbols
108108109109+#elif defined(__arm64__)
110110+// To keep things simple, __darling_bsd_syscall will handle the
111111+// Mach Syscall. See syscalls-table.S for more details.
112112+109113#else
110114# error Missing assembly
111115#endif
+52
src/kernel/emulation/linux/syscalls-table.S
···96969797.subsections_via_symbols
98989999+100100+#elif defined(__arm64__)
101101+// For i386/x64, the `syscall_sw.h` file has the BSD and Mach syscall defined
102102+// between two different macros (`UNIX_SYSCALL_TRAP` and `kernel_trap`). This
103103+// is not the case for ARM.
104104+105105+// For ARM64, there is only one syscall that is used for either BSD and Mach.
106106+// If the syscall number is less then zero, it will do a Mach syscall; otherwise,
107107+// it will do a BSD syscall.
108108+109109+// Because of the above, I decided to have the both the BSD and Mach syscall be
110110+// handled by the __darling_bsd_syscall.
111111+112112+// Notes:
113113+// https://stackoverflow.com/a/56993314/5988706
114114+// xnu/osfmk/arm64/sleh.c - handle_svc function
115115+116116+__darling_bsd_syscall:
117117+ ; Push temporary registers (syscalls don't modify temp register)
118118+ sub sp,sp,#16
119119+ stp x9,x10,[sp]
120120+121121+ ; if (x16 / *syscall number */ < 0)
122122+ cmp x16,#0
123123+ blt .get_mach_table
124124+125125+ ; Get &___bsd_syscall_table (function pointer)
126126+ adrp x9, ___bsd_syscall_table@PAGE
127127+ add x9, x9, ___bsd_syscall_table@PAGEOFF
128128+ mov x10,x16
129129+ b .calc_offset
130130+131131+.get_mach_table:
132132+ ; Get &___mach_syscall_table (function pointer)
133133+ adrp x9, ___mach_syscall_table@PAGE
134134+ add x9, x9, ___mach_syscall_table@PAGEOFF
135135+ neg x10,x16
136136+137137+.calc_offset:
138138+ ; &syscall_table + x10 * sizeof(void*)
139139+ lsl x10,x10,3
140140+ add x9,x9,x10
141141+142142+ ; Call ___bsd_syscall_table method
143143+ blr x9
144144+145145+ ; Restore original temp register values
146146+ ldp x9,x10,[sp]
147147+ add sp,sp,#16
148148+ ret
149149+150150+#warning "Heed to improve __darling_bsd_syscall ARM64 implementation"
99151#else
100152# error Missing assembly
101153#endif