Skip to main content

PyTorch Code for Simple Neural Networks for MNIST Dataset

Implementing a new system call in Kernel version 2.6.32

A system call is used by application or user programs to request service from the operating systems. Since the user programs does not have direct access to the kernel whereas the OS has the direct access. OS can access the hardware through system calls only.

The following files has to be modified for implementing a system call

  1. /usr/src/linux-
  2. /usr/src/linux-
  3. /usr/src/linux-
  4. /usr/src/linux-

New set of files to be created

  1. Create a new directory newcall/ inside the path “/usr/src/linux-
  2. Create new files Makefile, newcall.c and put them in the /usr/src/linux- folder
  3. Create new user files (in any folder of Linux) to test the system call
    testnewcall.c, testnewcall.h (created in /home/pradeepkumar)


Find the file /usr/src/linux- and add the following line at the end
".long sys_newcall"  (add without double quotes, but the preceding . should)

open the file /usr/src/linux-
(all the system calls will be defined in this file using #define macro)

This file contains the system call number that is passed to the kernel through the register (EAX) when a system call is invoked.

Add "#define __NR_mycall <Last_System_Call_Num + 1>" at the end of the list.
If the last system call defined here is:
"#define __NR_vmsplice   336", then add:
"#define __NR_newcall   337" at the end of the list. (337 is the new system call number)


Increment the "NR_syscalls" by 1. So, if NR_syscalls is defined as:
"#define NR_syscalls 337", then change it to:
"#define NR_syscalls 338"  (Since we added a new kernel, so the total number of system calls should be incremented)


open the file /usr/src/linux-
Add the following line at the end of the file:
"asmlinkage long sys_newcall(int i);"  (without double quotes)

Full path of the file - /usr/src/linux-
Create a new directory newcall/ under the folder /usr/src/linux-
and include that path to /usr/src/linux-

open the /usr/src/linux-
and find the "core-y += " and append newcall/ to the path (please see the image below)


Create a new file called newcall.c with full path: /usr/src/linux-
/*---Start of newcall.c----*/
#include <linux/linkage.h>
asmlinkage long sys_newcall(int i)
return i*10; //the value passed from the user program will be multiplied by 10
/*---End of newcall.c------*/

Create a new file called Makefile with full path: /usr/src/linux-
and paste the following line
obj-y := newcall.o

Create userspace files to test the system call
create two files testnewcall.c and testnewcall.h and the full path of the files are


#include <stdio.h>
#include "testnewcall.h"
int main(void)
printf("%d\n", newcall(15)); // since 15 is passed, the output should be 15*10=150
return 0;


#define __NR_newcall 337

long newcall(int i)
return syscall(__NR_newcall,i);

Note: "_syscall1(long, mycall, int, i)" this can be added instead of

long newcall(int i)
return syscall(__NR_newcall,i);

Macro _syscall1()

_syscall1(long, newcall, int, i)
the importance of the above syscall is

  • The name of the system call is newcall.
  • It takes one argument.
  • The argument is an int named number.
  • It returns an long.

Testing the new system call
Step 1: Recompile and install the new kernel so that our system call becomes available to the operating system. go to the kernel folder and give command make

Step 2: Reboot the system

Step 3: Compile and execute the user space C file (testnewcall.c) that we created above. (gcc testnewcall.c and then execute ./a.out)

RESULT: You should see the output as 150. This has been tested on kernel

Source: (The above link uses kernel version 2.6.17 and it uses different set of files)

My post uses a recent kernel and it modifies different set of files.

Any doubts, please query through the comments….


  1. In the "testnewcall.h"...why do u use header file "unistd.h" u already defined _NR_newcall 337..

  2. The unistd header defines the syscall system call.

  3. very nice tutorial!!its very friendly to novice programmers of linux

    more power!!

  4. ""Makefile
    Full path of the file – /usr/src/linux-
    Create a new directory newcall/ under the folder /usr/src/linux-
    and include that path to /usr/src/linux-"""
    can you please explain this part in a more simple way?i didn't understand where should i add the path..please thanks in advance

  5. Hi there!
    after i compiled then reboot
    then compiled the testnewcall.c
    and then ./a.out
    the answer is not 150 but -1 :(
    can u please help me thanks

  6. Hi,

    Is _syscallN still valid for use in linux 2.35.4. I seem to be running into errors while using this.and when i do look for the code in unistd.h the unistd.h in arch/x86 doesn't have this .Please comment.


  7. It returns -1 for kernel Why?

  8. -1 means there may be some error, keep trying to resolve..

  9. It could be because the kernel is 2.6.35 instead of 2-6-32?

  10. gcc testnewcall.c gives me a error:
    testnewcall.h error: invalid preprocessing directive #define __NR_newcall 337... Any idea Why?... i have recompiled everything but still it gives me this error

  11. thanks. this helps my project

  12. hi! can we implementing the same system call through module??how can we do?

  13. [...] [...]

  14. what is the meaning of Create a new directory newcall/ under the folder /usr/src/linux- and include that path to /usr/src/linux- you please explain in detail

  15. Right on the button for 32-bit, but what if I'm amd64 and need to use unistd_64.h? syscall_table_32.S does not apply, right? Does something else need to substitute for it?

  16. It returns -1 instead of the expected 150.can any1 help,pliz....??
    I'm using linux 2.6.32-21

  17. it doesn't work it reply -1 just
    I do every things in detail


Post a Comment

Popular posts from this blog

Installing ns3 in Ubuntu 22.04 | Complete Instructions

In this post, we are going to see how to install ns-3.36.1 in Ubuntu 22.04. You can follow the video for complete details Tools used in this simulation: NS3 version ns-3.36.1  OS Used: Ubuntu 22.04 LTS Installation of NS3 (ns-3.36.1) There are some changes in the ns3 installation procedure and the dependencies. So open a terminal and issue the following commands Step 1:  Prerequisites $ sudo apt update In the following packages, all the required dependencies are taken care and you can install all these packages for the complete use of ns3. $ sudo apt install g++ python3 python3-dev pkg-config sqlite3 cmake python3-setuptools git qtbase5-dev qtchooser qt5-qmake qtbase5-dev-tools gir1.2-goocanvas-2.0 python3-gi python3-gi-cairo python3-pygraphviz gir1.2-gtk-3.0 ipython3 openmpi-bin openmpi-common openmpi-doc libopenmpi-dev autoconf cvs bzr unrar gsl-bin libgsl-dev libgslcblas0 wireshark tcpdump sqlite sqlite3 libsqlite3-dev  libxml2 libxml2-dev libc6-dev libc6-dev-i386 libclang-dev llvm-

Installation of NS2 (ns-2.35) in Ubuntu 20.04

Installation of NS2 (ns-2.35) in Ubuntu 20.04 LTS Step 1: Install the basic libraries like      $] sudo apt install build-essential autoconf automake libxmu-dev Step 2: install gcc-4.8 and g++-4.8 open the file using sudo mode $] sudo nano /etc/apt/sources.list Include the following line deb bionic main universe $] sudo apt update $] sudo apt install gcc-4.8 g++-4.8 Step 3:  Unzip the ns2 packages to home folder $] tar zxvf ns-allinone-2.35.tar.gz $] cd ns-allinone-2.35/ns-2.35 Modify the following make files. ~ns-2.35/ Change @CC@ to gcc-4.8 change @CXX@ to g++-4.8 ~nam-1.15/ ~xgraph-12.2/ ~otcl-1.14/ Change in all places  @CC@ to gcc-4.8 @CPP@ or @CXX@ to g++-4.8 open the file: ~ns-2.35/linkstate/ls.h Change at the Line no 137  void eraseAll() { erase(baseMap::begin(), baseMap::end()); } to This void eraseAll() { this->erase(baseMap::begin(), baseMap::end()); } All changes made Step 4: Open a new termi

Installation of NS2 in Ubuntu 22.04 | NS2 Tutorial 2

NS-2.35 installation in Ubuntu 22.04 This post shows how to install ns-2.35 in Ubuntu 22.04 Operating System Since ns-2.35 is too old, it needs the following packages gcc-4.8 g++-4.8 gawk and some more libraries Follow the video for more instructions So, here are the steps to install this software: To download and extract the ns2 software Download the software from the following link Extract it to home folder and in my case its /home/pradeepkumar (I recommend to install it under your home folder) $ tar zxvf ns-allinone-2.35.tar.gz or Right click over the file and click extract here and select the home folder. $ sudo apt update $ sudo apt install build-essential autoconf automake libxmu-dev gawk To install gcc-4.8 and g++-4.8 $ sudo gedit /etc/apt/sources.list make an entry in the above file deb bionic main universe $ sudo apt update Since, it&#