All of lore.kernel.org
 help / color / mirror / Atom feed
* A confusion about invoking my syscall
@ 2012-06-19  1:39 王哲
  2012-06-19  1:58 ` Jeff Haran
  0 siblings, 1 reply; 8+ messages in thread
From: 王哲 @ 2012-06-19  1:39 UTC (permalink / raw)
  To: kernelnewbies

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 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19  1:39 A confusion about invoking my syscall 王哲
@ 2012-06-19  1:58 ` Jeff Haran
  2012-06-19  4:32   ` 王哲
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff Haran @ 2012-06-19  1:58 UTC (permalink / raw)
  To: kernelnewbies



From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of ??
Sent: Monday, June 18, 2012 6:40 PM
To: kernelnewbies
Subject: A confusion about invoking my syscall

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!

Because it appears you never defined the symbol SYS_mysyscall.

Jeff Haran


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120619/cbd66c84/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19  1:58 ` Jeff Haran
@ 2012-06-19  4:32   ` 王哲
  2012-06-19  8:11     ` Baoquan He
                       ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: 王哲 @ 2012-06-19  4:32 UTC (permalink / raw)
  To: kernelnewbies

2012/6/19 Jeff Haran <jharan@bytemobile.com>

>  ** **
>
> ** **
>
> *From:* kernelnewbies-bounces at kernelnewbies.org [mailto:
> kernelnewbies-bounces at kernelnewbies.org] *On Behalf Of *??
> *Sent:* Monday, June 18, 2012 6:40 PM
> *To:* kernelnewbies
> *Subject:* A confusion about invoking my syscall****
>
> ** **
>
> 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!
>
> Because it appears you never defined the symbol SYS_mysyscall.****
>
> ** I think so,but where shoud i defne the  **symbol SYS_mysyscall ?
>
  and where is the symbol SYS_getpid defined?
>
>
>


> Jeff Haran
>  ****
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120619/f16c0ed4/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19  4:32   ` 王哲
@ 2012-06-19  8:11     ` Baoquan He
  2012-06-19  9:54     ` Matthias Brugger
  2012-06-19 17:21     ` Jeff Haran
  2 siblings, 0 replies; 8+ messages in thread
From: Baoquan He @ 2012-06-19  8:11 UTC (permalink / raw)
  To: kernelnewbies

On Tue, Jun 19, 2012 at 12:32 PM, ?? <wangzhe5004@gmail.com> wrote:

>
>
> 2012/6/19 Jeff Haran <jharan@bytemobile.com>
>
>>  ** **
>>
>> ** **
>>
>> *From:* kernelnewbies-bounces at kernelnewbies.org [mailto:
>> kernelnewbies-bounces at kernelnewbies.org] *On Behalf Of *??
>> *Sent:* Monday, June 18, 2012 6:40 PM
>> *To:* kernelnewbies
>> *Subject:* A confusion about invoking my syscall****
>>
>> ** **
>>
>> 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!
>>
>> Because it appears you never defined the symbol SYS_mysyscall.****
>>
>> ** I think so,but where shoud i defne the  **symbol SYS_mysyscall ?
>>
>   and where is the symbol SYS_getpid defined?
>>
>>
>>
> you can read LKD3 written by Robert Love which describes the process
clearly.

>
>
>> Jeff Haran
>>   ****
>>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120619/b2b73ea6/attachment-0001.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19  4:32   ` 王哲
  2012-06-19  8:11     ` Baoquan He
@ 2012-06-19  9:54     ` Matthias Brugger
  2012-06-19 17:21     ` Jeff Haran
  2 siblings, 0 replies; 8+ messages in thread
From: Matthias Brugger @ 2012-06-19  9:54 UTC (permalink / raw)
  To: kernelnewbies

