当前位置:网站首页>如何实现一个系统调用
如何实现一个系统调用
2022-06-25 07:13:00 【TABE_】
自己实现一个简单系统调用的流程如下:
- 在arch/arm/include/uapi/asm/unistd.h 头文件中增加一项
- 在 arch/arm/include/asm/unistd.h 头文件中修改全局变量
- __NR_syscalls,__NR_syscalls 表示一共有多少的系统调用
- 在 arch/arm/kernel/calls.S 汇编中增加函数接口
- 在 arch/arm/kernel/sys_arm.c 文件中实现函数
实现了系统调度之后,可以使用syscall和sysret来调用该系统调用,具体的步骤如下:
- syscall使执行逻辑从用户态切换到内核态,在进入到内核态之后,cpu会从 MSR_LSTAR寄存器中,获取处理系统调用内核代码的起始地址,即上面的 entry_SYSCALL_64。
- 在执行 entry_SYSCALL_64 函数时,内核代码会根据约定,先从rax寄存器中获取想要执行的系统调用的编号,然后根据该编号从sys_call_table数组中找到对应的系统调用函数。
- 接着,从 rdi, rsi, rdx, r10, r8, r9 寄存器中获取该系统调用函数所需的参数,然后调用该函数,把这些参数传入其中。
- 在系统调用函数执行完毕之后,执行结果会被放到rax寄存器中。如果用户程序需要该系统调用的返回结果,则从rax中获取。
- 最后,执行sysret汇编指令,从内核态切换回用户态,用户程序继续执行。
边栏推荐
- 双周投融报:资本埋伏Web3基础设施
- Sword finger offer (medium level)
- Getting to know the generation confrontation network (12) -- using pytoch to build wgan-gp to generate handwritten digits
- CVPR 2022 oral 2D images become realistic 3D objects in seconds
- QSS 不同风格的按钮
- Measure the current temperature
- Is the securities account given by Qiantang education business school safe? Can I open an account?
- With the beauty of technology enabled design, vivo cooperates with well-known art institutes to create the "industry university research" plan
- [unexpected token o in JSON at position 1 causes and solutions]
- Overview of image super score: the past and present life of image super score in a single screen (with core code)
猜你喜欢

TCP acceleration notes
How to calculate the characteristic vector, weight value, CI value and other indicators in AHP?

Bluecmsv1.6-代码审计
![[QT] QT 5 procedure: print documents](/img/76/2fce505c43f75360a8ff477aa2d31d.png)
[QT] QT 5 procedure: print documents

《树莓派项目实战》第五节 使用Nokia 5110液晶屏显示Hello World

Wechat applet opening customer service message function development

35岁腾讯员工被裁员感叹:北京一套房,存款700多万,失业好焦虑

测一测现在的温度

What are the indicators of VIKOR compromise?

Deep learning series 45: overview of image restoration
随机推荐
Overview of image super score: the past and present life of image super score in a single screen (with core code)
想要软件测试效果好,搭建好测试环境是前提
Establish open data set standards and enable AI engineering implementation
Cloud computing exam version 1 0
iframe简单使用 、获取iframe 、获取iframe 元素值 、iframe获取父页面的信息
双周投融报:资本埋伏Web3基础设施
Unity Addressable批量管理
InfluxDB时序数据库
How to calculate the fuzzy comprehensive evaluation index? How to calculate the four fuzzy operators?
[supplementary question] 2021 Niuke summer multi school training camp 4-N
How do I install the software using the apt get command?
Is there any risk in the security of new bonds
Internet of things (intelligent irrigation system - Android end)
TCP and UDP
TCP stuff
Paper:Generating Hierarchical Explanations on Text Classification via Feature Interaction Detection
STM32CubeMX 学习(5)输入捕获实验
How to calculate the independence weight index?
Network model -- OSI model and tcp/ip model
打新债安不安全 有风险吗