Giter VIP home page Giter VIP logo

xv6-syscalls-ipc's Introduction

XV6-Syscalls-IPC

Introducing new system calls and inter-process-communication in xv6

xv6 is a teaching operating system, that is most likely be helpful for students in learning the basics of operating system. It contains the most important and basic parts of an operating system. See more about it here.

How to add a system call that can be called in xv6's shell?

- `sysproc.c`: Add the real implementation of your method here (or can do in `sysfile.c` as well)
- `syscall.c`: External define the function that connect the shell and the kernel, use the position defined in `syscall.h` to add the function to the system call vector
- `syscall.h`: Define the position of the system call vector that connect to your implementation
- `user.h`: Define the function that can be called through the shell
- `usys.S`: Use the macro to define connect the call of user to the system call function

See a similar type of question on stack overflow here.

Implementing Syscalls in xv6

  1. Implementing a system call trace: It will have two states: ON and OFF. Let us define it with a new system call sys_print_count. It will print the list of system calls that have been invoked since the last transition to the ON state with their counts.

For e.g.:

sys_fork 10
sys_read 12
sys_write 1 </

// actual function goes in `sysproc.c`
int
sys_print_count(void)
{
  int i;
  for(i=0; i<25; i++){
    if(call_count_history[i] != 0){
      cprintf("%s %d\n", call_name_history[i], call_count_history[i]);
    }
  }
  return 0;
}


// add one more system call in `user.h`
int print_count(void);
// and in `usys.S`
SYSCALL(print_count)
// and in syscall.h: With a unqiue integer (incremented from the previous one)
#define SYS_print_count 22 // (22nd system call)



// Initialise variables as extern in sysproc.c, so that we can use it inter-file
extern int call_count_history[25];
extern char *call_name_history[25];



/* modify syscall.c to count the number of times a sys_call has called */
// 1. Initialise variables
int toggle = 0;
int call_count_history[25] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char *call_name_history[25] = {"sys_fork", "sys_exit", "sys_wait", "sys_pipe", "sys_read", "sys_kill", "sys_exec", "sys_fstat", "sys_chdir", "sys_dup", "sys_getpid", "sys_sbrk", "sys_sleep", "sys_uptime", "sys_open", "sys_write", "sys_mknod", "sys_unlink", "sys_link", "sys_mkdir", "sys_close", "sys_print_count"};


void
syscall(void)
{
  int num;
  struct proc *curproc = myproc();

  num = curproc->tf->eax;
  if(num > 0 && num < NELEM(syscalls) && syscalls[num]) {
  
    // add up in number of times a sys call has appeared
    call_count_history[num-1] += 1;
	// ...

    curproc->tf->eax = syscalls[num]();
  } else {
    cprintf("%d %s: unknown sys call %d\n",
            curproc->pid, curproc->name, num);
    curproc->tf->eax = -1;
  }
}

xv6-syscalls-ipc's People

Contributors

techcentaur avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.