On 06/19/2012 06:32 AM, ?? wrote:
>
>
> 2012/6/19 Jeff Haran <jharan at bytemobile.com <mailto:jharan@bytemobile.com>>
>
>     __ __
>
>     __ __
>
>     *From:*kernelnewbies-bounces at kernelnewbies.org
>     <mailto:kernelnewbies-bounces@kernelnewbies.org>
>     [mailto:kernelnewbies-bounces at kernelnewbies.org
>     <mailto:kernelnewbies-bounces@kernelnewbies.org>] *On Behalf Of *??
>     *Sent:* Monday, June 18, 2012 6:40 PM
>     *To:* kernelnewbies
>     *Subject:* A confusion about invoking my syscall____
>
>     __ __
>
>     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!
>
>     Because it appears you never defined the symbol SYS_mysyscall.____
>
>     __ I think so,but where shoud i defne the __symbol SYS_mysyscall ?
>
>        and where is the symbol SYS_getpid defined?

Not sure, but I think the syscalls should be defined in syscall.h which 
is included by your program. I suppose that this file is part of libc, 
so there won't be your syscall definition in there.
The easiest way would be to define the syscall by yourself.

Remember that adding a syscall to the linux kernel is a bad idea.

Regards,
Matthias

>
>     Jeff Haran
>     ____
>
>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19  4:32   ` 王哲
  2012-06-19  8:11     ` Baoquan He
  2012-06-19  9:54     ` Matthias Brugger
@ 2012-06-19 17:21     ` Jeff Haran
  2012-06-20  8:15       ` 王哲
  2 siblings, 1 reply; 8+ messages in thread
From: Jeff Haran @ 2012-06-19 17:21 UTC (permalink / raw)
  To: kernelnewbies



From: ?? [mailto:wangzhe5004 at gmail.com]
Sent: Monday, June 18, 2012 9:32 PM
To: Jeff Haran
Cc: kernelnewbies
Subject: Re: A confusion about invoking my syscall


2012/6/19 Jeff Haran <jharan at bytemobile.com<mailto:jharan@bytemobile.com>>


From: kernelnewbies-bounces@kernelnewbies.org<mailto:kernelnewbies-bounces@kernelnewbies.org> [mailto:kernelnewbies-bounces at kernelnewbies.org<mailto:kernelnewbies-bounces@kernelnewbies.org>] On Behalf Of ??
Sent: Monday, June 18, 2012 6:40 PM
To: kernelnewbies
Subject: A confusion about invoking my syscall

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!
Because it appears you never defined the symbol SYS_mysyscall.
 I think so,but where shoud i defne the  symbol SYS_mysyscall ?
  and where is the symbol SYS_getpid defined?
On my system /usr/include/bits/syscall.h, which is being included in your program because it includes syscall.h.
Jeff Haran

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120619/c2efd3fd/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-19 17:21     ` Jeff Haran
@ 2012-06-20  8:15       ` 王哲
  2012-06-20 16:58         ` Jeff Haran
  0 siblings, 1 reply; 8+ messages in thread
From: 王哲 @ 2012-06-20  8:15 UTC (permalink / raw)
  To: kernelnewbies

2012/6/20 Jeff Haran <jharan@bytemobile.com>

>  ** **
>
> ** **
>
> *From:* ?? [mailto:wangzhe5004 at gmail.com]
> *Sent:* Monday, June 18, 2012 9:32 PM
> *To:* Jeff Haran
> *Cc:* kernelnewbies
> *Subject:* Re: A confusion about invoking my syscall****
>
> ** **
>
> ** **
>
> 2012/6/19 Jeff Haran <jharan@bytemobile.com>****
>
>  ****
>
>  ****
>
> *From:* kernelnewbies-bounces at kernelnewbies.org [mailto:
> kernelnewbies-bounces at kernelnewbies.org] *On Behalf Of *??
> *Sent:* Monday, June 18, 2012 6:40 PM
> *To:* kernelnewbies
> *Subject:* A confusion about invoking my syscall****
>
>  ****
>
> 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!****
>
> Because it appears you never defined the symbol SYS_mysyscall.****
>
>  I think so,but where shoud i defne the  symbol SYS_mysyscall ? ****
>
>     and where is the symbol SYS_getpid defined? ****
>
> On my system /usr/include/bits/syscall.h, which is being included in your
> program because it includes syscall.h.
>
>            83 #define SYS_getpid __NR_getpid  ?so SYS_getpid is replaced
by __NR_getpid. and __NR_getpid was defined in the
kernel(arch/x86/include/asm/unistd_32.h). and my syscall was also defined
there.#define SYS_mysyscall __NR_mysyscall, i don't kown why it doesn't
works.



