编写一个新的系统调用 [英] Writing a new system call

查看:214
本文介绍了编写一个新的系统调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图写在树莓的内核新的系统调用(称为sys_defclose),但在编译我得到这个错误:

 弓/ ARM /核心/内置in.o:在功能`__sys_trace_return:
。:(文字+ 0xd50):未定义的参考`sys_defclose

我已经修改以下文件:

-include / Linux的/ syscalls.h:这里我把我的系统调用的原型

-arch / ARM /有/ ASM / unistd.h中:这里我把系统调用表的新原料:

 的#define __NR_sys_defclose(__NR_SYSCALL_BASE + 380)

-arch / ARM /内核/ calls.S:这里我把:

  CALL(sys_defclose)

-i把在arch / ARM /内核sys_defclose的来源,我有新行修改makefile文件在同一目录

  OBJ-Y + = sys_defclose.o

内核版本为树莓派3.6。
有人可以解释我如何解决这个错误?
谢谢
这是我的系统调用执行

 静态结构的task_struct * get_task_by_pid(将为pid_t PID)
{
返回pid_task(find_pid_ns(PID,task_active_pid_ns(电流)),PIDTYPE_PID);
}静态无效close_files(结构files_struct *文件)
 {
     INT I,J;
     结构fdtable * FDT;    J = 0;    rcu_read_lock();
    FDT = files_fdtable(文件);
    rcu_read_unlock();
    为(;;){
            无符号长集;
            我= j的* BITS_PER_LONG;
            如果(ⅰ&GT = fdt-> max_fds)
                    打破;
           设置= fdt-> open_fds [J ++];
           而台(套){
                    如果(套&安培; 1){
                             结构文件*文件= XCHG(安培; fdt-> FD [I],NULL);
                             如果(文件){
                                 filp_close(文件,文件);
                                    cond_resched();
                           }
                    }
                  我++;
                  集>> = 1;
            }
    }
}
asmlinkage长sys_defclose(将为pid_t PID)
{
结构的task_struct *结果= NULL;rcu_read_lock();
结果= get_task_by_pid(PID);
rcu_read_unlock();
close_files(result->文件);
}


解决方案

您应该使用 SYSCALL_DEFINE * 来定义系统调用(我认为,这一步你没看错),然后添加您的系统调用到 sys_call_table的,这是架构相关的(弓/ ARM /内核/ ARM的calls.S)

I have been trying to write a new system call(called sys_defclose) in the raspberry's kernel, but upon compiling i get this error:

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

i have modified the following file:

-include/linux/syscalls.h : where i put the prototype of my syscall

-arch/arm/include/asm/unistd.h : where i put the new raw of the syscall table:

       #define __NR_sys_defclose    (__NR_SYSCALL_BASE+380)

-arch/arm/kernel/calls.S : where i put:

       CALL(sys_defclose)

-i put the source of sys_defclose in arch/arm/kernel and i have modified the makefile in the same directory with the new line

       obj-y    +=sys_defclose.o

the kernel version is 3.6 of raspberrypi. can somebody explain me how to solve this error? thanks this is the implementation of my syscall

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);
}

解决方案

You should use SYSCALL_DEFINE* to define syscall (I think, this step you did wrong), then add your syscall into sys_call_table, which is architecture-dependent (arch/arm/kernel/calls.S for arm)

这篇关于编写一个新的系统调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