为什么 MacOS 使用绝对内存位置进行系统调用?

Why do MacOS use absolute memory locations for system calls?

我在 Assembly 中看到了 Hello World 程序的示例,一个在 MacOS 中,另一个在 Linux 中。但它们之间的区别在于 MacOS 使用绝对内存位置进行系统调用,而 Linux 不使用。这是为什么?为什么 MacOS 不能只使用 1 或内核用于系统调用的任何数字 write?

; MacOS
mov       rax, 0x02000004         ; system call for write
; Linux
mov       rax, 1                  ; system call for write

为什么你认为它是一个绝对内存位置?系统调用编号在 syscalls.master 中定义,write 的编号为 4

4   AUE_NULL    ALL { user_ssize_t write(int fd, user_addr_t cbuf, user_size_t nbyte); } 

但是你还需要给它添加一些幻数,因为系统调用被分组到分区中

#define SYSCALL_CLASS_NONE  0   /* Invalid */
#define SYSCALL_CLASS_MACH  1   /* Mach */  
#define SYSCALL_CLASS_UNIX  2   /* Unix/BSD */
#define SYSCALL_CLASS_MDEP  3   /* Machine-dependent */
#define SYSCALL_CLASS_DIAG  4   /* Diagnostics */

Unix/BSD 的数字是 2 所以 write 的数字是 (SYSCALL_CLASS_UNIX << 24) + 4 等于 0x02000004