> ****
>
> Jeff Haran****
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120620/4ad9e055/attachment-0001.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* A confusion about invoking my syscall
  2012-06-20  8:15       ` 王哲
@ 2012-06-20 16:58         ` Jeff Haran
  0 siblings, 0 replies; 8+ messages in thread
From: Jeff Haran @ 2012-06-20 16:58 UTC (permalink / raw)
  To: kernelnewbies



From: ?? [mailto:wangzhe5004 at gmail.com]
Sent: Wednesday, June 20, 2012 1:16 AM
To: Jeff Haran
Cc: kernelnewbies
Subject: Re: A confusion about invoking my syscall


2012/6/20 Jeff Haran <jharan at bytemobile.com<mailto:jharan@bytemobile.com>>


From: ?? [mailto:wangzhe5004 at gmail.com<mailto:wangzhe5004@gmail.com>]
Sent: Monday, June 18, 2012 9:32 PM
To: Jeff Haran
Cc: kernelnewbies
Subject: Re: A confusion about invoking my syscall


2012/6/19 Jeff Haran <jharan at bytemobile.com<mailto:jharan@bytemobile.com>>


From: kernelnewbies-bounces@kernelnewbies.org<mailto:kernelnewbies-bounces@kernelnewbies.org> [mailto:kernelnewbies-bounces at kernelnewbies.org<mailto:kernelnewbies-bounces@kernelnewbies.org>] On Behalf Of ??
Sent: Monday, June 18, 2012 6:40 PM
To: kernelnewbies
Subject: A confusion about invoking my syscall

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!
Because it appears you never defined the symbol SYS_mysyscall.
 I think so,but where shoud i defne the  symbol SYS_mysyscall ?
  and where is the symbol SYS_getpid defined?
On my system /usr/include/bits/syscall.h, which is being included in your program because it includes syscall.h.
           83 #define SYS_getpid __NR_getpid  ?so SYS_getpid is replaced by __NR_getpid. and __NR_getpid was defined in the kernel(arch/x86/include/asm/unistd_32.h). and my syscall was also defined there.#define SYS_mysyscall __NR_mysyscall, i don't kown why it doesn't works.

My sources contain no reference to SYS_mysyscall nor __NR_mysyscall, so I assume you?ve added them to the Linux include files that you built your module from.

User space programs like your main() program above generally aren?t going to include Linux source tree include files. When you include <syscall.h> from a user space program in a typical development environment, the compiler is by default going to look for syscall.h in /usr/include, not in the Linux source tree where presumably you?ve made your modifications. Of course you can always tell the compiler to look there using the -I command line option to gcc, if you want to. The usual practice however is to keep kernel code and user code include files completely separate. That means some duplication of effort, like having to define SYS_mysyscall in two different places, but that?s the usual practice because most people aren?t building kernels and thus haven?t installed the kernel source include files.

Jeff Haran


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120620/4287a36b/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2012-06-20 16:58 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-19  1:39 A confusion about invoking my syscall 王哲
2012-06-19  1:58 ` Jeff Haran
2012-06-19  4:32   ` 王哲
2012-06-19  8:11     ` Baoquan He
2012-06-19  9:54     ` Matthias Brugger
2012-06-19 17:21     ` Jeff Haran
2012-06-20  8:15       ` 王哲
2012-06-20 16:58         ` Jeff Haran

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.