众所周知,BSD系统调用号,都是正值;mach系统调用号,都是负值。
在这里判断(汇编代码osfmk/x86_64/idt64.s):
/* Syscall dispatch routines! */ /* * * 32bit Tasks * System call entries via INTR_GATE or sysenter: * * r15 x86_saved_state32_t * rsp kernel stack * * both rsp and r15 are 16-byte aligned * interrupts disabled * direction flag cleared */ Entry(hndl_sysenter) /* * We can be here either for a mach syscall or a unix syscall, * as indicated by the sign of the code: */ movl R32_EAX(%r15),%eax testl %eax,%eax js EXT(hndl_mach_scall) /* < 0 => mach */ /* > 0 => unix */
指令test1判断寄存器EAX的值,如果正,就继续执行到hndl_unix_scall;如果负,就跳到hndl_mach_scall。
说明:上述逻辑仅限于32位时,64位有其他逻辑(在上一篇中)