3

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

1 Answer 1

2

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).

3
  • I checked again, i am sure archs are same for both of them
    – dirtybit
    Mar 7, 2010 at 23:50
  • What path are you looking at? I've found the system call numbers in /usr/include/asm/unistd_32.h and /usr/include/asm/unistd_64.h for x86 and x86-64 respectively. If you're on plain x86, I would expect /usr/include/asm/unistd.h to define __NR_close as 6. Mar 7, 2010 at 23:55
  • I've check paths that you poiny both files have same values as you have. But in the kernel source code there is only one unistd.h in include/asm-generic folder. Why is it so? There are no files for x86 and x86_64 seperately
    – dirtybit
    Mar 8, 2010 at 0:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.