CS307, Spring 2000

Adding a system call to Linux

These instructions are correct during CS307, spring 2000, at Carleton, and may (or may not) be more generally applicable.
  1. Login with username = root, password = jeffondich. You should see the "fvwm" window manager; pink and puce color scheme.

  2. Open a terminal window by left-clicking on the background and selecting Xterm.

  3. Make yourself a subdirectory of /root. Before you modify any linux source file, first copy it into your directory so you can restore the original sources when you're done using the machine. Remember that you're sharing these machines with other groups.

  4. Modify several syscall-related files. In each case, make sure to make copies of the files in /root/yourname before changing the original files.



  5. If there isn't one already, make a directory called /usr/src/linux/cs307. Go into that directory and execute "cp ../mm/Makefile .".

  6. Whether it's new or not, edit /usr/src/linux/cs307/Makefile, setting O_TARGET to cs307.o, and O_OBJS to yoursyscall.o. (Here, "yoursyscall" might be replaced by "joHello" or something that identifies you and the system call just in case you leave your source code lying around.)

  7. If you just created the cs307 directory, modify /usr/src/linux/Makefile. Change these lines

    
    	CORE_FILES	=kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o
    
    	SUBDIRS		=kernel drivers mm fs net ipc lib
    

    to say this:

    
    	CORE_FILES	=cs307/cs307.o kernel/kernel.o mm/mm.o fs/fs.o ipc/ipc.o
    
    	SUBDIRS		=cs307 kernel drivers mm fs net ipc lib
    



  8. Go back into /usr/src/linux/cs307, and create your system call source file, yoursyscall.c (using the same "yoursyscall" as when you changed O_OBJS in the cs307 Makefile. You will need at least one function in your source:

    
    	asmlinkage int sys_yoursyscall( ...parameter list...)
    

    The name "sys_yoursyscall" must be the same as in entry.S. See hello_syscall.c for an example.

  9. Change directories to /usr/src/linux. If you have added new files or changed the #include statements in existing source files, run "make dep", which updates the dependencies between the source files. This takes about 3 minutes on the Pentium 100 machines.

    Then run "make bzImage", which should take no more than a couple minutes, unless you have wilfully deleted lots of object files.

  10. Assuming your code compiled successfully, copy /usr/src/linux/arch/i386/boot/bzImage to /boot/yournameKernel.

  11. Edit /etc/lilo.conf and add the following lines

    
    	image=/boot/yournameKernel
    	label=yourname
    	root=/dev/hda5
    	initrd=/boot/initrd-2.2.5-15.img
    	read-only
    



  12. Enter the command "lilo".

  13. Restart the machine with the "reboot" command. At the lilo boot prompt, type "?" or TAB to get a list of kernels, and enter your kernel name.

  14. Login as root and change directories to /root/yourname. Create a C program to test your system call. Your test code will need to create the wrapper function by invoking one of the _syscalln macros (depending on the number of parameters your system call takes). Take a look at hellotest.c for a zero-parameter example. Compile and run your test program to see whether your system call works.

  15. When you are done with your session, restore all original Linux sources and header files.