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

I am trying to create a simple priority-based scheduler in XV6. To do this, I also need to create a system call that allows the process to set priority. I did everything necessary to create a system call, as described here and elsewhere:

how to add system call / utility in xv6

The problem is that I cannot pass any variables when the function is called, or rather, it works like nothing is wrong, but the correct values ​​are not displayed 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 and user.h):

 void setpty(int, int); 

Macro (usys.S):

 SYSCALL(setpty) 

Function call:

 setpty(3, 50); 

Conclusion:

 function pid: 16843009 function pty: 16843009 

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

+5
source share
1 answer

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 to the kernel function. For example, to pass an integer, the argint () function is called. In the implementation that I used for the set-priority function, this would look like this:

 argint(0, &pid); 

... to get the first argument, which is the process identifier, and:

 argint(1, &pty); 

... to get the second argument, which is the desired priority. The function call from the user process is as follows:

 setpty(getpid(), priority); 
+9
source

Source: https://habr.com/ru/post/1207439/


All Articles