The HyperNews Linux KHG Discussion Pages

Question: Problem creating a new system call

Forum: The Linux Kernel Hackers' Guide
Date: Sat, 11 Oct 1997 15:10:13 GMT
From: <>

Thanks for your time, friend. I have a small request for you. My question is a little descriptive, so if you can, please read it completely. I would appreciate it. Thanks.

Just to learn how to generate a system call, I created a simple system call that basically sets and resets the value of a global parameter "PREFETCH".

**************** SYSTEM CALL code ********************************** int PREFETCH = 0; /* this is a global variable */

int initialize (int nr_hints)
 printk ("prefetch routine to be initialized\n");

 if (PREFETCH == 1)
	return 0;   
 return 1;

int terminate ()
 return 1;

asmlinkage int sys_prefetch (int mode, int nr_hints)
 printk ("prefetch system call called\n");

 if (mode >= 0)
	return initialize (nr_hints);
	return terminate ();
**************** SYSTEM CALL code END**********************************

I included this code in /usr/src/linux/fs/buffer.c I then added the following line to arch/i386/kernel/entry.S

     .long SYMBOL_NAME (sys_prefetch)  /* 166 */
and changed 
     .space (NR_syscalls - 166)*4
     .space (NR_syscalls - 167)*4

I then added the following line to include/asm/unistd.h
	#define __NR_prefetch 166

To execute the sys_prefetch system call, I wrote a prefetch.c file with the following code.

************************code to call sys_prefetch***************** #include <linux/unistd.h> _syscall2 (int, prefetch, int, mode, int, nr_hints)

void main()
 (few declarations and statements)
 return_value = prefetch(1, 100);   /* initialize */
 printf ("%d", return_value);
This code compiles and runs but always returns a -1 value and does not 
even print the messages on the screen that I inserted using printk() in the
system call code in buffer.c

Since the messages are not getting printed, I have no way to know if the system call is getting called AT ALL !!!

Thanks for reading it. If you have any insights into the problem, please let me know.

Thanks again. saurabh desai <>