title: Implementing custom system call in android kernel
body: <p>I am trying to implement a simple custom system call in the Nexus 4's kernel (mako). I have taken these five steps so far:</p>
  
  <ol>
  <li><p>msm/arch/arm/kernel/calls.S</p>
  
  <pre><code>...
  /* 375 */   CALL(sys_setns)
  CALL(sys_process_vm_readv)
  CALL(sys_process_vm_writev)
  CALL(sys_hello)             /* a custom system call */ 
  </code></pre></li>
  <li><p>msm/include/linux/syscalls.h</p>
  
  <pre><code>...
  asmlinkage long sys_process_vm_writev(pid_t pid,
                const struct iovec __user *lvec,
                unsigned long liovcnt,
                const struct iovec __user *rvec,
                unsigned long riovcnt,
                unsigned long flags);
  asmlinkage long sys_hello(void);
  </code></pre></li>
  <li><p>msm/arch/arm/include/asm/unistd.h</p>
  
  <pre><code>...
  #define __NR_setns                  (__NR_SYSCALL_BASE+375)
  #define __NR_process_vm_readv       (__NR_SYSCALL_BASE+376)
  #define __NR_process_vm_writev      (__NR_SYSCALL_BASE+377)
  #define __NR_sys_hello              (__NR_SYSCALL_BASE+378)
  </code></pre></li>
  <li><p>msm/Makefile</p>
  
  <pre><code>...
  # Objects we will link into vmlinux / subdirs we need to visit
  ...
  core-y      := usr/ hello/
  </code></pre></li>
  <li><p>msm/hello/sys_hello.c &amp; msm/hello/Makefile</p>
  
  <pre><code>#include &lt;asm/unistd.d&gt;
  #include &lt;linux/linkage.h&gt;
  
  asmlinkage long sys_hello(void) {
      printk("Hello world\n");
      return 0;
  }
  
  ##### BEGIN MAKEFILE #####
  obj-y := sys_hello.o
  ##### END MAKEFILE #####
  </code></pre></li>
  </ol>
  
  <p>I also used <a href="http://forum.xda-developers.com/nexus-4/general/howto-build-nexus-4-kernel-t2021202" rel="nofollow">this guide</a> to set up to build the kernel.</p>
  
  <p>When I execute the <code>make mako_defconfig</code> and then <code> make -j4</code> (this is from the guide), I am getting these errors:</p>
  
  <pre><code>arm-eabi-gcc -Wp,-MD,scripts/mod/.empty.o.d -nostdinc -isystem arm-eabi-gcc -print-file-name=include [Errno 13] Permission denied -I/Users/Edward/CMSI/android-kernel/kernel/msm/arch/arm/include -Iarch/arm/include/generated -Iinclude -include /Users/Edward/CMSI/android-kernel/kernel/msm/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-msm/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -fstack-protector -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables -D__LINUX_ARM_ARCH__=7 -march=armv5t -Wa,-march=armv7-a -msoft-float -Uarm -fomit-frame-pointer -g -DKBUILD_STR(s)=#s -DKBUILD_BASENAME=KBUILD_STR(empty) -DKBUILD_MODNAME=KBUILD_STR(empty) -c -o scripts/mod/empty.o scripts/mod/empty.c [Errno 13] Permission denied
  make[2]: *** [scripts/mod/empty.o] Error 13
  make[1]: *** [scripts/mod] Error 2
  make[1]: *** Waiting for unfinished jobs....
  make: *** [scripts] Error 2
  make: *** Waiting for unfinished jobs....
  </code></pre>
  
  <p>I am unable to determine if it's my fault in building the kernel, if I have missed a step so that the kernel identifies the new custom system call, or if there is a permission error with one of the files I modified.</p>
  
  <p>Any suggestions would be helpful, this is my first time building a kernel for an Android device.</p>
  
  <p>Edit: Now getting this error:</p>
  
  <pre><code>arm-eabi-gcc -Wp,-MD,kernel/.bounds.s.d -nostdinc -isystem arm-eabi-gcc -print-file-name=include [Errno 13] Permission denied -I/Users/Edward/CMSI/android-kernel/kernel/msm/arch/arm/include -Iarch/arm/include/generated -Iinclude -include /Users/Edward/CMSI/android-kernel/kernel/msm/include/linux/kconfig.h -D__KERNEL__ -mlittle-endian -Iarch/arm/mach-msm/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -Wno-format-security -fno-delete-null-pointer-checks -Os -fstack-protector -mabi=aapcs-linux -mno-thumb-interwork -funwind-tables -D__LINUX_ARM_ARCH__=7 -march=armv5t -Wa,-march=armv7-a -msoft-float -Uarm -fomit-frame-pointer -g -DKBUILD_STR(s)=#s -DKBUILD_BASENAME=KBUILD_STR(bounds) -DKBUILD_MODNAME=KBUILD_STR(bounds) -fverbose-asm -S -o kernel/bounds.s kernel/bounds.c [Errno 13] Permission denied
  make[1]: *** [kernel/bounds.s] Error 13
  make: *** [prepare0] Error 2
  </code></pre>