Jump to content

[Help]How To display or list my systemcall in fedora 5?


Recommended Posts

Hi guys...

I'm new to this forum and to linux also...

i need some help here... i've been trying to make a new system call from my fedora 5, i want to try to list or display the system call. The purpose of this project is to modify the Linux kernel to record and report some statistics of programs after their execution. The kernel will provide a system call, which takes the name of a program as a parameter and reports the following statistics for the given program assigned by the user. In other words, a tool reporting the statistics of any running program specified by users can be implemented through your new system call.

 

1. the program name

2. the CPU time consumed during the execution

3. the number of files, if any, and their total size opened to read during the execution

4. the number of child processes, if any, created for the program during the execution.

5. the number of context switch performed for the program during the execution

 

But i still can't make it... well i'm really newbie to this linux...

can somebody help me with a tutorial?

thanks in advance...

 

Regards,

iCc

Link to post
Share on other sites

Welcome to the forums, adding a systemcall to the kernel shouldn't be that tricky a task.

  1. Download the kernel from http://www.kernel.org/
  2. Uncompress the tarball:
    tar -zxvf linux-VERSION.tar.gz -C /usr/src


  3. Edit file /usr/src/linux-VERSION/arch/i386/kernel/syscall_table.S Adding .long sys_mysyscallnew after the last line of the file.
  4. Edit file /usr/src/linux-VERSION/arch/i386/kernel/Makefile Appending mysyscallnew.o at the end of the list of syscalls.
  5. Create a new file call mysyscallnew.c under /usr/src/linux-VERSION/arch/i386/kernel/ directory.
  6. Add your syscall in the file:
    #include <linux/mysyscallnew.h>
    #include <linux/init.h>
    
    /* do something! */
    asmlinkage int sys_mysyscallnew(int arg) {
     cvalue += arg;
     return (cvalue);
    }
    
    /* initialize */
    void __init mysyscallnew_init(void) {
     cvalue = 0;
    }


     

  7. Create another file in /usr/src/linux-VERSION/include/linux/mysyscallnew.h
  8. Add this into the file:
    #ifndef __LINUX_MYSYSCALLNEW_H
    #define __LINUX_MYSYSCALLNEW_H 
    #include <linux/linkage.h> 
    int cvalue;
    #endif


     

  9. Now edit the file Edit file /usr/src/linux-VERSION/include/asm-i386/unistd.h
  10. Add (this should be the current value of the __NR_syscalls !!:
    #define __NR_mysyscallnew			 318


  11. Modify:
    #define __NR_syscalls		   318


  12. To be
    #define __NR_syscalls		   319


  13. Now edit this file /usr/src/linux-VERSION/init/main.c and add (after extern void prepare_namespace(void);)
    extern void mynewcall_init(void);


  14. In the same file, add (after acpi_early_init(); /* before LAPIC and SMP init */)
    mysyscallnew_init();


OK! So at this point you should be able to build your kernel with its nice new syscall! If it builds first time I'd be stunned ;) So once its built, install it and reboot into the new kernel.

 

Now of course you want to test the magic new syscall.

  1. Create a file called /usr/include/linux/mysyscallnew-user.h
    #include <linux/unistd.h>
    #define __NR_mysyscallnew		 318
    _syscall1(int, mysyscallnew, int, arg);


  2. Create another file called testing.c (or whatever!)
    #include <linux/mysyscallnew-user.h>
    #include <stdio.h> 
    
    int main (int argc, char * argv[]) {
     int val = 0; 
     val = mysyscallnew(10); 
     printf("currentvalue = %d\n", val); 
     return 0;
    }


YES that's right, we have created a syscall that magically ADDs! :o hehe.

 

I hope that my stuff here is good, you might want to check out some other sources to see what's what but I hope this gives you the jist. I found a nice article )it is old though .. 1999!). I also spotted a shorter and less descriptive example here but it does have a patch and C file example (NOTE its for the 2.4 kernel!).

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...