“value not ignored \”(argaddr(0, &fva)\””

huangapple go评论60阅读模式
英文:

value not ignored "(argaddr(0, &fva)"

问题

抱歉,以下是翻译好的部分:

我想要添加 xv6 页面表功能。然而,出现了一些关于 argaddrargint 的错误。为什么?

实验参考链接:xv6 页面表

int sys_pgaccess(void){
  uint64 fva;
  int pnum;
  uint64 abits;
  int res = 0;
  pte_t* pte_addr;
  pte_t pte;


  if(argaddr(0, &fva) < 0) {
    return -1;
  }
  if(argint(1, &pnum) < 0) {
    return -1;
  }
kernel/sysproc.c: 在函数‘sys_pgaccess’中:
kernel/sysproc.c:105:6: 错误:应该忽略 void 
  105 |   if(argaddr(0, &fva) < 0) {
      |      ^~~~~~~~~~~~~~~~
kernel/sysproc.c:108:6: 错误:应该忽略 void 
  108 |   if(argint(1, &pnum) < 0) {
      |      ^~~~~~~~~~~~~~~~

我是初学者,所以我查看了 argaddr 等函数的代码,但无法理解它。

英文:

I am looking to add xv6 page table functionality. However, for some reason I am getting errors with argaddr and argint. Why?

Lab reference: xv6 page table

int sys_pgaccess(void){
  uint64 fva;
  int pnum;
  uint64 abits;
  int res = 0;
  pte_t* pte_addr;
  pte_t pte;


  if(argaddr(0, &amp;fva) &lt; 0) {
    return -1;
  }
  if(argint(1, &amp;pnum) &lt; 0) {
    return -1;
  }
kernel/sysproc.c: In function &#39;sys_pgaccess&#39;:
kernel/sysproc.c:105:6: error: void value not ignored as it ought to be
  105 |   if(argaddr(0, &amp;fva) &lt; 0) {
      |      ^~~~~~~~~~~~~~~~
kernel/sysproc.c:108:6: error: void value not ignored as it ought to be
  108 |   if(argint(1, &amp;pnum) &lt; 0) {
      |      ^~~~~~~~~~~~~~~~

I am a beginner so I looked at the code for argaddr, etc., but could not understand it.

答案1

得分: 4

The compiler is telling you that argaddr and argint are void functions, and do not return a value.

You cannot compare nothing with an integer.

Looking at kernel/syscall.c from mit-pdos/xv6-riscv, we can see the RISC-V function definitions:

// Fetch the nth 32-bit system call argument.
void
argint(int n, int *ip)
{
  *ip = argraw(n);
}

// Retrieve an argument as a pointer.
// Doesn't check for legality, since
// copyin/copyout will do that.
void
argaddr(int n, uint64 *ip)
{
  *ip = argraw(n);
}

The contents of the lab linked deal with RISC-V.

It appears you should simply remove the conditionals:

int sys_pgaccess(void)
{
  uint64 fva;
  int pnum;
  /* ... */
 
  argaddr(0, &amp;fva);
  argint(1, &amp;pnum);
  /* ... */
}

For completeness, the x86 versions of these functions do return values, so you may have read the wrong documentation.

syscall.c from the no longer maintained mit-pdos/xv6-public contains the x86 definitions:

// Fetch the int at addr from the current process.
int
fetchint(uint addr, int *ip)
{
  struct proc *curproc = myproc();

  if(addr &gt;= curproc-&gt;sz || addr+4 &gt; curproc-&gt;sz)
    return -1;
  *ip = *(int*)(addr);
  return 0;
}

// Fetch the nth 32-bit system call argument.
int
argint(int n, int *ip)
{
  return fetchint((myproc()-&gt;tf-&gt;esp) + 4 + 4*n, ip);
}

// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  struct proc *curproc = myproc();
 
  if(argint(n, &amp;i) &lt; 0)
    return -1;
  if(size &lt; 0 || (uint)i &gt;= curproc-&gt;sz || (uint)i+size &gt; curproc-&gt;sz)
    return -1;
  *pp = (char*)i;
  return 0;
}
英文:

The compiler is telling you that argaddr and argint are void functions, and do not return a value.

You cannot compare nothing with an integer.

Looking at kernel/syscall.c from mit-pdos/xv6-riscv, we can see the RISC-V function definitions:

// Fetch the nth 32-bit system call argument.
void
argint(int n, int *ip)
{
  *ip = argraw(n);
}

// Retrieve an argument as a pointer.
// Doesn&#39;t check for legality, since
// copyin/copyout will do that.
void
argaddr(int n, uint64 *ip)
{
  *ip = argraw(n);
}

The contents of the lab linked deal with RISC-V.

It appears you should simply remove the conditionals:

int sys_pgaccess(void)
{
  uint64 fva;
  int pnum;
  /* ... */
 
  argaddr(0, &amp;fva);
  argint(1, &amp;pnum);
  /* ... */
}

For completeness, the x86 versions of these functions do return values, so you may have read the wrong documentation.

syscall.c from the no longer maintained mit-pdos/xv6-public contains the x86 definitions:

// Fetch the int at addr from the current process.
int
fetchint(uint addr, int *ip)
{
  struct proc *curproc = myproc();

  if(addr &gt;= curproc-&gt;sz || addr+4 &gt; curproc-&gt;sz)
    return -1;
  *ip = *(int*)(addr);
  return 0;
}

// Fetch the nth 32-bit system call argument.
int
argint(int n, int *ip)
{
  return fetchint((myproc()-&gt;tf-&gt;esp) + 4 + 4*n, ip);
}

// Fetch the nth word-sized system call argument as a pointer
// to a block of memory of size bytes.  Check that the pointer
// lies within the process address space.
int
argptr(int n, char **pp, int size)
{
  int i;
  struct proc *curproc = myproc();
 
  if(argint(n, &amp;i) &lt; 0)
    return -1;
  if(size &lt; 0 || (uint)i &gt;= curproc-&gt;sz || (uint)i+size &gt; curproc-&gt;sz)
    return -1;
  *pp = (char*)i;
  return 0;
}

huangapple
  • 本文由 发表于 2023年7月3日 13:10:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76601972.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定