riscv-software-src / riscv-pk

RISC-V Proxy Kernel
Other
596 stars 308 forks source link

pk: correct the handling of SYS_getcwd #250

Closed compnerd closed 3 years ago

compnerd commented 3 years ago

SYS_getcwd is different from getcwd in that the return value is < 0 on failure otherwise it is the length of the string. The proxy kernel was treating 0 as success and all other values as error. As a result, we would never return a valid value for getcwd.

The following program now executes properly with the Proxy Kernel:

  #include <stdio.h>
  #include <stdlib.h>
  #include <unistd.h>

  #include <linux/limits.h>

  int main(int argc, char **argv) {
    unsigned char buffer[PATH_MAX + 1] = {0};
    if (getcwd(buffer, PATH_MAX))
      printf("cwd: %s\n", buffer);
    return EXIT_SUCCESS;
  }