LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Thread Tools
Old 11-04-2009, 05:15 AM   #1
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Thanked: 0
System call returns "ffffffff.."


[Log in to get rid of this advertisement]
This is my first post in this forum, an i am very new to linux. I have ubuntu 9.04 installed on my system under windows with wubi.
As a school assignment i have to write, compile and test a system call. İ have downloaded linux kernel 2.6.31 from kernel.org, compiled and booted it if i could this step succesfully, fortunately i could. Then following the tutorial our teaching assistant sent us, whose link is here,
i have tried add my first system call.
let me list the things i have done:
-i added ".long sys_mycall" at the end of syscall_table.S but i didn't have a /i386 directory and a syscall_table.S file exactly. What i did was i added this line to syscall_table32.S which is in /usr/src/linux/arch/x86/kernel. Directory and file name is some different.
-secondly i have edited unistd.h file which is not where i expected again. it was in /usr/src/linux/include/asm-generic. tutorial says it is in ..../asm-i386. anyway after editing the regarding part of unistd.h is as
Code:
#define __NR_bdflush 1075
__SYSCALL(__NR_bdflush, sys_bdflush)
#define __NR_umount 1076
__SYSCALL(__NR_umount, sys_oldumount)
#define __ARCH_WANT_SYS_OLDUMOUNT
#define __NR_uselib 1077
__SYSCALL(__NR_uselib, sys_uselib)
#define __NR__sysctl 1078
__SYSCALL(__NR__sysctl, sys_sysctl)

#define __NR_fork 1079

#define __NR_mycall 1080

#ifdef CONFIG_MMU
__SYSCALL(__NR_fork, sys_fork)
#else
__SYSCALL(__NR_fork, sys_ni_syscall)
#endif /* CONFIG_MMU */

#undef __NR_syscalls
#define __NR_syscalls (__NR_mycall+1)

#endif /* __ARCH_WANT_SYSCALL_DEPRECATED */
-then i edited syscalls.h file which i found in right place, and the edited file end as
Code:
  struct timespec __user *, const sigset_t __user *,
			  size_t);

int kernel_execve(const char *filename, char *const argv[], char *const envp[]);


asmlinkage long sys_perf_counter_open(
		struct perf_counter_attr __user *attr_uptr,
		pid_t pid, int cpu, int group_fd, unsigned long flags);
asmlinkage long sys_mycall(int i,int j);
#endif
-then i edited the makefile accordingly in /usr/src/linux
Code:
ifeq ($(KBUILD_EXTMOD),)
core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/ mycall/

vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, $(init-y) $(init-m)\
--i have created a directory /mycall and created a file mycall.c in mycall dir, it contents are:
Code:
#include <linux/linkage.h>
asmlinkage long sys_mycall(int i, int j)  {
     return(i+j);
}
--created a new makefile and added
Code:
obj-y := mycall.o
--compiled and booted my new kernel. one note i want to mention the image of kernel was like "......amd64.deb" which was the same when i compiled without any modification. (i have intel processor, doesn't it have something to do with processor type).
--added a userspace test.c file whose contents are
Code:
#include <unistd.h>
#include <stdio.h>
#define __NR_mycall 1080

long mycall(int i,int j)
	{
		return syscall(__NR_mycall,i,j);
	}

int main(void)
{
	printf("%lx\n",mycall(15,20));
	return 0;
}
compile and run this program but it outputs "ffffffffffff" to the screen?
what am i doing wrong?is it c language issue or i am making mistakes on kernel?
i know it is very long question but please do this favour for me nd please read and help me. maybe it is something quite easy piece but i couldn't figure it out for one week, thanks to my brain, anyway waiting for urgent help.
thanks for all.
linuxubuntu bahhti is offline     Reply With Quote
Old 11-04-2009, 07:27 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,969
Thanked: 19
I would start by adding printk() lines to the system call method, and identifying if the call is being made or not, what the passed values are as seen by the kernel and what the kernel thinks is being returned.

http://www.linuxgrill.com/anonymous/...g-HOWTO-4.html
linuxubuntu rjlee is offline     Reply With Quote
Old 11-06-2009, 05:56 AM   #3
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Thanked: 0

Original Poster
i am getting a compiling error when i am trying to compile mycall.c
which is as :
Code:
mycall.c:2:27: error: linux/linkage.h: No such file or directory
mycall.c:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘long’
mycall.c is
Code:
#include <linux/linkage.h>
#include <linux/kernel.h>


asmlinkage long sys_mycall()
{
	printk(KERN_EMERG "heloo world!");
	return 1;
}
i have looked in that directory and it is there. what may be the cause of this error?
linuxubuntu bahhti is offline     Reply With Quote
Old 11-06-2009, 06:43 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 8.04 (upgraded from 6.06), Ubuntu Netbook Remix 9.04
Posts: 2,741
Thanked: 87
This is far too advanced for a newbie question ( )and should go in the programming. I will ask a moderator to move it.
linuxubuntu Wim Sturkenboom is offline     Reply With Quote
Old 11-07-2009, 05:19 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :}
Posts: 18,848
Blog Entries: 1
Thanked: 160
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
linux Tinkster is online now     Reply With Quote
Old 11-07-2009, 05:33 PM   #6
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: washington U.S.
Distribution: Damn Small Linux, KateOs, M$ Ickdows Vista, My own OS
Posts: 1,241
Thanked: 60
without asmlinkage?
windows_vista smeezekitty is offline     Reply With Quote
Old 11-07-2009, 06:17 PM   #7
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Thanked: 0

