修改内核源码 

添加的内容:arch\arm\include\uapi\asm\unistd.h文件

#define __NR_lkmao_hello		(__NR_SYSCALL_BASE+388)

 修改文件:arch\arm\include\asm\unistd.h

vi arch/arm/include/asm/unistd.h

/*
 * This may need to be greater than __NR_last_syscall+1 in order to
 * account for the padding in the syscall table
 */
//#define __NR_syscalls  (388)//原来的值
#define __NR_syscalls  (392)//修改后的值

修改文件kernel/sys.c,添加内容

 vi kernel/sys.c 

SYSCALL_DEFINE0(lkmao_hello)
{
	printk("%s:%s:%d -- sys_lkmao_hello is called\n",
		__FILE__,__func__,__LINE__);
	return 0;
}

修改文件include/linux/syscalls.h,添加如下内容:

asmlinkage long sys_hello_lkmao(void);

修改系统调用表,修改文件arch/arm/kernel/calls.S,添加CALL(sys_lkmao_hello)

linux4.0新增32位ARM的系统调用-LMLPHP

修改的文件统计

 应用测试代码

#define _GNU_SOURCE         /* See feature_test_macros(7) */
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>   /* For SYS_xxx definitions */

#define DEBUG_INFO(format, ...) printf("%s:%d -- "format"\n",\
__func__,__LINE__,##__VA_ARGS__)

#define __NR_lkmao_hello 388

int main(int argc, char**argv){
    int ret = syscall(__NR_lkmao_hello);
    DEBUG_INFO("ret = %d\n", ret);
    return 0;
}

编译代码测试

linux4.0新增32位ARM的系统调用-LMLPHP

在系统调用中打印PID和UID


SYSCALL_DEFINE0(lkmao_hello)
{
	const struct cred *cred = current_cred();
	printk("%s:%s:%d -- sys_lkmao_hello is called\n",
		__FILE__,__func__,__LINE__);



	printk("%s:%s:%d -- pid = %d,%d,uid = %d\n",
		task_pid_nr(current),
		task_pid_nr_ns(current),
		cred->uid;,
		__FILE__,__func__,__LINE__);
	return 0;
}

 测试结果

linux4.0新增32位ARM的系统调用-LMLPHP

 

小结

08-11 12:52