Table of Contents
1. Design purpose and requirements
2. Design content
3. Equipment and environment
4. Design thinking
5. Main data structures and processes
6. Experimental test results and result analysis
7. Summary of course design
Attachment 1 Course Design Defense Record
Attachment 2 source program list
1. Design purpose and requirements
This course is designed to enable middle school students to understand the implementation principles of Linux system calls, master how to change the Linux kernel source code, and how to compile calling programs to call new system calls. Middle school students are required to complete this course independently and understand the concept and implementation of system calls.
2. Design content
Using the compiled kernel methodoperating system principles and Linux system experiments, recompile the Linux kernel and reduce a system call in Linux.
Requirements: (1) Function implemented by system call: estimate the cube of a number and copy it. (2) Write another program to call.
3. Equipment and environment
Device: VMware Workstation Pro
Environment: Ubantu15.0.2
Image: ubuntu-16.04-desktop-amd64.iso
4. Design Thought 4.1 Design Idea
Change the Linux kernel and lower a new system call to implement the function of estimating the cube of a number and copying it, including downloading the Linux kernel source code, making changes, compiling the changed Linux kernel, and installing it into the system, Write a program that calls this new system call.
4.2 Main steps
(1) View the original kernel:
(2)Download the new kernel:
wgetOperating system principles and Linux system experimentLinux transplantation, then press Enter. The result is as shown
(3)將下載好的安裝包聯通到/usr/src目錄下,之後解壓縮.,終端機輸入如下指令,結果如圖
mvlinux-5.6.15.tar.gz/usr/src
cd/usr/src
tar-xvflinux-5.6.15.tar.gz
(4)下載超級編輯器vim(先前已下載好),我這兒早已下載好,若沒下,可以使用sudoapt-get-yinstallvim進行下載
(5)新增系統呼叫:
新增呼叫函數申明:viminclude/linux/syscalls.h
在#ifndef前面加asmlinkagelongsys_cube(intnum);
註:i步入編輯模式,加入後Esc返回linux移植,最後shiift+:敲wq儲存退出。
(6)加入呼叫函數定義,輸入vimkernel/sys.c,在文末加入函數
SYSCALL_DEFINE1(cube,int,num){
intresult=numnumnum;
printk(“Theresultis%d.n”,result);
returnresult;
(7)新增系統呼叫號碼
輸入vimarch/x86/entry/syscalls/syscall_64.tbl,在syscall_64.tbl檔案中加入439項內容
(8)安裝編譯核心所需的依賴套件:
apt-get -y install make apt-get -y install libncurses5-dev apt-get -y install flex apt-get -y install bison apt-get -y install libssl-dev apt-get -y install libelf-dev
(9)配置內核
輸入makemenuconfig,在跳出的介面中依序執行【Save】—>【Ok】—>【Exit】—>【Exit】
(10)編譯
在【終端】中鍵入make-j8(8個執行緒開始編譯),大約一個小時左右,如圖所示編譯完成
鍵入makemodules、makemodules_install指令,分別完成模組的編譯和安裝作業。
(11)安裝內核
【終端】輸入makeinstall
(12)重啟系統
【終端】輸入uname-r,查看核心版本,如圖所示已對核心重新編譯
編撰呼叫程式:
保存後退出,在【終端】中依序執行gcctest.c-otest.out、./test.out即可得到測試結果
五、主要資料結構與流程
The above is the detailed content of A Deep Dive into Linux System Calls: New System Call to Cube a Number and Print It. For more information, please follow other related articles on the PHP Chinese website!