Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a value into a system call function in XV6?

I am attempting to create a simple priority based scheduler in XV6. To do this, I also have to create a system call that will allow a process to set its priority. I have done everything required to create the system call as discussed here and elsewhere:

how do i add a system call / utility in xv6

The problem is, I cannot pass any variables when I call the function, or rather, it runs like nothing is wrong but the correct values do not show up inside the function.

Extern declaration (syscall.c):

...
extern int sys_setpty(void);

static int (*syscalls[])(void) = {
...
[SYS_setpty]  sys_setpty,
};

Sys-call Vector (syscall.h):

#define SYS_setpty 22

Implementation (sysproc.c):

void
sys_setpty(int pid, int pty)
{
  cprintf("function pid: %d \n", pid);
  cprintf("function pty: %d \n", pty);
}

(defs.h & user.h):

void setpty(int, int);

Macro (usys.S):

SYSCALL(setpty)

Function call:

setpty(3, 50);

Output:

function pid: 16843009
function pty: 16843009

The values are always the same exact number: 16843009. I have checked to see if the cprintf is working correctly by assigning values to pid and pty. I have spent about 6 hours trying every possible combination of everything I can think of and I'm starting to think that there is no built in mechanism for passing values via a system call in XV6. Am I missing something? Thank you in advance.

like image 377
bertmoog Avatar asked Nov 21 '14 18:11

bertmoog


People also ask

How do you pass arguments in XV6?

Xv6 has its own functions for passing arguments from user space to kernel space (system call). You can use argint() to retrieve integer arguments in your system call and argstr() to retrieve string arguments.

How do system calls work in XV6?

Adding new system call to xv6 : A computer program makes system call when it makes request to operating system's kernel. System calls are used for hardware services, to create or execute process, and for communicating with kernel services, including application and process scheduling.

How does argint work XV6?

Here's a high-level understanding of how it works: argint accesses the parameters with some pointer math. It accesses the trapframe struct of the process, containing the user-space registers of the syscall. The trapframe saved the function's parameters starting at the esp register.


1 Answers

Passing arguments from user-level functions to kernel-level functions cannot be done in XV6. XV6 has its own built-in functions for passing arguments into a kernel function. For instance, to pass in an integer, the argint() function is called. In the implementation that I used for the set-priority function, that would look something like:

argint(0, &pid);

... to get the first argument which is the Process ID, and:

argint(1, &pty);

... to get the second argument which is the desired priority. The function call from the user process looks like this:

setpty(getpid(), priority);
like image 144
bertmoog Avatar answered Oct 06 '22 00:10

bertmoog