title: Why is my linux syscall returning a -1 in userspace?
body: <p>I tried many guides and for some reason, my syscall isn't even returning a 0 as it should. Where am I going wrong? Here are my steps to creating one: </p>
  
  <p>inside "/linux/" folder: 
  I created a folder called "mycall" with files mycall.c, mycall.h, &amp; Makefile</p>
  
  <p>mycall.c:</p>
  
  <pre><code>#include &lt;linux/kernel.h&gt;
  #include &lt;linux/init.h&gt;
  #include &lt;sched.h&gt;
  #include &lt;syscalls.h&gt;
  #include &lt;linux/unistd.h&gt;
  #include "mycall.h"
  
  asmlinkage long sys_mysyscall(int *id, int username, int *size)
  {
   printk("hello");
   return 0;
  }
  </code></pre>
  
  <p>mycall.h:</p>
  
  <pre><code>asmlinkage long sys_mysyscall(int *id, int username, int *size);
  </code></pre>
  
  <p>Makefile:</p>
  
  <pre><code>obj-y := mycall.o
  </code></pre>
  
  <p>then I went into all of the places where I THOUGHT i should declare the syscall. </p>
  
  <pre><code>// inside of /linux/include/linux/syscalls.h
  asmlinkage long sys_mysyscall(int __user *myid, int username, int __user *size);
  </code></pre>
  
  <p>then to </p>
  
  <pre><code>// inside of /linux/arch/arm/tools/syscall.tbl
  398    common  mysyscall      sys_mysyscall
  </code></pre>
  
  <p>finally i added </p>
  
  <pre><code>// inside of /linux/Makefile
  core-y    += kernel/ certs/ mm/ fs/ ipc/ security/ crypt/ block/ mycall/
  </code></pre>
  
  <p>thats my set up. then the final thing I do is make a userspace in /linux directory
  userspace.c:</p>
  
  <pre><code>#include &lt;linux/kernel.h&gt;
  #include &lt;sys/syscall.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;pwd.h&gt;
  
  int main () 
  {
  int id = 0;
  int username = 7;
  int size = 2;
  int ret_val = syscall(398, &amp;id, username, &amp;size);
  printf("%d\n", ret_val);
  return 0;
  }
  </code></pre>
  
  <p>the return value is -1 so this doesn't work. please let me know what I'm doing wrong. I have read several implementation guides. </p>
  
  <p>ERRNO is 38 . Function not implemented. </p>