LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 12-05-2009, 01:09 AM   #1
sunnyhay
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Rep: Reputation: 0
SOS: 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!
 
Old 12-05-2009, 01:33 AM   #2
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,633
Blog Entries: 29

Rep: Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897Reputation: 897
Kindly try the following links and see if they help you:

1. http://www.linuxjournal.com/article/3326

2. http://tldp.org/LDP/lkmpg/2.6/html/

3. http://courses.cs.vt.edu/~cs3204/spr...inux_rev00.pdf

Last edited by TheIndependentAquarius; 12-05-2009 at 04:41 AM. Reason: added one more link
 
Old 12-05-2009, 12:26 PM   #3
fpmurphy
Member
 
Registered: Jan 2009
Location: /dev/ph
Distribution: Fedora, Ubuntu, Redhat, Centos
Posts: 294

Rep: Reputation: 61
If you provide us with your source code diffs, perhaps somebody here can figure out what you are doing wrong.
 
Old 12-05-2009, 02:48 PM   #4
sunnyhay
LQ Newbie
 
Registered: Nov 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by fpmurphy View Post
If you provide us with your source code diffs, perhaps somebody here can figure out what you are doing wrong.
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
3. 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/
4. Add an entry for the new syscall by modifying source/arch/x86/kernel/syscall_table_32.S. The new line is
.long sys_mysyscall
5. Add a new #define line in source/include/asm-x86/unistd_32.h with
#define __NR_mysyscall 327
6. 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-05-2009 at 02:56 PM.
 
0 members found this post helpful.
  


Reply

Tags
call, system


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fail to implement system call in Ubuntu distribution. Kunsheng Programming 1 04-01-2009 12:15 AM
how to implement my own system call in madrake LE 2005 jawahar_bits Mandriva 2 02-04-2007 11:10 AM
I am trying implement sleep in read system call problem sbharsha Programming 1 09-19-2005 12:48 AM
how to implement a simple file system for linux amitchakote Linux - Newbie 8 03-17-2004 11:19 AM


All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration