Find the answer to your Linux question:
Results 1 to 1 of 1
Hi everyone, I'm trying to figure out how to add a simple system call into my Debian Linux 2.4.27 kernel. The short story here is I've followed the tutorials online ...
  1. #1
    Just Joined!
    Join Date
    May 2010
    Posts
    3

    Trying to Add a New Syscall, Get Weird Kernel Compilation Error

    Hi everyone,

    I'm trying to figure out how to add a simple system call into my Debian Linux 2.4.27 kernel. The short story here is I've followed the tutorials online and I think I'm doing everything correctly; yet I'm getting a weird compilation error that I can't figure out.

    Basically, I want to add a new system call which will (A) list all processes in the runqueue head, and (B) generate some random bytes. This might not seem like the world's most useful system call, but I need this for a class project I'm working on. If I can get this to work, I can get the project off the ground. Below is the code for the system call itself:

    Code:
    /* /usr/src/linux/kernel/print_task.c */
    
    #include <linux/linkage.h>
    #include <linux/kernel.h>
    #include <linux/list.h>
    #include <linux/sched.h>
    
    struct list_head *temp;
    static LIST_HEAD(runqueue_head);
    struct task_struct *task;
    int random_bytes;
    
    asmlinkage int sys_print_tasks(int param) {
    	list_for_each(temp, &runqueue_head) {
    		task=list_entry(temp, struct task_struct, run_list);
    		printk(KERN_ALERT "Task: PID %5d, state %5d, start_time %u..\n", task->pid, task->state, task->start_time);
    		get_random_bytes(&random_bytes, sizeof(random_bytes));
    		printk(KERN_ALERT "/nAlso, here is your random bytes: %d", random_bytes);
    		}
    
    	return 1;
    }

    In addition, I've made the following modifications to the kernel code:

    In /usr/src/linux/kernel/Makefile, I've added "print_task.o" into "obj-y" section:

    Code:
    obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
    	    module.o exit.o itimer.o info.o time.o softirq.o resource.o \
    	    sysctl.o acct.o capability.o ptrace.o timer.o user.o \
    	    signal.o sys.o kmod.o context.o printtasks.o

    In /usr/src/linux/include/asm-i386/unistd.h, I've added a "# define" statement for print_task:

    Code:
    #define __NR_print_tasks	259	/* ADDED */
    In /usr/src/linux/arch/i386/kernel/entry.S, I've added .long SYMBOL_NAME(sys_print_tasks):

    Code:
    ENTRY(sys_call_table)
       ...
       .long SYMBOL_NAME(sys_print_tasks)	/* ADDED #259 - sys_print_tasks  */

    So when I compile, I get this super-strange error message:


    Code:
    make[3]: *** [printtasks.o] Error 1
    make[2]: *** [first_rule] Error 2
    make[1]: *** [_dir_kernel] Error 2
    make: *** [stamp-build] Error 2

    I have no idea what the problem might be! My print_task.c code compiles fine on its own, so I assume this is some error having to do with integrating it into the kernel. But what that problem is, I haven't a clue.

    Any ideas? Please help!

    Many thanks!
    -Phummon
    Last edited by phummon; 11-02-2010 at 06:26 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •