A confusion about invoking my syscall

王哲 wangzhe5004 at gmail.com
Mon Jun 18 21:39:53 EDT 2012


Hello everyone:

         I append a simple syscall in kernel. and the function is as
follows:

  asmlinkage  long sys_mysyscall(long data)
 {
          printk("This is my syscall!\n");
          return data;
  }

and i test it sucessfully in user space . and the test program:

   #include
<linux/unistd.h>

   #include <syscall.h>
   #include <sys/types.h>
   #include <stdio.h>



   int main(void)
   {
   long n = 0,m = 0,pid1,pid2;
   n = syscall(345,190);// #define __NR_mysyscall          345
   printf("n = %ld\n",n);
   pid1 = syscall(SYS_getpid);  //getpid
   printf("pid = %ld\n",pid1);
   pid2 = syscall(20);  //getpid
   printf("pid = %ld\n",pid2);
   return 0;
  }
and the result:
n = 190
pid = 4097
pid = 4097

but if the test program is:
#include <linux/unistd.h>
#include <syscall.h>
#include <sys/types.h>
#include <stdio.h>



int main(void)
{
 long n = 0,m = 0,pid1,pid2;
 n = syscall(345,190);// #define __NR_mysyscall          345
 printf("n = %ld\n",n);
 m = syscall(SYS_mysyscall,190);
 printf("m = %ld\n",m);
 pid1 = syscall(SYS_getpid);  //getpid
 printf("pid = %ld\n",pid1);
 pid2 = syscall(20);  //getpid
 printf("pid = %ld\n",pid2);
 return 0;
}
and the result:
wanny at wanny-C-Notebook-XXXX:~/syscall/src$ gcc test1.c
test1.c: In function ‘main’:
test1.c:13:14: error: ‘SYS_mysyscall’ undeclared (first use in this
function)
test1.c:13:14: note: each undeclared identifier is reported only once for
each function it appears in


why i can't invoke my syscall with "SYS_mysyscall"?

Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120619/692ba190/attachment.html 


More information about the Kernelnewbies mailing list