当前位置:网站首页>Add system calls by compiling the kernel
Add system calls by compiling the kernel
2022-06-21 14:46:00 【User 6978604】
Ubuntu edition :20.04 LTS Virtual machine configuration : Hard disk :40 GB Memory :4 GB Kernel version :5.4.0.26-generic VMware edition :15.5.0
Preparation
You need some libraries to compile , So install it in advance :
sudo apt-get install libncurses5-devsudo apt-get install bisonsudo apt-get install flexsudo apt-get install libssl-devsudo apt-get install sudo apt-get install build-essentialsudo apt-install kernel-package So much ?? ok , It doesn't have to be all , part Linux The distribution may come with , You can skip this step first , Do the next thing first , The premise is that you should do a good job first and show up halfway error To prepare ! If an error occurs halfway, you can install it according to the prompt .
Check your kernel version
uname -aMy is 5.4.0.26-generic
Download the kernel
Try to download a kernel similar to your own , Avoid incompatibility caused by too large version span . Here's the URL
http://cdn.kernel.org/pub/linux/kernel I downloaded it linux-5.3.9.tar.xz
Unzip the kernel file
First, move the above kernel file to /usr/src/ Under the table of contents
stay /usr/src/ Open the terminal in the directory
decompression
sudo xz -d linux-5.3.9.tar.xzUnpack
sudo tar -xvf linux-5.3.9.tarAdd functions
After unpacking, a linux-5.3.9 Folder , Enter the folder kernel In the folder
cd linux-5.3.9/kernel edit sys.c file , Add the function at the end :
asmlinkage long sys_hello(void){
prink("hello syscall!");
return 1;
}Add function declaration
Get into /usr/src/linux-5.3.9/arch/x86/include/asm
edit syscalls.h, Join us in sys_hello function :
Assign a to our system call id
open /usr/src/linux-5.3.9/arch/x86/entry/syscalls/syscall_64.tbl,
Be sure not to conflict with what you already have
I added
548 64 hello sys_hello
Configure the kernel
Enter into /usr/src/linux-5.3.9 Under the table of contents , Execute sequentially
sudo make mrpropersudo make cleansudo make menuconfig If you execute sudo make menuconfig When the following error occurs
Full screen virtual machine ( Fill up the screen )
Then the page appears , direct save, then exit.
Then we can compile our kernel with the following commands
sudo makeThe process takes about a few hours , Anyway, I put it backstage , Then go to bed first ~~.
however ! When I woke up, I found , The computer went to sleep automatically ! A wasted night , So remind to turn off the hibernation mode of the computer before compiling . In addition, the compilation process will produce a large number of intermediate files , It is recommended to give enough hard disk 40 GB
The above information indicates that the compilation is successful .
Generate modules
sudo make modulesThis process also takes some time .
install modules
sudo make modules_installInstall the kernel into the system
sudo make installRestart and test
Restart the process to enter advanced options
Just press... When restarting ESC( The Internet says yes ESC, But mine is a long press Shift)
Choose advanced options , Then select the new kernel
If the process of entering the kernel occurs kernel panic not syncing:System is deadlocked on memory error , Just increase the memory .
Create a new test source program testMyCall.c
#include<stdio.h>
#include<sys/syscall.h>
#include<unistd.h>
#include<stdio.h>
int main(){
// syscall You need to pass a system call number
long int myRetutn = syscall(548);
printf("syscall return: %ld",myRetutn);
return 0;
}Compile operation
gcc testMyCall.c -o test
./test
syscall return: 1 We found no output hello syscall!, Because of the log output level problem , Just call dmesg Command is enough .
边栏推荐
- SSH based command operation
- Record the processing process of slow response of primary system
- Viewing tcp/ip network communication from the sending of an email
- Cmake upgrade
- Chart. JS 2.0 doughnut tooltip percentage - chart js 2.0 doughnut tooltip percentages
- Num in tensorflow basiclstmcell_ What are units- What is num_ units in tensorflow BasicLSTMCell?
- So many statistical charts? This visualizer is great~~
- Windows系统下C语言连接MySQL
- JS written test question: array
- Calculate subtotal of advertising business
猜你喜欢

Simplified crud using code generation

Word thesis typesetting tutorial

Two of my essays

LINQ extension methods - any() vs. where() vs. exists() - LINQ extension methods - any() vs. where() vs. exists()

Qt-3-basic assembly 2

Use Matplotlib to draw the first figure
Counter attack of flour dregs: MySQL 66 questions, 20000 words + 50 pictures!

Usage of SED (replacement, deletion of text content, etc.)

Summary of the most basic methods of numpy

Explain the design idea and capacity expansion mechanism of ThreadLocal in detail
随机推荐
Compile time annotation automatically generates dataholder
English accumulation__ annoyance
Use OpenCV to decompose the video into single frame pictures and synthesize the video with pictures
[untitled] fish pond forwarding command
Qt-7-multithreading
Operator Tour (I)
Win10 installation and configuration mongodb
Skills of assigning IP address by DHCP in secondary route after wireless bridge
First Canary deployment with rancher
Redis5.0 installation and production startup steps
阶乘求和
2022 Hunan latest fire facility operator simulation test question bank and answers
养老年金险是理财产品吗?资金安全吗?
Chart. JS 2.0 doughnut tooltip percentage - chart js 2.0 doughnut tooltip percentages
The code remotely calls aria2 to download URL resources or BT seeds
Selection (042) - what is the output of the following code?
Format printout
kernel GDB
Simplified crud using code generation
Write a compile time annotation