Add system calls to the Linux kernel and compile the kernel

Source: Internet
Author: User

1 Environment Preparation

Operating system: ubuntu10.10 32bit Desktop version installed under VMware.

Build kernel version: linux-2.6.32.63

Kernel directory:/home/wanchouchou/linuxkernel/linux-2.6.32.63

For convenience, use chmod 777-r linux-2.6.32.63/to change all kernel files to full permissions so that you can modify the files in a non-root state to compile.

2 adding system calls

First enter the linux-2.6.32.63 directory. Future file paths are based on this directory as the "root directory".

2.1 Adding a table entry in the System function table

Enter the Arch/x86/kernel directory, and then vim Syscall_table_32.s, add your own system call table entry on the last line of the file:

1 . long sys_rt_tgsigqueueinfo/    **/2 .  Long  sys_perf_event_open3 . long sys_mycall      // This is the table entry we added ourselves

OK, let's start adding the system call number.

2.2 Add your own system call number

Now enter the directory arch/x86/include/asm, which has three files unistd_32.h, Unistd_64.h, Unistd.h. Since we are compiling a 32-bit kernel, we need to add the system call number in Unistd_32.h.

Vim unistd_32.h, add code at the end:

1 #define __nr_perf_event_open    3362#define __nr_syahello           // added  3#ifdef __kernel__45/*  originally 337, but because we added a line, so change 338  */6#define nr_syscalls             338  
2.3 Write your own system call implementation function

Because the system calls must be compiled into the core kernel image. So we write the implementation of this function to kernel/sys_i386_32.c:

1 // Introducing Header Files 2 #include <asm/page.h>3 ..... 4 // Add function Code 5 asmlinkage  long sys_mycall (void) {6     return  thread_size; 7 }

3 Compiling the kernel

You can now go back to the linux-2.6.32.63 directory to compile. If you have previously compiled the kernel, it is best to use the make mrproper and make clear commands to clean up the previous compiled residue files. If you are compiling the kernel for the first time, you will need to configure the kernel's compilation options, and make Menuconfig is recommended here. If you are prompted for a missing ncurses library file after you type this command, install the library using the sudo apt-get install Libncurses5-dev command. The Menuconfig configuration can then be done, and it is recommended to keep the default values.

All ready, type the make command to start compiling the kernel! Now can brew a bucket of coffee to drink slowly, why is a bucket? Because the time is really long ~ ~ ~

Add system calls to the Linux kernel and compile the kernel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.