When I was reading Operating System Concepts (7e, Silberschatz, Galvin, Gagne), I encountered a study project about adding a system call to the linux kernel. The book says that
The system call numbers for recent versions of the Linux kernel are listed in /usr/src/linux-2.x/include/asm-i386/unistd.h. (for instance, __NR_close, which corresponds to the system call close() that is invoked for closing a file descriptor, is defined as value 6.) The /usr/src/linux-2.x开发者_如何转开发/arc/i386/kernel/entry.S under the heading ENTRY(sys_call_table). Notice that sys_close is stored at entry numbered 6 in the table to be consistent with the system call number defined in unistd.h file. (pg. 75)
I've downloaded latest linux source package from the ubuntu repository, and found the mentioned source files with minor directory and file name changes. But there is an interesting thing confuses me in the file /usr/src/linux-source-2.6.31/arch/x86/kernel/less syscall_table_32.S, sys_close is stored at entry numbered 6 as said in the book, nevertheless, in unistd.h file __NR_close defined as 57, instead of 6. What is the reason of this difference?
Thanks in advance
Are you sure you're comparing like architectures? On different architectures, system calls may well have different numbers. For instance, on x86, close is indeed 6, while on x86-64, close is 3 (looked up in unistd.h on my PC).
精彩评论