ARM Linux系统调用过程

系统调用开始

在unistd.h中有系统调用号比如reboot
#define __NR_reboot (__NR_SYSCALL_BASE+ 88)


arm的系统调用
arch/arm/kernel/calls.S声明了系统调用函数
/* 85 */ CALL(sys_readlink)
CALL(sys_uselib)
CALL(sys_swapon)
CALL(sys_reboot)
CALL(OBSOLETE(sys_old_readdir)) /* used by libc4 */


在/Kernel/arch/arm/kernel/calls.S中
/* 85 */ CALL(sys_readlink)
CALL(sys_uselib)
CALL(sys_swapon)
CALL(sys_reboot)
CALL(OBSOLETE(sys_old_readdir)) /* used by libc4 */


在sys.c中真正调用的函数
/*
 * Reboot system call: for obvious reasons only root may call it,
 * and even root needs to set up some magic numbers in the registers
 * so that some mistake won't make this reboot the whole machine.
 * You can also set the meaning of the ctrl-alt-del-key here.
 *
 * reboot doesn't sync: do that yourself before calling this.
 */
SYSCALL_DEFINE4(reboot, int, magic1, int, magic2, unsigned int, cmd,
void __user *, arg)




在ARM Linux中添加一个自己的系统调用
1.在unistd.h结尾处添加系统调用号
#define __NR_mysyscall (__NR_SYSCALL_BASE+367)


2.在目标文件中添加具体的调用函数
比如下面是在sys.c中添加的
/*susz add for test*/
asmlinkage int sys_mycall(int number)
{
printk("%s:%d\n", __func__, __LINE__);
return number; 
}
3.将系统调用号和调用函数联系起来
在calls.S中添加,这里要按照顺序添加
/*susz test*/
/* 367*/CALL(sys_mycall)


4.用户态调用该函数
#include <linux/unistd.h>
#include <stdio.h>


int main(int argc, char *argv[])
{
int ret = 0;
int cmd = 0;
if(argc < 2){
printf("input error\n");
return -1;
}
cmd = atoi(argv[1]);
ret = syscall(367, cmd);

printf("mysyscall ret:%d\n", ret);
return 0;
}


不是ARM的板子可能会不一样,但是大致流程是一致
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值