系统调用开始
在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的板子可能会不一样,但是大致流程是一致
在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的板子可能会不一样,但是大致流程是一致