Skip to main content

Posts

Showing posts from May, 2016

How to add a system call in xv6?

I will explain a simple example on adding a system call in xv6. Assume that you have to add a system call to get the address space size of the currently running user program. You can name your system call as getmysize() and call this system call from within a user program. You can write your user program as follows. Let the program name be  myprog.c  I assume that you know how to add a user program to xv6. So I will skip mentioning those steps here because it will be off the topic. #include "types.h" #include "stat.h" #include "user.h" int main(void){ printf(1,"The size of my address space is %d bytes\n", getmysize()); exit(); } This program is written for the purpose of demonstrating the working of the system call only. Now we will add our system call to xv6. First add the following line at the end of the file  syscall.h . #define SYS_getmysize 23 Note that the 23 here might change depending on the number given before the li