Find the answer to your Linux question:
Results 1 to 2 of 2
I'm trying to add a custom ("Hello world" :o) system call. In /usr/src/linux/hello/ I put simple hello.c ... Code: #include "linux/linkage.h" // for linking a system call #include "linux/kernel.h" // ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Dec 2010
    Posts
    15

    Unhappy Adding custom ("Hello") system call: help


    I'm trying to add a custom ("Hello world" :o) system call.
    In /usr/src/linux/hello/ I put simple hello.c ...
    Code:
    #include "linux/linkage.h" // for linking a system call
    #include "linux/kernel.h" // for "printk"
    
    asmlinkage int sys_hello() 
    {
    	printk(KERN_ALERT "Hello!");
    	return 1;
    }
    ... and in home directory helloTest.c:
    Code:
    #include <stdio.h>
    #include <sys/syscall.h>
    #include <linux/unistd.h>
    
    #define __NR_hello	338
    
    int main()
    {
    	syscall(__NR_hello);
    	return 0;
    }
    I compiled helloTest.c and ran ./a.out: in /var/log/messages nothing gets written!

    Before "compile & install & reboot" I did these steps (linux is symbolic link to linux-2.6.35.10):
    1. In /usr/src/linux/arch/x86/include/asm/unistd_32.h, I've added/changed:
      Code:
      #define __NR_hello	 338
      #define __NR_syscalls	 339
    2. In /usr/src/linux/arch/x86/kernel/syscall_table.S, I've added (on the last line):
      Code:
      .long sys_hello
    3. In /usr/src/linux/hello, I've created a Makefile:
      Code:
      obj-y += hello.o
      ... and in /usr/src/linux, I've modified Makefile and added hello/ directory:
      Code:
      core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ hello/
    4. In /usr/src/linux/include/linux/syscalls.h, I've added (on the last line):
      Code:
      asmlinkage long sys_hello(void)

  2. #2
    Just Joined!
    Join Date
    Dec 2010
    Posts
    15

    "Hello!" IS in dmesg but NOT in /var/log/messages

    I've checked System.map (in /boot directory) and 'hello' is indeed there:
    Code:
    c015c3c0 T sys_hello
    Does that imply that something is wrong with my test call, helloTest.c?

    EDIT: dmesg* does print "Hello!" on the last line, but there is nothing in /var/log/messages file.


    * dmesg - prints or controls the kernel ring buffer
    Last edited by courteous; 01-13-2011 at 09:33 AM.

Posting Permissions

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