Add system calling (including kernel compilation)-General Linux technology-Linux programming and kernel information. The following is a detailed description. First linux job
Adding a system call is actually very simple. The Internet is everywhere. Let me briefly describe:
1.
Include/linux/unistd. h, and add a new system call number in it.
# Define _ NR_mysyscall 320
2.
Arch/i386/kernel/table. s, add the corresponding table item in it
. Long SYSMBOL_NAME (sys_mysyscall)
Note: in many cases, we can add them in arch/i386/kernel/entry. S. It should be about the kernel version. I use
The kernel version of is 2.60.
3.
Add the system call implementation function in kernel/sys. c.
Asmlinkage int sys_mysyscall (void)
{
Return 0:
}
Opening the sys. c file with gedit is garbled and can only use vim.
This adds a system call. It's actually quite simple.
The following describes how to compile the kernel.
1.
Go to the Kernel File
Cd linux
Make mrproper
2.
Make config
Make menuconfig
Make xconfig
Make oldconfig
Choose one of the four types for Kernel configuration. I will not talk about the specific differences here.
When I start to use it, I can only use the first one, that is, make config. Other errors will be reported. Very strange
Later I found that I needed to download the relevant stuff.
Install ubuntu directly from the source.
Sudo apt-get install build-essential kernel-package libncurses5-dev
Kernel configuration is still quite troublesome, and I don't know much about it, so I used a method of laziness:
Directly from/boot/config ********/to/usr/src/linux/
Make menuconfig is used for installation, and Load an Alternate Configuration File is directly selected.
In this way, the original configuration is modified.
3.
A. Run the sudo make-kpkg clean command to clear things.
B. Final compilation command: sudo make-kpkg? Initrd? Append-to-version mylinux1 kernel_image
Kernel_headers, where? Initrd is required. append-to-version is used to generate multiple images.
To the options, and then the parameter is the image name, you set, must end with a number. Finally, the image package and header file are generated.
Package. You can also use binaryreplacement to combine image.headers.doc. source, which is the most complete package.
Then there is an endless compilation process.
4.
Then, the system will generate two deb installation packages in the linux directory. as long as sudo dpkg-I installs these two packages, restart them. you do not need to manually set grub.
Finally, I had to write a test program called by the system and almost fainted.
I used the call version _ syscall0 (int, syscallname) of kernel 2.4, which is not supported now.
You need to call it in the form of syscall (syscallnumber, parameter.
Laments that linux is too new and fast, and many books cannot keep up with it.
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