LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 05-11-2009, 01:00 AM   #1
RepSTOSW
LQ Newbie
 
Registered: May 2009
Posts: 5

Rep: Reputation: 0
Syscall problems


Hi,

I'm very new to linux kernel development, but I have a few years of programming experience (not much C though).

I'm trying to get a syscall to work in user mode linux (version 2.6.29.1). I found a couple of tutorials on how to do it, but the file- and catalogue-structures doesn't really match, so I've tried to add code as best I could to make it work in my linux version.

The following additions have been made by me:
* In arch/x86/kernel/syscall_table_32.S
long sys_mycall

* In arch/x86/include/asm/unistd_32.h
#define __NR_mycall 333

* In arch/x86/include/asm/syscalls.h
asmlinkage long sys_mycall();

* In kernel\sys_ni.c
cond_syscall(sys_mycall);
(don't know why I would need this line, but it doesn't compile without it)

* In arch/x86/kernel/Makefile
obj-y += mycall.o

* In arch/x86/kernel/mycall.c
#include <asm/linkage.h>

asmlinkage long sys_mycall()
{
kprint("Hello world!\n");
return 1234;
}


I then run the kernel in user mode and try to call my syscall from a c-file:

* testmycall.c
#include<stdio.h>
#include "testmycall.h"

int main(void)
{
printf("Output: %d \n", syscall(333));
}


I get the output -1 and it doesn't print my hello world message :,(
Now I'm stuck and don't really know how to proceed or what could be wrong with my syscall code.
Help would be much appreciated!


Thanks in advance!

/Magnus

PS. I posted this over at the newbie-forum. Maybe some kind person could delete it from there :S
 
Old 05-11-2009, 08:40 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 64
Quote:
Originally Posted by RepSTOSW View Post
* In kernel\sys_ni.c
cond_syscall(sys_mycall);
(don't know why I would need this line, but it doesn't compile without it)
This says it all. Are you compiling a UML kernel or a native 32-bit x86 kernel? The steps you have taken so far will only work in the latter case.

On any other arch (and UML is somewhat like an arch), the following:
Code:
	cond_syscall(sys_mycall);
will make sys_mycall a weak alias to sys_ni_syscall. Thus, it will enable compilation on an arch for which the syscall has not yet been written, by replacing it with a stub (the “not implemented” system call). If the stub is required for compilation, it means the strong alias is not available (i.e., it is in an object file unused by the current architecture).

So I do not think symbols in arch/x86/kernel will be available to a UML kernel. It would be better to put your file somewhere more universal (especially considering your system call does nothing processor-specific).
 
Old 05-15-2009, 12:56 AM   #3
RepSTOSW
LQ Newbie
 
Registered: May 2009
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up

Solved it It was exactly what you said. Thanks!
 
Old 03-21-2010, 11:57 AM   #4
hcrbaser
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
Hi,I have same problem.Please can you tell me which file's place was changed and where did you put it???I realy need these answers
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syscall problems RepSTOSW Linux - Newbie 2 05-11-2009 08:00 PM
i need help in understanding syscall tonyr81 Linux - Kernel 4 05-27-2008 05:18 PM
how to use kill syscall shifter Programming 19 05-28-2007 10:04 AM
syscall hook robertos Linux - Kernel 15 03-09-2007 07:33 PM
syscall hook robertos Programming 4 03-05-2007 11:48 PM


All times are GMT -5. The time now is 12:46 PM.

Main Menu
 
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
Open Source Consulting | Domain Registration