


A Deep Dive into Linux System Calls: New System Call to Cube a Number and Print It
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!


For years, Linux software distribution relied on native formats like DEB and RPM, deeply ingrained in each distribution's ecosystem. However, Flatpak and Snap have emerged, promising a universal approach to application packaging. This article exami

The differences between Linux and Windows in handling device drivers are mainly reflected in the flexibility of driver management and the development environment. 1. Linux adopts a modular design, and the driver can be loaded and uninstalled dynamically. Developers need to have an in-depth understanding of the kernel mechanism. 2. Windows relies on the Microsoft ecosystem, and the driver needs to be developed through WDK and signed and certified. The development is relatively complex but ensures the stability and security of the system.

The security models of Linux and Windows each have their own advantages. Linux provides flexibility and customizability, enabling security through user permissions, file system permissions, and SELinux/AppArmor. Windows focuses on user-friendliness and relies on WindowsDefender, UAC, firewall and BitLocker to ensure security.

Linux and Windows differ in hardware compatibility: Windows has extensive driver support, and Linux depends on the community and vendors. To solve Linux compatibility problems, you can manually compile drivers, such as cloning RTL8188EU driver repository, compiling and installing; Windows users need to manage drivers to optimize performance.

The main differences between Linux and Windows in virtualization support are: 1) Linux provides KVM and Xen, with outstanding performance and flexibility, suitable for high customization environments; 2) Windows supports virtualization through Hyper-V, with a friendly interface, and is closely integrated with the Microsoft ecosystem, suitable for enterprises that rely on Microsoft software.

The main tasks of Linux system administrators include system monitoring and performance tuning, user management, software package management, security management and backup, troubleshooting and resolution, performance optimization and best practices. 1. Use top, htop and other tools to monitor system performance and tune it. 2. Manage user accounts and permissions through useradd commands and other commands. 3. Use apt and yum to manage software packages to ensure system updates and security. 4. Configure a firewall, monitor logs, and perform data backup to ensure system security. 5. Troubleshoot and resolve through log analysis and tool use. 6. Optimize kernel parameters and application configuration, and follow best practices to improve system performance and stability.

Learning Linux is not difficult. 1.Linux is an open source operating system based on Unix and is widely used in servers, embedded systems and personal computers. 2. Understanding file system and permission management is the key. The file system is hierarchical, and permissions include reading, writing and execution. 3. Package management systems such as apt and dnf make software management convenient. 4. Process management is implemented through ps and top commands. 5. Start learning from basic commands such as mkdir, cd, touch and nano, and then try advanced usage such as shell scripts and text processing. 6. Common errors such as permission problems can be solved through sudo and chmod. 7. Performance optimization suggestions include using htop to monitor resources, cleaning unnecessary files, and using sy


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

WebStorm Mac version
Useful JavaScript development tools
