diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2021-08-27 22:58:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-27 22:58:01 -0700 |
commit | 2f3e6f530384b4ab9f8b39bceb8e86f2ba51a835 (patch) | |
tree | c9cfc3d49413a6222be80fd06bec748af607910f | |
parent | 8e29c382bac5412dabc55933e4078ee309df5b8e (diff) | |
download | riscv-pk-2f3e6f530384b4ab9f8b39bceb8e86f2ba51a835.zip riscv-pk-2f3e6f530384b4ab9f8b39bceb8e86f2ba51a835.tar.gz riscv-pk-2f3e6f530384b4ab9f8b39bceb8e86f2ba51a835.tar.bz2 |
pk: correct the handling of SYS_getcwd (#250)
`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:
```c
#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;
}
```
-rw-r--r-- | pk/syscall.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pk/syscall.c b/pk/syscall.c index b47c237..03eee27 100644 --- a/pk/syscall.c +++ b/pk/syscall.c @@ -420,7 +420,7 @@ long sys_getcwd(char* buf, size_t size) { char kbuf[MAX_BUF]; long ret = frontend_syscall(SYS_getcwd, kva2pa(kbuf), MIN(size, MAX_BUF), 0, 0, 0, 0, 0); - if (ret == 0) + if (ret > 0) memcpy_to_user(buf, kbuf, strlen(kbuf) + 1); return ret; } |