Original Poster
Quote:
Originally Posted by smeezekitty View Post
without asmlinkage?
excuse me???
windows_vista bahhti is offline     Reply With Quote
Old 11-08-2009, 10:28 AM   #8
ntubski
Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 698
Thanked: 50
Quote:
Originally Posted by bahhti View Post
i am getting a compiling error when i am trying to compile mycall.c
which is as :
Code:
mycall.c:2:27: error: linux/linkage.h: No such file or directory
mycall.c:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘long’
I believe mycall.c is supposed to be compiled when you recompile the kernel, if you just try to compile it on its own, the include paths won't be setup properly.
ntubski is offline     Reply With Quote
Old 11-09-2009, 04:05 AM   #9
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Thanked: 0

Original Poster
how can i shorten my kernel compile time?
windows_vista bahhti is offline     Reply With Quote
Old 11-09-2009, 11:29 AM   #10
ntubski
Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 698
Thanked: 50
Quote:
Originally Posted by bahhti View Post
how can i shorten my kernel compile time?
Get a faster computer

Seriously though, recompiling after you've added that file shouldn't take nearly as long as the first compile, most of the kernel is compiled already so only relinking is needed.
ntubski is offline     Reply With Quote
Old 11-10-2009, 03:13 AM   #11
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 5
Thanked: 0

Original Poster
i use this two commands to compile the kernel.
make-kpkg clean
fakeroot make-kpkg --initrd –-append-to-version=-custom kernel_image kernel_headers
first will clean the files in the source folder , and second will create the two deb packages of the kernel; image and headers.
so to skip compilation of some files i won't use make-kpkg clean. but as i am having a deb package output, won't it still be as long as the first one?
also i wonder if i can have a fast compile by cahnging some configuration features. i am copying the old config file from my current system.
thanks.
windows_vista bahhti is offline     Reply With Quote
Old 11-10-2009, 10:33 AM   #12
ntubski
Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 698
Thanked: 50
I would imagine most of the is spent in compilation, making a .deb out of it shouldn't take that long (although I can't say for sure: I've never bothered making .debs from source).

Quote:
also i wonder if i can have a fast compile by cahnging some configuration features.
thanks.
That is possible.
ntubski is offline     Reply With Quote

Reply

Bookmarks


Thread Tools

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
Command "mail" returns "panic: temporary file seek" kenneho Linux - Software 5 12-23-2008 04:27 AM
to make the system call "read()" blocked sankari27 Programming 23 09-16-2008 07:50 AM
"expected specifier-qualifier-list" ERROR while adding a new system call ahm_irf Linux - Kernel 0 04-29-2007 11:52 PM
list file system linux supports "please give the command or system call" varun_shrivastava Linux - General 4 01-09-2007 08:28 AM
Any way to get "Alice"; "Call of Duty" series and "Descent 3" to work? JBailey742 Linux - Games 13 06-23-2006 02:34 PM


All times are GMT -5. The time now is 07:54 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
RSS2  LQ Podcast
RSS2  LQ Radio
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration