How to implement a system call in linux?


 
Thread Tools Search this Thread
Operating Systems Linux How to implement a system call in linux?
# 1  
Old 12-05-2009
How to implement a system call in linux?

I encountered a variety of difficulties when implementing a system call as simple as HelloWorld example in Linux so far.
Firstly, according to the book "Linux Kernel Development Second Edition", I tried to implement a syscall in 2.6.31 but no way absolutely because 2.6.10 has a very different way to deal with it by comparison to 2.6.31. In fedora 4(2.6.11) I tried to compile the new kernel versions 2.6.10 or 2.6.11 but failed with unexpected errors. Even "make menuconfig" fails to work in this case.
Secondly, I tried to get help from the example from "http://tldp.org/HOWTO/html_single/Implement-Sys-Call-Linux-2.6-i386/" but still not work. Even the compilation of new kernel 2.6.17 in Ubuntu 6.10(exact 2.6.17) fails to add a syscall.
Last I also got no help from the example "http://www.imada.sdu.dk/~daniel/DM510/assignment1/system-call.html" which indicates how to implement a syscall in recent 2.6.28. But the error always take place when compiling the source with new system call modification on source:
arch/x86/built-in.o: In function `sys_call_table':
(.rodata+0x724): undefined reference to `sys_hellokernel'
make: *** [.tmp_vmlinux1] Error 1

Now can somebody give me a detailed step-by-step howto example to implement a syscall in linux?
Thank you!
# 2  
Old 12-05-2009
If you provide us with your source code changes, perhaps we can figure out what you are doing wrong. Adding a new "hello world" type of syscall is a fairly trivial exercise.
# 3  
Old 12-05-2009
Quote:
Originally Posted by fpmurphy
If you provide us with your source code changes, perhaps we can figure out what you are doing wrong. Adding a new "hello world" type of syscall is a fairly trivial exercise.
Ok.
1 I downloaded 2.6.26 kernel. Fedora 9 is my OS with kernel version 2.6.25;
2. I extract the source into /usr/src/linux-2.6.26;
3. Make a directory "/mysyscall" under the source folder;
4. Add two files in "/mysyscall".
(1) mysyscall.c
#include <linux/kernel.h>
#include <linux/linkage.h>

asmlinkage long mysyscall(int i){
printk(KERN_DEBUG "Hello World with number %d \n", i);
return(1);}
(2) mysyscall.h with only one line
obj-y := mysyscall.o
5. Modify Makefile under the source folder.
just add the new folder in the end of this line
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
So the change line is
core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ mysyscall/
6. Add an entry for the new syscall by modifying source/arch/x86/kernel/syscall_table_32.S. The new line is
.long sys_mysyscall
7. Add a new #define line in source/include/asm-x86/unistd_32.h with
#define __NR_mysyscall 327
8. I compile the kernel 2.6.26 and get the following error message:
arch/x86/built-in.o: In function `sys_call_table':
(.rodata+0x724): undefined reference to `sys_mysyscall'
make: *** [.tmp_vmlinux1] Error 1


It's all. Please tell me how to implement the syscall successfully. Thank you very much!

Last edited by sunnyhay; 12-06-2009 at 12:01 PM..
# 4  
Old 12-06-2009
Did you create a Makefile for your new subdirectory?
# 5  
Old 12-06-2009
Quote:
Originally Posted by fpmurphy
Did you create a Makefile for your new subdirectory?
No, I just modified the Makefile under source/ folder as the 5th step showed.
# 6  
Old 12-07-2009
Looking at the output from make, is mysyscall.c being compiled?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. IP Networking

Implement inter vlan routing with Linux

Hello. I want to Communicate 2 VLAN with router like this solution: http://8pic.ir/images/83m0ouih8mmm9s1sfl56.jpg For this purpose I'm configuring 2 Linux system as a switch and connect 4 host to them. Then a router is added to scenario. The configuration of the switches is: On DUT1(Linux):... (1 Reply)
Discussion started by: zsn
1 Replies

2. Shell Programming and Scripting

system call

Trying to figure out a load issue with a webserver. I have traced a php script and noticed the following connect(4, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("XX.XX.XX.XX")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000035> poll(, 1, 2000) = 1 () <0.000120>... (5 Replies)
Discussion started by: rajan007
5 Replies

3. Ubuntu

How to implement TIOCOUTQ for USB modem on Linux Ubuntu

Hi, I need to override ioctl operation for a few USB drivers (sierra, option, cdc-acm) on Linux Ubuntu 2.6.34sb2 to support TIOCOUTQ command. Unfortunately, none of the drivers I mentioned above support TIOCOUTQ because it seems unclear to know amount of data inside a modem. Does Linux... (12 Replies)
Discussion started by: SDoroshenko
12 Replies

4. Shell Programming and Scripting

system call

Hi, How to write a system calls in a script ? > cd $HOME > ls -ltr thanks in advance.. (10 Replies)
Discussion started by: hegdeshashi
10 Replies

5. UNIX for Advanced & Expert Users

ioctl() system call on Linux-i386

Greetings, Please help me with the following : Where can I find what means exactly and how to use each of the second argument of the ioctl() system call in Linux/386 : FIOxxx (file IOCTL requests), SIOxxx (socket IOCTL requests), TCxxx TIOxxx (terminal IOCTL requests) ? ... (1 Reply)
Discussion started by: aigoia
1 Replies

6. Programming

c system call

How the c compiler differentiates the system calls and function calls? (1 Reply)
Discussion started by: rangaswamy
1 Replies

7. UNIX for Advanced & Expert Users

how implement a kernel call?

Hi, I would like o implement a kernel call, but I don't know how to do it. Where can I find an example? I've already look to minix source code, but I'm still confused and not very comfortable to mess with the code at this level. Thanks, (1 Reply)
Discussion started by: pedrosacosta
1 Replies

8. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

9. Linux

Making Socket System Call From Linux Kernel Module?

Hi Everyone! How can we make a socket() system call from a linux module executing in kernel space? If any one knows, kindly tell me. It will be great. I want to use the socket interface in linux kernel space for sending raw packets over the network. Hamayun (0 Replies)
Discussion started by: mian_m_hamayun
0 Replies
Login or Register to Ask a Question