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