龙芯内核添加系统调用介绍
2017-11-29 14:16
330 查看
添加主要有两个模块 1:交叉工具链的修改 2:内核代码的修改
1:交叉工具链的修改
添加交叉工具链 新系统调用的 定义; 龙芯官网下载交叉工具链。 不妨按照以下思路来实现 添加过程,
在交叉工具链代码中全局查找 __NR_open , 以此为模版,在系统调用表的最后面添加上自己的定义。
交叉工具链:gcc-4.4-gnu
实现如下;
1:在目录 sysroot/usr/include/asm/unistd.h 最后面添加自己的定义 : #define __NR_wuheshi (__NR_Linux + 360) //需要跟在内核中定义一样、
2:在 目录 sysroot/usr/include/bit/syscall.h 最后添加定义 #define SYS_wuheshi __NR_wuheshi
3: 在目录 sysroot/usr/include/asm-generic/unistd.h 最后添加
#define __NR_wuheshi 285
SYSCALL(__NR_wuheshi , sys_wuheshi)
4: 在sysroot/usr/include/bits/sched.h 这个路径可选则,只要能找到即可 添加: extern void sys_wuheshi(void);
以上定义必须和内核中的定义。
内核4.4.2
1:在内核系统调用表 syscall table中添加自己的 定义
在arch/mips/kernel/scall64-o32.S 最后添加 PTR sys_wuheshi
2:添加函数声明
在include/linux/syscalls.h 添加 asmlinkage void sys_wuheshi(void);
3:添加函数实现
这个位置根据自己的功能选择, 我添加的是在 arch/mips/kernel/syscall.c 中添加
asmlinkage viod sys_wuheshi(void)
{
printk("sys wuheshi here\n");
}
4: 添加系统调用 定义
在目录 arch/mips/include/uapi/asm/unistd.h 中添加 #define __NR_wuheshi (__NR_Linux + 360)
在 include/uapi/asm-generic/unistd.h 添加
#define __NR_wuheshi 285
__SYSCALL(__NR_wuheshi, sys_wuheshi)
到此为止 添加工作结束,后面为测试阶段。
重新编译内核,最好用修改后的 交叉工具链。
写个test函数如下
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
int
main(int argc, char *argv[])
{
tid = syscall(SYS_wuheshi);
}
交叉编译一下 测试函数,在编译后的内核环境下执行, ok。
syscall 介绍
int syscall(int number, ...);
DESCRIPTION
syscall() performs the system call whose assembly language interface has the specified number with the specified arguments. Symbolic constants for system calls can be found in the header file
<sys/syscall.h>.
asmlinkage是个宏,使用它是为了保持传递参数在stack中。因为从汇编语言到C语言代码参数的传递是通过stack的,它也可能从stack中得到一些不需要的参数。Asmlinkage将要解析那些参数。
1:交叉工具链的修改
添加交叉工具链 新系统调用的 定义; 龙芯官网下载交叉工具链。 不妨按照以下思路来实现 添加过程,
在交叉工具链代码中全局查找 __NR_open , 以此为模版,在系统调用表的最后面添加上自己的定义。
交叉工具链:gcc-4.4-gnu
实现如下;
1:在目录 sysroot/usr/include/asm/unistd.h 最后面添加自己的定义 : #define __NR_wuheshi (__NR_Linux + 360) //需要跟在内核中定义一样、
2:在 目录 sysroot/usr/include/bit/syscall.h 最后添加定义 #define SYS_wuheshi __NR_wuheshi
3: 在目录 sysroot/usr/include/asm-generic/unistd.h 最后添加
#define __NR_wuheshi 285
SYSCALL(__NR_wuheshi , sys_wuheshi)
4: 在sysroot/usr/include/bits/sched.h 这个路径可选则,只要能找到即可 添加: extern void sys_wuheshi(void);
以上定义必须和内核中的定义。
内核4.4.2
1:在内核系统调用表 syscall table中添加自己的 定义
在arch/mips/kernel/scall64-o32.S 最后添加 PTR sys_wuheshi
2:添加函数声明
在include/linux/syscalls.h 添加 asmlinkage void sys_wuheshi(void);
3:添加函数实现
这个位置根据自己的功能选择, 我添加的是在 arch/mips/kernel/syscall.c 中添加
asmlinkage viod sys_wuheshi(void)
{
printk("sys wuheshi here\n");
}
4: 添加系统调用 定义
在目录 arch/mips/include/uapi/asm/unistd.h 中添加 #define __NR_wuheshi (__NR_Linux + 360)
在 include/uapi/asm-generic/unistd.h 添加
#define __NR_wuheshi 285
__SYSCALL(__NR_wuheshi, sys_wuheshi)
到此为止 添加工作结束,后面为测试阶段。
重新编译内核,最好用修改后的 交叉工具链。
写个test函数如下
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
int
main(int argc, char *argv[])
{
tid = syscall(SYS_wuheshi);
}
交叉编译一下 测试函数,在编译后的内核环境下执行, ok。
syscall 介绍
int syscall(int number, ...);
DESCRIPTION
syscall() performs the system call whose assembly language interface has the specified number with the specified arguments. Symbolic constants for system calls can be found in the header file
<sys/syscall.h>.
asmlinkage是个宏,使用它是为了保持传递参数在stack中。因为从汇编语言到C语言代码参数的传递是通过stack的,它也可能从stack中得到一些不需要的参数。Asmlinkage将要解析那些参数。
相关文章推荐
- 【内核】Linux添加系统调用(静态,非动态加载模块)
- Linux内核添加系统调用
- linux内核编译与系统调用的添加(适合3.0及以后版本内核)
- 重新编译龙芯梦兰loongnix系统内核添加iptables_nat模块
- 利用模块添加系统调用(不重新编译内核)
- 在内核中添加(增加)系统调用 在内核中替换替换系统调用
- linux-3.5.4内核添加新的系统调用并测试!!!!!
- Linux系统调用的内核命令 : 探究SCI并添加自己的调用
- 树莓派1代·添加一个linux系统调用·编译内核
- Linux 内核编译 添加系统调用
- linux-3.5.4内核添加新的系统调用并测试
- Linux编译内核(4.2.6)并添加系统调用
- 【Linux编译内核】Linux添加系统调用
- 使用 Linux 系统调用的内核命令--探究 SCI 并添加自己的调用
- 怎么去转换任何系统调用为一个事件:对 eBPF 内核探针的介绍
- Linux系统调用的内核命令 : 探究SCI并添加自己的调用
- Linux 内核编译 添加系统调用
- Linux添加内核系统调用报告
- Linux开发心得总结4 - 在内核中添加系统调用
- 使用内核模块添加系统调用