Writing a new system call

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

1 Answer

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).

Change your sys_defclose to look like this:

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like