LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
LinkBack Search this Thread
Old 11-04-2009, 04:15 AM   #1
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Rep: Reputation: 0
System call returns "ffffffff.."


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.
 
Old 11-04-2009, 06:27 AM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,989

Rep: Reputation: 63
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
 
Old 11-06-2009, 04:56 AM   #3
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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?
 
Old 11-06-2009, 05:43 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 10.04, Crunchbang Statler
Posts: 3,325

Rep: Reputation: 168Reputation: 168
This is far too advanced for a newbie question ( )and should go in the programming. I will ask a moderator to move it.
 
Old 11-07-2009, 04:19 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,618
Blog Entries: 10

Rep: Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771Reputation: 771
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 11-07-2009, 04: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: 2,094

Rep: Reputation: 104Reputation: 104
without asmlinkage?
 
Old 11-07-2009, 05:17 PM   #7
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by smeezekitty View Post
without asmlinkage?
excuse me???
 
Old 11-08-2009, 09:28 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
Old 11-09-2009, 03:05 AM   #9
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Original Poster
Rep: Reputation: 0
how can i shorten my kernel compile time?
 
Old 11-09-2009, 10:29 AM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
Old 11-10-2009, 02:13 AM   #11
bahhti
LQ Newbie
 
Registered: Nov 2009
Posts: 12

Original Poster
Rep: Reputation: 0
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.
 
Old 11-10-2009, 09:33 AM   #12
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 1,421

Rep: Reputation: 360Reputation: 360Reputation: 360Reputation: 360
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.
 
  


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


All times are GMT -5. The time now is 10:57 AM.

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