Linux-Noob Forums
[Help]How To display or list my systemcall in fedora 5? - Printable Version

+- Linux-Noob Forums (https://www.linux-noob.com/forums)
+-- Forum: Linux Noob (https://www.linux-noob.com/forums/forum-3.html)
+--- Forum: Kernel Related (https://www.linux-noob.com/forums/forum-61.html)
+--- Thread: [Help]How To display or list my systemcall in fedora 5? (/thread-1648.html)



[Help]How To display or list my systemcall in fedora 5? - iCc - 2007-01-07


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




[Help]How To display or list my systemcall in fedora 5? - znx - 2007-01-07


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

<ol style="list-style-type:decimal;">[*]Download the kernel from [/url][url=http://www.kernel.org/]http://www.kernel.org/

[*]Uncompress the tarball:
Code:
tar -zxvf linux-VERSION.tar.gz -C /usr/src






[*]Edit file /usr/src/linux-VERSION/arch/i386/kernel/syscall_table.S Adding .long sys_mysyscallnew after the last line of the file.

[*]Edit file /usr/src/linux-VERSION/arch/i386/kernel/Makefile Appending mysyscallnew.o at the end of the list of syscalls.

[*]Create a new file call mysyscallnew.c under /usr/src/linux-VERSION/arch/i386/kernel/ directory.

[*]Add your syscall in the file:
Code:
#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;
}



 



[*]Create another file in /usr/src/linux-VERSION/include/linux/mysyscallnew.h

[*]Add this into the file:
Code:
#ifndef __LINUX_MYSYSCALLNEW_H
#define __LINUX_MYSYSCALLNEW_H
#include <linux/linkage.h>
int cvalue;
#endif



 



[*]Now edit the file Edit file /usr/src/linux-VERSION/include/asm-i386/unistd.h

[*]Add (this should be the current value of the __NR_syscalls !!:
Code:
#define __NR_mysyscallnew             318






[*]Modify:
Code:
#define __NR_syscalls           318






[*]To be
Code:
#define __NR_syscalls           319






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






[*]In the same file, add (after acpi_early_init(); /* before LAPIC and SMP init */)
Code:
mysyscallnew_init();






</ol>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.

<ol style="list-style-type:decimal;">[*]Create a file called /usr/include/linux/mysyscallnew-user.h
Code:
#include <linux/unistd.h>
#define __NR_mysyscallnew         318
_syscall1(int, mysyscallnew, int, arg);






[*]Create another file called testing.c (or whatever!)
Code:
#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;
}






</ol>YES that's right, we have created a syscall that magically ADDs! [img]<___base_url___>/uploads/emoticons/default_ohmy.png[/img] 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!).