I'm currently reading Operating System Concepts 7th edition by Silberschartz, Galvin and Gagne. At the end of chapter 2, there is an exercise "Add a system call to the Linux Kernel". Unfortunately, I realized the directory structure that the authors used is completely different with Ubuntu's one. For example, the authors referred to "/usr/src/linux-2.x/include/asm-i386/unistd.h", but on my machine, they are:
- /usr/src/linux-headers-2.6.38-10
- /usr/src/linux-headers-2.6.38-10-generic
And inside this folder, I couldn't find anything called "asm-i386" :(. I wonder is there a documentation specified for Ubuntu? Any suggestion would be greatly appreciated.
Thank you,
Best Answer
Ubuntu doesn't do anything special. Your first difficulty is that you don't have the kernel source installed, only kernel headers. The authors are describing a system with a copy of the kernel source in
/usr/src/linux-2.x
. If you're only compiling external modules, the headers, which are what you see on your system, are enough. Ubuntu ships kernel headers for that purpose in thelinux-headers-*
packages (which you would normally install via the dependency from the linux-headers-generic metapackage). If you need the whole source, get a compressed archive from the linux-source-2.6 binary package.Another thing is that the directory structure has changed a little over time; architecture-dependent headers moved from
include/asm-$ARCH
toarch/$ARCH/include/asm
. Furthermore thei386
andx86_64
architectures were merged into a unifiedx86
in 2.6.24. (More details here.) So you now need to look inarch/x86/include
rather thaninclude/asm-i386
.Here are a few useful resources for Linux kernel hackers:
And also read this thread on Unix & Linux, which explains how to locate the implementation of an existing syscall.