编写新的系统调用

我一直在尝试在raspberry的内核中编写一个新的系统调用(称为sys_defclose),但是在编译时我得到了这个错误:

arch/arm/kernel/built-in.o: In function `__sys_trace_return': :(.text+0xd50): undefined reference to `sys_defclose' 

我修改了以下文件:

-include / linux / syscalls.h:我把我的系统调用的原型放在哪里

-arch / arm / include / asm / unistd.h:我把syscall表的新原始文件放在哪里:

  #define __NR_sys_defclose (__NR_SYSCALL_BASE+380) 

-arch / arm / kernel / calls.S:我把它放在哪里:

  CALL(sys_defclose) 

-i把sys_defclose的源码放在arch / arm / kernel中,我用新行修改了同一目录下的makefile

  obj-y +=sys_defclose.o 

内核版本是raspberrypi的3.6。 谁能解释一下如何解决这个错误? 谢谢这是我的系统调用的实现

 static struct task_struct* get_task_by_pid(pid_t pid) { return pid_task(find_pid_ns(pid, task_active_pid_ns(current)), PIDTYPE_PID); } static void close_files(struct files_struct * files) { int i, j; struct fdtable *fdt; j = 0; rcu_read_lock(); fdt = files_fdtable(files); rcu_read_unlock(); for (;;) { unsigned long set; i = j * BITS_PER_LONG; if (i >= fdt->max_fds) break; set = fdt->open_fds[j++]; while (set) { if (set & 1) { struct file * file = xchg(&fdt->fd[i], NULL); if (file) { filp_close(file, files); cond_resched(); } } i++; set >>= 1; } } } asmlinkage long sys_defclose(pid_t pid) { struct task_struct *result = NULL; rcu_read_lock(); result = get_task_by_pid(pid); rcu_read_unlock(); close_files(result->files); } 

您应该使用SYSCALL_DEFINE*来定义系统调用(我认为,这一步你做错了),然后将你的系统调用添加到sys_call_table ,这是依赖于体系结构的(arm / arm / kernel / calls.S for arm)。

sys_defclose更改为如下所示:

 SYSCALL_DEFINE1(defclose, pid_t, pid) { struct task_struct *result = NULL; rcu_read_lock(); result = get_task_by_pid(pid); rcu_read_unlock(); close_files(result->files); }