一、在内核中添加系统调用的步骤:
1.在 kernel/sys.c 中添加系统调用函数
asmlinkage int sys_hello()
{
printk(KERN_INFO "hello world\n");
return 0;
}
2.在 include/asm/unistd.h 尾部添加系统调用号
#define __NR_hello (__NR_SYSCALL_BASE+352)
3.在 arch/arm/kernel/calls.S中的尾部添加系统调用函数
CALL(sys_hello)
#include <linux/unistd.h>
int main(void)
{
int result;
result= syscall(352);
printf("result= %d\n", result);
return 0;
}
1.在 kernel/sys.c 中添加系统调用函数
asmlinkage int sys_hello()
{
printk(KERN_INFO "hello world\n");
return 0;
}
2.在 include/asm/unistd.h 尾部添加系统调用号
#define __NR_hello (__NR_SYSCALL_BASE+352)
3.在 arch/arm/kernel/calls.S中的尾部添加系统调用函数
CALL(sys_hello)
二、测试添加的系统调用
写一个应用程序
#include <stdio.h>#include <linux/unistd.h>
int main(void)
{
int result;
result= syscall(352);
printf("result= %d\n", result);
return 0;
}
本文介绍如何在嵌入式Linux内核中添加自定义系统调用,并提供了一个简单的示例程序来测试新增的系统调用。文章详细说明了添加步骤:修改sys.c文件实现系统调用函数、在unistd.h中定义系统调用号以及在calls.S中添加系统调用函数。
2025

被折叠的 条评论
为什么被折叠?



