summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
authordzwdz2022-08-19 19:44:36 +0200
committerdzwdz2022-08-19 19:44:36 +0200
commit390aec5ca22e62d128e71d1dee312a2f0a82ab68 (patch)
tree2a79bb1ee35dab3006a947f595891fbcfefa4bfb /src/user/lib
parent6bea8cd391125734339dfb83db498a8651c9f7f7 (diff)
syscall/fs_wait: return a handle for each request
Diffstat (limited to 'src/user/lib')
-rw-r--r--src/user/lib/compat.c20
-rw-r--r--src/user/lib/compat.h6
-rw-r--r--src/user/lib/fs/misc.c45
-rw-r--r--src/user/lib/syscall.c8
4 files changed, 53 insertions, 26 deletions
diff --git a/src/user/lib/compat.c b/src/user/lib/compat.c
new file mode 100644
index 0000000..cadc77f
--- /dev/null
+++ b/src/user/lib/compat.c
@@ -0,0 +1,20 @@
+#include <camellia/syscalls.h>
+#include <stdio.h>
+#include <user/lib/compat.h>
+
+#define eprintf(fmt, ...) fprintf(stderr, "user/lib/compat: "fmt"\n" __VA_OPT__(,) __VA_ARGS__)
+
+static handle_t h = -1;
+long c0_fs_wait(char *buf, long len, struct fs_wait_response *res) {
+ if (h != -1) {
+ eprintf("didn't respond to request!");
+ c0_fs_respond(NULL, -1, 0);
+ }
+ h = _syscall_fs_wait(buf, len, res);
+ return h >= 0 ? 0 : -1;
+}
+long c0_fs_respond(void *buf, long ret, int flags) {
+ ret = _syscall_fs_respond(h, buf, ret, flags);
+ h = -1;
+ return ret;
+}
diff --git a/src/user/lib/compat.h b/src/user/lib/compat.h
new file mode 100644
index 0000000..b678cf5
--- /dev/null
+++ b/src/user/lib/compat.h
@@ -0,0 +1,6 @@
+#pragma once
+#include <camellia/types.h>
+
+/* c0 - fs_wait returning a handle */
+long c0_fs_wait(char *buf, long len, struct fs_wait_response *res);
+long c0_fs_respond(void *buf, long ret, int flags);
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index 038cd3b..d130901 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <user/lib/compat.h>
#include <user/lib/fs/dir.h>
#include <user/lib/fs/misc.h>
@@ -41,12 +42,12 @@ void fs_passthru(const char *prefix) {
int prefix_len = prefix ? strlen(prefix) : 0;
if (!buf) exit(1);
- while (!_syscall_fs_wait(buf, buf_len, &res)) {
+ while (!c0_fs_wait(buf, buf_len, &res)) {
switch (res.op) {
case VFSOP_OPEN:
if (prefix) {
if (prefix_len + res.len > buf_len) {
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
break;
}
@@ -57,11 +58,11 @@ void fs_passthru(const char *prefix) {
memcpy(buf, prefix, prefix_len);
res.len += prefix_len;
}
- _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
+ c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
break;
default:
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
break;
}
}
@@ -77,7 +78,7 @@ void fs_whitelist(const char **list) {
struct dirbuild db;
if (!buf) exit(1);
- while (!_syscall_fs_wait(buf, buf_len, &res)) {
+ while (!c0_fs_wait(buf, buf_len, &res)) {
size_t blen;
ipath = res.id;
switch (res.op) {
@@ -103,15 +104,15 @@ void fs_whitelist(const char **list) {
}
}
if (passthru) {
- _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
+ c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
} else if (inject) {
// TODO all the inject points could be precomputed
ipath = malloc(res.len + 1);
memcpy(ipath, buf, res.len);
ipath[res.len] = '\0';
- _syscall_fs_respond(ipath, 0, 0);
+ c0_fs_respond(ipath, 0, 0);
} else {
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
}
break;
@@ -126,16 +127,16 @@ void fs_whitelist(const char **list) {
if (blen < len && !memcmp(ipath, *iter, blen))
dir_appendl(&db, *iter + blen, dir_seglen(*iter + blen));
}
- _syscall_fs_respond(target, dir_finish(&db), 0);
+ c0_fs_respond(target, dir_finish(&db), 0);
break;
case VFSOP_CLOSE:
free(ipath);
- _syscall_fs_respond(NULL, 0, 0);
+ c0_fs_respond(NULL, 0, 0);
break;
default:
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
break;
}
}
@@ -157,11 +158,11 @@ void fs_union(const char **list) {
struct dirbuild db;
if (!pre) exit(1);
- while (!_syscall_fs_wait(post, postlen, &res)) {
+ while (!c0_fs_wait(post, postlen, &res)) {
switch (res.op) {
case VFSOP_OPEN:
if (res.len == 1) { /* root directory */
- _syscall_fs_respond(NULL, 0, 0);
+ c0_fs_respond(NULL, 0, 0);
break;
}
@@ -178,7 +179,7 @@ void fs_union(const char **list) {
post[res.len] = '\0';
}
if (ret < 0) ret = -1;
- _syscall_fs_respond(NULL, ret, FSR_DELEGATE);
+ c0_fs_respond(NULL, ret, FSR_DELEGATE);
break;
case VFSOP_READ:
@@ -198,11 +199,11 @@ void fs_union(const char **list) {
end = end || dir_append_from(&db, h);
_syscall_close(h);
}
- _syscall_fs_respond(target, dir_finish(&db), 0);
+ c0_fs_respond(target, dir_finish(&db), 0);
break;
default:
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
break;
}
}
@@ -225,7 +226,7 @@ void fs_dir_inject(const char *path) {
if (!buf) exit(1);
- while (!_syscall_fs_wait(buf, buf_len, &res)) {
+ while (!c0_fs_wait(buf, buf_len, &res)) {
data = res.id;
switch (res.op) {
case VFSOP_OPEN:
@@ -237,9 +238,9 @@ void fs_dir_inject(const char *path) {
data->delegate = _syscall_open(buf, res.len, res.flags);
data->inject = path + res.len;
data->inject_len = dir_seglen(data->inject);
- _syscall_fs_respond(data, 0, 0);
+ c0_fs_respond(data, 0, 0);
} else {
- _syscall_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
+ c0_fs_respond(NULL, _syscall_open(buf, res.len, res.flags), FSR_DELEGATE);
}
break;
@@ -247,7 +248,7 @@ void fs_dir_inject(const char *path) {
if (data->delegate >= 0)
close(data->delegate);
free(data);
- _syscall_fs_respond(NULL, 0, 0);
+ c0_fs_respond(NULL, 0, 0);
break;
case VFSOP_READ:
@@ -259,11 +260,11 @@ void fs_dir_inject(const char *path) {
dir_appendl(&db, data->inject, data->inject_len);
if (data->delegate >= 0)
dir_append_from(&db, data->delegate);
- _syscall_fs_respond(target, dir_finish(&db), 0);
+ c0_fs_respond(target, dir_finish(&db), 0);
break;
default:
- _syscall_fs_respond(NULL, -1, 0);
+ c0_fs_respond(NULL, -1, 0);
break;
}
}
diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c
index 1635636..d001990 100644
--- a/src/user/lib/syscall.c
+++ b/src/user/lib/syscall.c
@@ -50,12 +50,12 @@ long _syscall_close(handle_t h) {
return _syscall(_SYSCALL_CLOSE, (long)h, 0, 0, 0, 0);
}
-long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) {
- return _syscall(_SYSCALL_FS_WAIT, (long)buf, max_len, (long)res, 0, 0);
+handle_t _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res) {
+ return (handle_t)_syscall(_SYSCALL_FS_WAIT, (long)buf, max_len, (long)res, 0, 0);
}
-long _syscall_fs_respond(void __user *buf, long ret, int flags) {
- return _syscall(_SYSCALL_FS_RESPOND, (long)buf, ret, (long)flags, 0, 0);
+long _syscall_fs_respond(handle_t hid, void __user *buf, long ret, int flags) {
+ return _syscall(_SYSCALL_FS_RESPOND, (long)hid, (long)buf, ret, (long)flags, 0);
}
void __user *_syscall_memflag(void __user *addr, size_t len, int flags) {