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
--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.