Trying to add a new system call in linux kernel 4.18.13, but failed to pass function parameters

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Ubuntu18, linux kernel 4.18.13



I added a new system call with following steps:
1. edit ./arth/x86/entry/syscalls/syscall_64.tbl



401 common my_syscall sys_my_syscall



  1. edit ./arth/x86/include/asm/syscalls.h

asmlinkage int sys_my_syscall(...)



  1. and the ./mine/my_syscall.c, ./mine/my_syscall.h:

my_syscall.c



#include <linux/linkage.h>
asmlinkage int sys_my_syscall(int n)
printk("test %dn", n);
return n;



my_syscall.h



#ifndef HELLO_WORLD_H
#define HELLO_WORLD_H
asmlinkage int sys_my_syscall(int n);
#endif


  1. then use Makefile to make the new files in step 3.


  2. compile the kernel.



  3. try my syscall with the following program:



    #include <stdio.h>
    #include <linux/unistd.h>
    int main()
    int ret = syscall(401, 20);
    printf("ret %dn", ret);
    return 0;



And the syscall is successfully called. I can see the "test xxx" and "ret xxx" on my terminal. However, the parameter I pass into the syscall was wrong -- it is always an undefined number, 1018123134, -2021134452, and so on.



see step 2 above:



  1. edit ./arth/x86/include/asm/syscalls.h

asmlinkage int sys_my_syscall(...)



You see (...), where I tried (char*), (int), (int, int), (char*, int) but none of them can make it correct. I dont know the principle here. Or maybe the problem is caused by other mistakes?



However, my friend tried the same method but succeeded in linux kernel 4.7.x! How could that be?



I have tried to search by google but failed to find the same problem. Could anyone help me to pass the parameter to my syscall? Thanks very much!



Ubuntu18, linux kernel 4.18.13









share







New contributor




JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    0
    down vote

    favorite












    Ubuntu18, linux kernel 4.18.13



    I added a new system call with following steps:
    1. edit ./arth/x86/entry/syscalls/syscall_64.tbl



    401 common my_syscall sys_my_syscall



    1. edit ./arth/x86/include/asm/syscalls.h

    asmlinkage int sys_my_syscall(...)



    1. and the ./mine/my_syscall.c, ./mine/my_syscall.h:

    my_syscall.c



    #include <linux/linkage.h>
    asmlinkage int sys_my_syscall(int n)
    printk("test %dn", n);
    return n;



    my_syscall.h



    #ifndef HELLO_WORLD_H
    #define HELLO_WORLD_H
    asmlinkage int sys_my_syscall(int n);
    #endif


    1. then use Makefile to make the new files in step 3.


    2. compile the kernel.



    3. try my syscall with the following program:



      #include <stdio.h>
      #include <linux/unistd.h>
      int main()
      int ret = syscall(401, 20);
      printf("ret %dn", ret);
      return 0;



    And the syscall is successfully called. I can see the "test xxx" and "ret xxx" on my terminal. However, the parameter I pass into the syscall was wrong -- it is always an undefined number, 1018123134, -2021134452, and so on.



    see step 2 above:



    1. edit ./arth/x86/include/asm/syscalls.h

    asmlinkage int sys_my_syscall(...)



    You see (...), where I tried (char*), (int), (int, int), (char*, int) but none of them can make it correct. I dont know the principle here. Or maybe the problem is caused by other mistakes?



    However, my friend tried the same method but succeeded in linux kernel 4.7.x! How could that be?



    I have tried to search by google but failed to find the same problem. Could anyone help me to pass the parameter to my syscall? Thanks very much!



    Ubuntu18, linux kernel 4.18.13









    share







    New contributor




    JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Ubuntu18, linux kernel 4.18.13



      I added a new system call with following steps:
      1. edit ./arth/x86/entry/syscalls/syscall_64.tbl



      401 common my_syscall sys_my_syscall



      1. edit ./arth/x86/include/asm/syscalls.h

      asmlinkage int sys_my_syscall(...)



      1. and the ./mine/my_syscall.c, ./mine/my_syscall.h:

      my_syscall.c



      #include <linux/linkage.h>
      asmlinkage int sys_my_syscall(int n)
      printk("test %dn", n);
      return n;



      my_syscall.h



      #ifndef HELLO_WORLD_H
      #define HELLO_WORLD_H
      asmlinkage int sys_my_syscall(int n);
      #endif


      1. then use Makefile to make the new files in step 3.


      2. compile the kernel.



      3. try my syscall with the following program:



        #include <stdio.h>
        #include <linux/unistd.h>
        int main()
        int ret = syscall(401, 20);
        printf("ret %dn", ret);
        return 0;



      And the syscall is successfully called. I can see the "test xxx" and "ret xxx" on my terminal. However, the parameter I pass into the syscall was wrong -- it is always an undefined number, 1018123134, -2021134452, and so on.



      see step 2 above:



      1. edit ./arth/x86/include/asm/syscalls.h

      asmlinkage int sys_my_syscall(...)



      You see (...), where I tried (char*), (int), (int, int), (char*, int) but none of them can make it correct. I dont know the principle here. Or maybe the problem is caused by other mistakes?



      However, my friend tried the same method but succeeded in linux kernel 4.7.x! How could that be?



      I have tried to search by google but failed to find the same problem. Could anyone help me to pass the parameter to my syscall? Thanks very much!



      Ubuntu18, linux kernel 4.18.13









      share







      New contributor




      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      Ubuntu18, linux kernel 4.18.13



      I added a new system call with following steps:
      1. edit ./arth/x86/entry/syscalls/syscall_64.tbl



      401 common my_syscall sys_my_syscall



      1. edit ./arth/x86/include/asm/syscalls.h

      asmlinkage int sys_my_syscall(...)



      1. and the ./mine/my_syscall.c, ./mine/my_syscall.h:

      my_syscall.c



      #include <linux/linkage.h>
      asmlinkage int sys_my_syscall(int n)
      printk("test %dn", n);
      return n;



      my_syscall.h



      #ifndef HELLO_WORLD_H
      #define HELLO_WORLD_H
      asmlinkage int sys_my_syscall(int n);
      #endif


      1. then use Makefile to make the new files in step 3.


      2. compile the kernel.



      3. try my syscall with the following program:



        #include <stdio.h>
        #include <linux/unistd.h>
        int main()
        int ret = syscall(401, 20);
        printf("ret %dn", ret);
        return 0;



      And the syscall is successfully called. I can see the "test xxx" and "ret xxx" on my terminal. However, the parameter I pass into the syscall was wrong -- it is always an undefined number, 1018123134, -2021134452, and so on.



      see step 2 above:



      1. edit ./arth/x86/include/asm/syscalls.h

      asmlinkage int sys_my_syscall(...)



      You see (...), where I tried (char*), (int), (int, int), (char*, int) but none of them can make it correct. I dont know the principle here. Or maybe the problem is caused by other mistakes?



      However, my friend tried the same method but succeeded in linux kernel 4.7.x! How could that be?



      I have tried to search by google but failed to find the same problem. Could anyone help me to pass the parameter to my syscall? Thanks very much!



      Ubuntu18, linux kernel 4.18.13







      linux linux-kernel system-calls





      share







      New contributor




      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 5 mins ago









      JM233333

      1




      1




      New contributor




      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      JM233333 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          active

          oldest

          votes











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          JM233333 is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476189%2ftrying-to-add-a-new-system-call-in-linux-kernel-4-18-13-but-failed-to-pass-func%23new-answer', 'question_page');

          );

          Post as a guest



































          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          JM233333 is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          JM233333 is a new contributor. Be nice, and check out our Code of Conduct.












          JM233333 is a new contributor. Be nice, and check out our Code of Conduct.











          JM233333 is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f476189%2ftrying-to-add-a-new-system-call-in-linux-kernel-4-18-13-but-failed-to-pass-func%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Displaying single band from multi-band raster using QGIS

          How many registers does an x86_64 CPU actually have?