如何在XV6中将值传递给系统调用函数?

ber*_*oog 8 c system function call xv6

我试图在XV6中创建一个简单的基于优先级的调度程序.为此,我还必须创建一个允许进程设置其优先级的系统调用.我已经完成了创建系统调用所需的所有内容,如此处和其他地方所述:

如何在xv6中添加系统调用/实用程序

问题是,当我调用函数时,我无法传递任何变量,或者更确切地说,它运行时没有任何错误,但正确的值不会显示在函数内部.

外部声明(syscall.c):

...
extern int sys_setpty(void);

static int (*syscalls[])(void) = {
...
[SYS_setpty]  sys_setpty,
};
Run Code Online (Sandbox Code Playgroud)

系统调用向量(syscall.h):

#define SYS_setpty 22
Run Code Online (Sandbox Code Playgroud)

实现(sysproc.c):

void
sys_setpty(int pid, int pty)
{
  cprintf("function pid: %d \n", pid);
  cprintf("function pty: %d \n", pty);
}
Run Code Online (Sandbox Code Playgroud)

(defs.h和user.h):

void setpty(int, int);
Run Code Online (Sandbox Code Playgroud)

宏(usys.S):

SYSCALL(setpty)
Run Code Online (Sandbox Code Playgroud)

功能调用:

setpty(3, 50);
Run Code Online (Sandbox Code Playgroud)

输出:

function pid: 16843009
function pty: 16843009
Run Code Online (Sandbox Code Playgroud)

这些值始终是完全相同的确定数字:16843009.我已经通过为pid和pty分配值来检查cprintf是否正常工作.我花了大约6个小时尝试了我能想到的所有可能的组合,并且我开始认为没有内置的机制来通过XV6中的系统调用传递值.我错过了什么吗?先感谢您.

ber*_*oog 12

在XV6中无法将参数从用户级函数传递到内核级函数.XV6有自己的内置函数,用于将参数传递给内核函数.例如,要传入一个整数,调用argint()函数.在我用于set-priority函数的实现中,它看起来像:

argint(0, &pid);
Run Code Online (Sandbox Code Playgroud)

...获取第一个参数,即进程ID,并且:

argint(1, &pty);
Run Code Online (Sandbox Code Playgroud)

...获得第二个参数,这是所需的优先级.来自用户进程的函数调用如下所示:

setpty(getpid(), priority);
Run Code Online (Sandbox Code Playgroud)