You are not logged in.

#1 2012-07-10 14:36:26

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

[solved] add a new syscall to kernel 3.4

hi there,
I'm trying to add a new system call to the kernel but all I found seems regarding old kernel versions.
I found only a posts that says to modify the file: arch/x86/syscalls/syscall_32.tbl (adding an entry for the syscall), then add the real code of the syscall to the file fs/open.c;
I wanted to do something like this:
http://appusajeev.wordpress.com/2010/11 … el-2-6-35/
and then use makepkg to compile the kernel.
any suggestion??

Last edited by alwaysanoob (2012-07-17 15:18:38)

Offline

#2 2012-07-10 14:46:14

ethail
Member
From: Spain
Registered: 2011-02-10
Posts: 225

Re: [solved] add a new syscall to kernel 3.4

make a patch (or several) to patch the kernel, then apply that patch in the PKGBUILD. You could look at the PKGBUILd of the linux package to get an idea of it


My GitHub Page

Best Testing Repo Warning: [testing] means it can eat you hamster, catch fire and you should keep it away from children. And I'm serious here, it's not an April 1st joke.

Offline

#3 2012-07-10 15:11:02

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

Re: [solved] add a new syscall to kernel 3.4

moving to kernel & hardware section..

Offline

#4 2012-07-10 15:23:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [solved] add a new syscall to kernel 3.4

Alwaysanoob, I believe moderators can move threads.  You can request that they do so, but otherwise, please do not cross post.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2012-07-10 15:34:45

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

Re: [solved] add a new syscall to kernel 3.4

ok, sorry for that
I was dubious about the right section to put the thread!

Offline

#6 2012-07-10 15:37:10

fsckd
Forum Fellow
Registered: 2009-06-15
Posts: 4,173

Re: [solved] add a new syscall to kernel 3.4

Okay, moving from Creating & Modifying Packages to Kernel & Hardware.

I have deleted your other thread. Good luck! smile

alwaysanoob wrote:

ok, sorry for that
I was dubious about the right section to put the thread!

It could go in either, that is assuming it's more about modifying the kernel than making a PKGBUILD.


aur S & M :: forum rules :: Community Ethos
Resources for Women, POC, LGBT*, and allies

Offline

#7 2012-07-10 16:13:32

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

Re: [solved] add a new syscall to kernel 3.4

yes it is, but when you finish to modify the kernel you use makepkg to compile, and I'd also like to know about some tricks to make the compilation faster!

Offline

#8 2012-07-11 07:20:47

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

Re: [solved] add a new syscall to kernel 3.4

new day = new discussion : )

how do I modify the kernel 3.4.4 in order to add a new system call, the question are:
where is the system call table?
if I insert the system call code in a directory (for example: src/new_syscall/, what about the Makefile inside that directory and the main PKGBUILD?
inserting a new entry in the system call table and writing the system call code are enough?
which are differences between x86 and x86_64?

Offline

#9 2012-07-17 15:15:49

alwaysanoob
Member
Registered: 2010-01-20
Posts: 22

Re: [solved] add a new syscall to kernel 3.4

for anyone who cares:
I have compiled and runned the custom kernel with a new dummy syscall

1. https://wiki.archlinux.org/index.php/Ke … ild_System
this contains main steps needed for kernel compilation with ABS

2. create a testing folder in src root: src/linux-3.4/testing/
put inside this folder:
- a file that contains syscall code: strcpy.c

#include <linux/linkage.h>
#include <linux/kernel.h>
asmlinkage long sys_strcpy(char *dest, char *src)
{
	int i=0;
	while(src[i]!=0) {
		dest[i]=src[i++];
	}
	dest[i]=0;
	printk("<1>done it!");
	return 1;
}

- and the Makefile that contains just the following line:

 obj-y:=strcpy.o

3. add an entry to the syscall table and the prototype of the function:
- edit the file src/linux-3.4/arch/x86/syscalls/syscall_32.tbl by adding this line to the entry 223 that is free

223	i386	strcpy			sys_strcpy

- edit the file src/linux-3.4/include/linux/syscalls.h by adding the prototype of the function

asmlinkage long sys_strcpy(char	*dest, char *src);

4. edit the main Makefile in the src root (src/linux-3.4/Makefile) by adding the testing folder created before, as follow:

core-y		+= kernel/ mm/ fs/ ipc/ security/ crypto/ block/ testing/

You have done!!
Compile the kernel and install the package as explained in #1.
Run the custom kernel and write a simple program like this to test the strcpy that's now a syscall (you are not including string.h in order to use strcpy):

#include <stdio.h>
int main(int argc, char *argv){
	char *src="testing the syscall";
	char dest[40];
	syscall(223,dest,src);
	printf("copied string:%s\n",dest);
}

Note that the number of the system call is the same defined before; in order to read the message written by the printk function, exec the command dmesg.

Edit the file /etc/makepkg.conf if you want to use all your cores during compilation phase:
#-- Make Flags: change this for DistCC/SMP systems
#MAKEFLAGS="-j2"
2 is for a single core, add 1 for any other core you are going to use.
You can use makepkg -e if you want to compile faster, but remember to comment patches in the PKGBUILD before doing this.

BYE

Last edited by alwaysanoob (2012-07-17 21:10:00)

Offline

Board footer

Powered by FluxBB