search
HomeSystem TutorialLINUXA Deep Dive into Linux System Calls: New System Call to Cube a Number and Print It

深入探究 Linux 系统调用:新增计算数字三次方并打印的系统调用

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.

操作系统原理与linux系统实验_linux操作系统原理与应用_操作系统原理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:

操作系统原理linux篇_操作系统原理与linux系统实验_linux操作系统原理与应用

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);

linux操作系统原理与应用_操作系统原理linux篇_操作系统原理与linux系统实验

註: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)安裝編譯核心所需的依賴套件:

操作系统原理与linux系统实验_linux操作系统原理与应用_操作系统原理linux篇

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)編譯

操作系统原理linux篇_linux操作系统原理与应用_操作系统原理与linux系统实验

在【終端】中鍵入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!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Mastering Text Manipulation With the Sed CommandMastering Text Manipulation With the Sed CommandMar 16, 2025 am 09:48 AM

The Linux command line interface provides a wealth of text processing tools, one of the most powerful tools is the sed command. sed is the abbreviation of Stream EDitor, a multi-functional tool that allows complex processing of text files and streams. What is Sed? sed is a non-interactive text editor that operates on pipeline inputs or text files. By providing directives, you can let it modify and process text in a file or stream. The most common use cases of sed include selecting text, replacing text, modifying original files, adding lines to text, or removing lines from text. It can be used from the command line in Bash and other command line shells. Sed command syntax sed

How To Count Files And Directories In Linux: A Beginner's GuideHow To Count Files And Directories In Linux: A Beginner's GuideMar 19, 2025 am 10:48 AM

Efficiently Counting Files and Folders in Linux: A Comprehensive Guide Knowing how to quickly count files and directories in Linux is crucial for system administrators and anyone managing large datasets. This guide demonstrates using simple command-l

How To Add A User To Multiple Groups In LinuxHow To Add A User To Multiple Groups In LinuxMar 18, 2025 am 11:44 AM

Efficiently managing user accounts and group memberships is crucial for Linux/Unix system administration. This ensures proper resource and data access control. This tutorial details how to add a user to multiple groups in Linux and Unix systems. We

How To List Or Check All Installed Linux Kernels From CommandlineHow To List Or Check All Installed Linux Kernels From CommandlineMar 23, 2025 am 10:43 AM

Linux Kernel is the core component of a GNU/Linux operating system. Developed by Linus Torvalds in 1991, it is a free, open-source, monolithic, modular, and multitasking Unix-like kernel. In Linux, it is possible to install multiple kernels on a sing

How To Type Indian Rupee Symbol In Ubuntu LinuxHow To Type Indian Rupee Symbol In Ubuntu LinuxMar 22, 2025 am 10:39 AM

This brief guide explains how to type Indian Rupee symbol in Linux operating systems. The other day, I wanted to type "Indian Rupee Symbol (₹)" in a word document. My keyboard has a rupee symbol on it, but I don't know how to type it. After

Locating Leviathan Files in LinuxLocating Leviathan Files in LinuxMar 13, 2025 pm 12:11 PM

Introduction In the realm of Linux, where the command line is often the compass by which we navigate, the efficient management of disk space is crucial. Whether you’re sailing through personal projects or steering the ship o

Install Fedora Linux 41 Workstation [Step-by-Step Guide]Install Fedora Linux 41 Workstation [Step-by-Step Guide]Mar 09, 2025 am 11:21 AM

This guide provides a comprehensive walkthrough for installing Fedora Linux 41 Workstation Edition. Let's get started! Table of Contents - Step 1: Prepare Your Fedora 41 Installation Media Step 2: Boot from the Fedora 41 Installation Media Step 3:

Linux Kernel 6.14 RC6 ReleasedLinux Kernel 6.14 RC6 ReleasedMar 24, 2025 am 10:21 AM

Linus Torvalds has released Linux Kernel 6.14 Release Candidate 6 (RC6), reporting no significant issues and keeping the release on track. The most notable change in this update addresses an AMD microcode signing issue, while the rest of the updates

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

mPDF

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),