summaryrefslogtreecommitdiff
path: root/src/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/user')
-rw-r--r--src/user/app/drawmouse/drawmouse.c4
-rw-r--r--src/user/app/dvd/dvd.c2
-rw-r--r--src/user/app/ext2fs/main.c54
-rw-r--r--src/user/app/httpd/httpd.c6
-rw-r--r--src/user/app/init/driver/driver.h2
-rw-r--r--src/user/app/init/driver/initctl.c6
-rw-r--r--src/user/app/init/driver/ps2.c6
-rw-r--r--src/user/app/init/driver/termcook.c20
-rw-r--r--src/user/app/init/init.c20
-rw-r--r--src/user/app/iochk/iochk.c8
-rw-r--r--src/user/app/iostress/iostress.c4
-rw-r--r--src/user/app/logfs/logfs.c4
-rw-r--r--src/user/app/login/login.c8
-rw-r--r--src/user/app/netdog/nd.c12
-rw-r--r--src/user/app/netstack/arp.c6
-rw-r--r--src/user/app/netstack/ether.c4
-rw-r--r--src/user/app/netstack/fs.c50
-rw-r--r--src/user/app/netstack/netstack.c4
-rw-r--r--src/user/app/netstack/proto.h6
-rw-r--r--src/user/app/shell/builtins.c8
-rw-r--r--src/user/app/shell/shell.c16
-rw-r--r--src/user/app/tests/kernel/fdlimit.c28
-rw-r--r--src/user/app/tests/kernel/fs.c44
-rw-r--r--src/user/app/tests/kernel/misc.c38
-rw-r--r--src/user/app/tests/kernel/miscsyscall.c160
-rw-r--r--src/user/app/tests/kernel/path.c6
-rw-r--r--src/user/app/tests/kernel/threads.c12
-rw-r--r--src/user/app/tests/libc/esemaphore.c34
-rw-r--r--src/user/app/tests/stress.c4
-rw-r--r--src/user/app/tests/tests.c14
-rw-r--r--src/user/app/tests/tests.h2
-rw-r--r--src/user/app/tmpfs/tmpfs.c22
-rw-r--r--src/user/bootstrap/entry.S4
-rw-r--r--src/user/bootstrap/main.c6
-rw-r--r--src/user/lib/_start2.c4
-rw-r--r--src/user/lib/assert.c2
-rw-r--r--src/user/lib/camellia.c6
-rw-r--r--src/user/lib/compat.c6
-rw-r--r--src/user/lib/draw/draw.c4
-rw-r--r--src/user/lib/draw/draw.h2
-rw-r--r--src/user/lib/draw/flush.c6
-rw-r--r--src/user/lib/elfload.S2
-rw-r--r--src/user/lib/elfload.c12
-rw-r--r--src/user/lib/esemaphore.c18
-rw-r--r--src/user/lib/esemaphore.h2
-rw-r--r--src/user/lib/fs/dir.c6
-rw-r--r--src/user/lib/fs/misc.c44
-rw-r--r--src/user/lib/fs/whitelist.c14
-rw-r--r--src/user/lib/include/camellia.h2
-rw-r--r--src/user/lib/include/camellia/fs/dir.h2
-rw-r--r--src/user/lib/include/camellia/fs/misc.h6
-rw-r--r--src/user/lib/include/stdio.h2
-rw-r--r--src/user/lib/include/unistd.h4
-rw-r--r--src/user/lib/mman.c4
-rw-r--r--src/user/lib/printf.c2
-rw-r--r--src/user/lib/stdio/file.c14
-rw-r--r--src/user/lib/stdlib.c4
-rw-r--r--src/user/lib/syscall.c84
-rw-r--r--src/user/lib/syscall.c.awk2
-rw-r--r--src/user/lib/thread.S4
-rw-r--r--src/user/lib/unistd.c14
61 files changed, 448 insertions, 448 deletions
diff --git a/src/user/app/drawmouse/drawmouse.c b/src/user/app/drawmouse/drawmouse.c
index 6e2a881..24aa55e 100644
--- a/src/user/app/drawmouse/drawmouse.c
+++ b/src/user/app/drawmouse/drawmouse.c
@@ -50,7 +50,7 @@ struct packet {
int main(void) {
char buf[64];
- handle_t fd = camellia_open("/kdev/ps2/mouse", OPEN_READ);
+ hid_t fd = camellia_open("/kdev/ps2/mouse", OPEN_READ);
if (fd < 0) {
eprintf("couldn't open mouse");
return 1;
@@ -64,7 +64,7 @@ int main(void) {
for (;;) {
- int len = _syscall_read(fd, buf, sizeof buf, 0);
+ int len = _sys_read(fd, buf, sizeof buf, 0);
if (len == 0) break;
ring_put(&r, buf, len);
while (ring_used(&r) >= 3) {
diff --git a/src/user/app/dvd/dvd.c b/src/user/app/dvd/dvd.c
index f880782..70adc8b 100644
--- a/src/user/app/dvd/dvd.c
+++ b/src/user/app/dvd/dvd.c
@@ -36,7 +36,7 @@ int main(void) {
y += dy;
draw_rect(x, y, w, h, col++);
dirty_flush(&dirty, &fb);
- _syscall_sleep(1000 / 60);
+ _sys_sleep(1000 / 60);
}
return 1;
diff --git a/src/user/app/ext2fs/main.c b/src/user/app/ext2fs/main.c
index 65e7460..678d189 100644
--- a/src/user/app/ext2fs/main.c
+++ b/src/user/app/ext2fs/main.c
@@ -21,10 +21,10 @@ struct handle {
static int my_read(void *fp, void *buf, size_t len, size_t off);
static int my_write(void *fp, const void *buf, size_t len, size_t off);
-static void do_open(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf);
-static void do_read(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf, size_t buflen);
-static void do_write(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf);
-static void do_getsize(struct ext2 *fs, handle_t reqh, struct ufs_request *req);
+static void do_open(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf);
+static void do_read(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf, size_t buflen);
+static void do_write(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf);
+static void do_getsize(struct ext2 *fs, hid_t reqh, struct ufs_request *req);
static int
my_read(void *fp, void *buf, size_t len, size_t off)
@@ -51,61 +51,61 @@ my_write(void *fp, const void *buf, size_t len, size_t off)
}
static void
-do_open(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf)
+do_open(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf)
{
bool is_dir = req->len == 0 || buf[req->len-1] == '/';
uint32_t n = ext2c_walk(fs, buf, req->len);
if (n == 0) {
if (is_dir) {
- _syscall_fs_respond(reqh, NULL, -ENOSYS, 0);
+ _sys_fs_respond(reqh, NULL, -ENOSYS, 0);
return;
}
/* buf[0] == '/', strrchr != NULL */
char *name = strrchr(buf, '/') + 1;
uint32_t dir_n = ext2c_walk(fs, buf, name - buf);
if (dir_n == 0) {
- _syscall_fs_respond(reqh, NULL, -ENOENT, 0);
+ _sys_fs_respond(reqh, NULL, -ENOENT, 0);
return;
}
n = ext2_alloc_inode(fs, 0100700);
if (n == 0) {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
return;
}
if (ext2_link(fs, dir_n, name, n, 1) < 0) {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
return;
}
} else {
struct ext2d_inode *inode = ext2_req_inode(fs, n);
if (!inode) {
- _syscall_fs_respond(reqh, NULL, -ENOENT, 0);
+ _sys_fs_respond(reqh, NULL, -ENOENT, 0);
return;
}
int type = (inode->perms >> 12) & 0xF;
ext2_dropreq(fs, inode, false);
if ((type == 0x8 && is_dir) || (type == 0x4 && !is_dir)) {
- _syscall_fs_respond(reqh, NULL, -ENOENT, 0);
+ _sys_fs_respond(reqh, NULL, -ENOENT, 0);
return;
} else if (type != 0x8 && type != 0x4) {
- _syscall_fs_respond(reqh, NULL, -ENOSYS, 0);
+ _sys_fs_respond(reqh, NULL, -ENOSYS, 0);
return;
}
}
struct handle *h = malloc(sizeof *h);
if (!h) {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
return;
}
h->n = n;
h->dir = is_dir;
- _syscall_fs_respond(reqh, h, 0, 0);
+ _sys_fs_respond(reqh, h, 0, 0);
}
static void
-do_read(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf, size_t buflen)
+do_read(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf, size_t buflen)
{
struct handle *h = req->id;
if (!h->dir) {
@@ -116,7 +116,7 @@ do_read(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf, size
void *b = ext2_req_file(fs, h->n, &req->capacity, req->offset);
if (!b) goto err;
- _syscall_fs_respond(reqh, b, req->capacity, 0);
+ _sys_fs_respond(reqh, b, req->capacity, 0);
ext2_dropreq(fs, b, false);
} else {
struct dirbuild db;
@@ -142,15 +142,15 @@ do_read(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf, size
dir_appendl(&db, iter.ent->name, iter.ent->namelen_lower);
}
}
- _syscall_fs_respond(reqh, buf, dir_finish(&db), 0);
+ _sys_fs_respond(reqh, buf, dir_finish(&db), 0);
}
return;
err:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
static void
-do_write(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf)
+do_write(struct ext2 *fs, hid_t reqh, struct ufs_request *req, char *buf)
{
struct handle *h = req->id;
if (h->dir) goto err;
@@ -169,24 +169,24 @@ do_write(struct ext2 *fs, handle_t reqh, struct ufs_request *req, char *buf)
inode = NULL;
int ret = ext2_write(fs, h->n, buf, req->len, req->offset);
- _syscall_fs_respond(reqh, NULL, ret, 0);
+ _sys_fs_respond(reqh, NULL, ret, 0);
return;
err:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
static void
-do_getsize(struct ext2 *fs, handle_t reqh, struct ufs_request *req) {
+do_getsize(struct ext2 *fs, hid_t reqh, struct ufs_request *req) {
struct handle *h = req->id;
if (h->dir) goto err;
struct ext2d_inode *inode = ext2_req_inode(fs, h->n);
if (!inode) goto err;
- _syscall_fs_respond(reqh, NULL, inode->size_lower, 0);
+ _sys_fs_respond(reqh, NULL, inode->size_lower, 0);
ext2_dropreq(fs, inode, false);
return;
err:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
int
@@ -208,7 +208,7 @@ main(int argc, char **argv)
char *buf = malloc(buflen);
struct ufs_request req;
for (;;) {
- handle_t reqh = ufs_wait(buf, buflen, &req);
+ hid_t reqh = ufs_wait(buf, buflen, &req);
struct handle *h = req.id;
if (reqh < 0) break;
switch (req.op) {
@@ -226,10 +226,10 @@ main(int argc, char **argv)
break;
case VFSOP_CLOSE:
free(h);
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/app/httpd/httpd.c b/src/user/app/httpd/httpd.c
index 02f9e6b..668e534 100644
--- a/src/user/app/httpd/httpd.c
+++ b/src/user/app/httpd/httpd.c
@@ -20,7 +20,7 @@ static void handle(FILE *c) {
char *end = strchr(path, ' ');
if (end) *end = '\0';
- handle_t h = _syscall_open(path, strlen(path), OPEN_READ);
+ hid_t h = _sys_open(path, strlen(path), OPEN_READ);
if (h < 0) {
fprintf(c, "HTTP/1.1 404 Not Found\r\n\r\n");
return;
@@ -65,9 +65,9 @@ static void handle(FILE *c) {
int main(int argc, char **argv) {
const char *path = (argc > 1) ? argv[1] : "/net/listen/0.0.0.0/tcp/80";
- handle_t conn;
+ hid_t conn;
for (;;) {
- conn = _syscall_open(path, strlen(path), OPEN_RW);
+ conn = _sys_open(path, strlen(path), OPEN_RW);
if (conn < 0)
errx(1, "open('%s') failed, errno %d", path, -conn);
FILE *f = fdopen(conn, "a+");
diff --git a/src/user/app/init/driver/driver.h b/src/user/app/init/driver/driver.h
index fc9f51b..98c18f1 100644
--- a/src/user/app/init/driver/driver.h
+++ b/src/user/app/init/driver/driver.h
@@ -1,7 +1,7 @@
#pragma once
#include <camellia/types.h>
-void initctl_drv(handle_t killswitch);
+void initctl_drv(hid_t killswitch);
void ps2_drv(void);
void tmpfs_drv(void);
diff --git a/src/user/app/init/driver/initctl.c b/src/user/app/init/driver/initctl.c
index 67c8ade..fed71b7 100644
--- a/src/user/app/init/driver/initctl.c
+++ b/src/user/app/init/driver/initctl.c
@@ -6,7 +6,7 @@
#include <string.h>
#include <camellia/compat.h>
-void initctl_drv(handle_t killswitch) {
+void initctl_drv(hid_t killswitch) {
struct ufs_request res;
char buf[64];
const size_t buflen = sizeof buf;
@@ -28,10 +28,10 @@ void initctl_drv(handle_t killswitch) {
}
}
if (!strcmp(buf, "halt")) {
- _syscall_write(killswitch, "halt", 4, 0, 0);
+ _sys_write(killswitch, "halt", 4, 0, 0);
}
if (!strcmp(buf, "intr")) {
- _syscall_write(killswitch, "intr", 4, 0, 0);
+ _sys_write(killswitch, "intr", 4, 0, 0);
}
c0_fs_respond(NULL, res.len, 0);
break;
diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c
index 1accbfc..a5cdb07 100644
--- a/src/user/app/init/driver/ps2.c
+++ b/src/user/app/init/driver/ps2.c
@@ -32,7 +32,7 @@ static const char keymap_upper[] = {
static volatile uint8_t backlog_buf[16];
static volatile ring_t backlog = {(void*)backlog_buf, sizeof backlog_buf, 0, 0};
-static handle_t fd;
+static hid_t fd;
static bool keys[0x80] = {0};
@@ -63,7 +63,7 @@ static void main_loop(void) {
case VFSOP_READ:
while (ring_used((void*)&backlog) == 0) {
/* read raw input until we have something to output */
- int len = _syscall_read(fd, buf, sizeof buf, 0);
+ int len = _sys_read(fd, buf, sizeof buf, 0);
if (len == 0) break;
for (int i = 0; i < len; i++)
parse_scancode(buf[i]);
@@ -80,7 +80,7 @@ static void main_loop(void) {
}
void ps2_drv(void) {
- fd = _syscall_open("/kdev/ps2/kb", 12, 0);
+ fd = _sys_open("/kdev/ps2/kb", 12, 0);
if (fd < 0) exit(1);
main_loop();
diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c
index 8845839..a76f3a8 100644
--- a/src/user/app/init/driver/termcook.c
+++ b/src/user/app/init/driver/termcook.c
@@ -10,21 +10,21 @@ enum tstate {
CSI,
};
-static void w_output(handle_t output, const char *buf, size_t len) {
+static void w_output(hid_t output, const char *buf, size_t len) {
size_t pos = 0;
while (pos < len) {
- int ret = _syscall_write(output, buf + pos, len - pos, pos, 0);
+ int ret = _sys_write(output, buf + pos, len - pos, pos, 0);
if (ret < 0) break;
pos += ret;
}
}
-static void line_editor(handle_t input, handle_t output) {
+static void line_editor(hid_t input, hid_t output) {
char readbuf[16], linebuf[256];
size_t linepos = 0;
enum tstate state = Normal;
for (;;) {
- int readlen = _syscall_read(input, readbuf, sizeof readbuf, -1);
+ int readlen = _sys_read(input, readbuf, sizeof readbuf, -1);
if (readlen < 0) return;
for (int i = 0; i < readlen; i++) {
char c = readbuf[i];
@@ -39,13 +39,13 @@ static void line_editor(handle_t input, handle_t output) {
}
break;
case 3: /* C-c */
- _syscall_exit(1);
+ _sys_exit(1);
case 4: /* EOT, C-d */
if (linepos > 0) {
w_output(output, linebuf, linepos);
linepos = 0;
} else {
- _syscall_write(output, NULL, 0, 0, 0); /* EOF */
+ _sys_write(output, NULL, 0, 0, 0); /* EOF */
}
break;
case '\n':
@@ -82,14 +82,14 @@ static void line_editor(handle_t input, handle_t output) {
}
void termcook(void) {
- handle_t stdin_pipe[2] = {-1, -1};
- if (_syscall_pipe(stdin_pipe, 0) < 0)
+ hid_t stdin_pipe[2] = {-1, -1};
+ if (_sys_pipe(stdin_pipe, 0) < 0)
return;
if (!fork()) {
/* the caller continues in a child process,
* so it can be killed when the line editor quits */
- _syscall_dup(stdin_pipe[0], 0, 0);
+ _sys_dup(stdin_pipe[0], 0, 0);
close(stdin_pipe[0]);
close(stdin_pipe[1]);
return;
@@ -99,5 +99,5 @@ void termcook(void) {
line_editor(0, stdin_pipe[1]);
exit(0);
}
- exit(_syscall_await());
+ exit(_sys_await());
}
diff --git a/src/user/app/init/init.c b/src/user/app/init/init.c
index d872b24..8346a31 100644
--- a/src/user/app/init/init.c
+++ b/src/user/app/init/init.c
@@ -26,18 +26,18 @@ void redirect(const char *exe, const char *out, const char *in) {
termcook();
execv(exe, (void*)argv);
fprintf(stderr, "init: couldn't start %s\n", exe);
- _syscall_sleep(5000);
+ _sys_sleep(5000);
exit(1);
}
- _syscall_await();
- _syscall_intr();
+ _sys_await();
+ _sys_intr();
}
}
}
int main(void) {
const char *teststr = "I am teststr.\n";
- handle_t killswitch_pipe[2];
+ hid_t killswitch_pipe[2];
freopen("/kdev/com1", "a+", stdout);
freopen("/kdev/com1", "a+", stderr);
@@ -86,7 +86,7 @@ int main(void) {
execv(argv[0], (void*)argv);
}
- if (_syscall_pipe(killswitch_pipe, 0) < 0) {
+ if (_sys_pipe(killswitch_pipe, 0) < 0) {
printf("couldn't create the killswitch pipe, quitting...\n");
return 1;
}
@@ -106,20 +106,20 @@ int main(void) {
char buf[128];
for (;;) {
- if (_syscall_read(killswitch_pipe[0], buf, 128, 0) != 4) {
+ if (_sys_read(killswitch_pipe[0], buf, 128, 0) != 4) {
break;
}
if (memcmp(buf, "intr", 4) == 0) {
- _syscall_intr();
+ _sys_intr();
} else if (memcmp(buf, "halt", 4) == 0) {
break;
}
}
printf("[init] intr\n");
- _syscall_intr();
- _syscall_sleep(1000);
+ _sys_intr();
+ _sys_sleep(1000);
printf("[init] filicide\n");
- _syscall_filicide();
+ _sys_filicide();
printf("[init] goodbye\n");
return 0;
}
diff --git a/src/user/app/iochk/iochk.c b/src/user/app/iochk/iochk.c
index e4b0346..9703919 100644
--- a/src/user/app/iochk/iochk.c
+++ b/src/user/app/iochk/iochk.c
@@ -13,7 +13,7 @@ static bool verbose = false;
#define eprintf(fmt, ...) fprintf(stderr, "iochk: "fmt"\n" __VA_OPT__(,) __VA_ARGS__)
-void check(handle_t h) {
+void check(hid_t h) {
const size_t buflen = 4096;
const size_t offsets[] = {
0, 1, 2, 3, 4, 5, 6, 7,
@@ -28,7 +28,7 @@ void check(handle_t h) {
}
long offlast = 0;
- long retlast = _syscall_read(h, buflast, buflen, offlast);
+ long retlast = _sys_read(h, buflast, buflen, offlast);
if (retlast < 0) {
eprintf("error %d when reading at offset %d", retlast, offlast);
goto end;
@@ -41,7 +41,7 @@ void check(handle_t h) {
assert(diff >= 0);
if (retlast < diff) break;
- long retcur = _syscall_read(h, bufcur, buflen, offcur);
+ long retcur = _sys_read(h, bufcur, buflen, offcur);
if (retcur < 0) {
eprintf("error %d when reading at offset %d", retlast, offcur);
break;
@@ -85,7 +85,7 @@ int main(int argc, char **argv) {
for (; optind < argc; optind++) {
const char *path = argv[optind];
verbosef("checking %s...\n", path);
- handle_t h = camellia_open(path, OPEN_READ);
+ hid_t h = camellia_open(path, OPEN_READ);
if (h < 0) {
eprintf("couldn't open %s", path);
continue;
diff --git a/src/user/app/iostress/iostress.c b/src/user/app/iostress/iostress.c
index 2f15471..3a3a23c 100644
--- a/src/user/app/iostress/iostress.c
+++ b/src/user/app/iostress/iostress.c
@@ -26,9 +26,9 @@ int main(int argc, char **argv) {
for (long i = 0; i < num_runs; i++) {
uint64_t time = __rdtsc();
for (long j = 0; j < num_calls; j++)
- _syscall_write(1, inbuf, num_bytes, -1, 0);
+ _sys_write(1, inbuf, num_bytes, -1, 0);
results[i] = __rdtsc() - time;
- _syscall_write(1, "\n", 1, -1, 0);
+ _sys_write(1, "\n", 1, -1, 0);
}
uint64_t total = 0;
diff --git a/src/user/app/logfs/logfs.c b/src/user/app/logfs/logfs.c
index 14a8f2a..a50d530 100644
--- a/src/user/app/logfs/logfs.c
+++ b/src/user/app/logfs/logfs.c
@@ -11,7 +11,7 @@ _Noreturn void fs(void) {
if (!buf) err(1, "malloc");
for (;;) {
struct ufs_request req;
- handle_t reqh = ufs_wait(buf, buflen, &req);
+ hid_t reqh = ufs_wait(buf, buflen, &req);
if (reqh < 0) errx(1, "ufs_wait error");
switch (req.op) {
@@ -23,7 +23,7 @@ _Noreturn void fs(void) {
/* Unsupported vfs operation.
* Currently if you never create your own file descriptors you won't receive
* anything but VFSOP_OPEN, but it's idiomatic to handle this anyways. */
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/app/login/login.c b/src/user/app/login/login.c
index a348254..0f9e8b7 100644
--- a/src/user/app/login/login.c
+++ b/src/user/app/login/login.c
@@ -36,23 +36,23 @@ static void drv(const char *user) {
char *buf = malloc(PATH_MAX);
for (;;) {
struct ufs_request req;
- handle_t reqh = ufs_wait(buf, PATH_MAX, &req);
+ hid_t reqh = ufs_wait(buf, PATH_MAX, &req);
if (reqh < 0) break;
switch (req.op) {
case VFSOP_OPEN:
if (segcmp(buf, 1, "Users") && segcmp(buf, 2, user)) { // /Users/$user/**
forward_open(reqh, buf, req.len, req.flags);
} else if (segcmp(buf, 1, "Users") && segcmp(buf, 3, "private")) { // /Users/*/private/**
- _syscall_fs_respond(reqh, NULL, -EACCES, 0);
+ _sys_fs_respond(reqh, NULL, -EACCES, 0);
} else if (!OPEN_WRITEABLE(req.flags)) {
forward_open(reqh, buf, req.len, req.flags);
} else {
- _syscall_fs_respond(reqh, NULL, -EACCES, 0);
+ _sys_fs_respond(reqh, NULL, -EACCES, 0);
}
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/app/netdog/nd.c b/src/user/app/netdog/nd.c
index 93e1d3a..fdc8361 100644
--- a/src/user/app/netdog/nd.c
+++ b/src/user/app/netdog/nd.c
@@ -6,15 +6,15 @@
#define eprintf(fmt, ...) fprintf(stderr, "netdog: "fmt"\n" __VA_OPT__(,) __VA_ARGS__)
-handle_t conn;
+hid_t conn;
void send_stdin(void *arg) { (void)arg;
static char buf[4096];
for (;;) {
// TODO define STDIN_FILENO
- long ret = _syscall_read(0, buf, sizeof buf, -1);
+ long ret = _sys_read(0, buf, sizeof buf, -1);
if (ret <= 0) return; /* instead of sending an empty packet, quit. */
- ret = _syscall_write(conn, buf, ret, -1, 0);
+ ret = _sys_write(conn, buf, ret, -1, 0);
if (ret < 0) return;
}
}
@@ -22,9 +22,9 @@ void send_stdin(void *arg) { (void)arg;
void recv_stdout(void *arg) { (void)arg;
static char buf[4096];
for (;;) {
- long ret = _syscall_read(conn, buf, sizeof buf, -1);
+ long ret = _sys_read(conn, buf, sizeof buf, -1);
if (ret < 0) return;
- ret = _syscall_write(1, buf, ret, -1, 0);
+ ret = _sys_write(1, buf, ret, -1, 0);
if (ret < 0) return;
}
}
@@ -43,6 +43,6 @@ int main(int argc, char **argv) {
thread_create(0, send_stdin, NULL);
thread_create(0, recv_stdout, NULL);
- _syscall_await();
+ _sys_await();
return 0;
}
diff --git a/src/user/app/netstack/arp.c b/src/user/app/netstack/arp.c
index 6c230b3..3a1c8da 100644
--- a/src/user/app/netstack/arp.c
+++ b/src/user/app/netstack/arp.c
@@ -107,7 +107,7 @@ int arpcache_get(uint32_t ip, mac_t *mac) {
return -1;
}
-void arp_fsread(handle_t h, long offset) {
+void arp_fsread(hid_t h, long offset) {
const char *fmt = "%08x\t%02x:%02x:%02x:%02x:%02x:%02x\n";
long linelen = snprintf(NULL, 0, fmt, 0, 1, 2, 3, 4, 5, 6) + 1;
char buf[28];
@@ -129,10 +129,10 @@ void arp_fsread(handle_t h, long offset) {
cur->mac[3],
cur->mac[4],
cur->mac[5]);
- _syscall_fs_respond(h, buf + offset, linelen - offset, 0);
+ _sys_fs_respond(h, buf + offset, linelen - offset, 0);
return;
err:
- _syscall_fs_respond(h, NULL, -1, 0);
+ _sys_fs_respond(h, NULL, -1, 0);
}
long arp_fswrite(const char *buf, long len, long offset) {
diff --git a/src/user/app/netstack/ether.c b/src/user/app/netstack/ether.c
index 20d16ab..52abac2 100644
--- a/src/user/app/netstack/ether.c
+++ b/src/user/app/netstack/ether.c
@@ -19,7 +19,7 @@ void ether_parse(const uint8_t *buf, size_t len) {
for (struct ethq **iter = &ether_queue; iter && *iter; ) {
struct ethq *qe = *iter;
- _syscall_fs_respond(qe->h, buf, len, 0);
+ _sys_fs_respond(qe->h, buf, len, 0);
/* remove entry */
/* yes, doing it this way here doesn't make sense. i'm preparing for filtering */
*iter = qe->next;
@@ -54,6 +54,6 @@ uint8_t *ether_start(size_t len, struct ethernet ether) {
void ether_finish(uint8_t *pkt) {
uint8_t *buf = pkt - Payload - fhoff;
size_t len = *(size_t*)buf;
- _syscall_write(state.raw_h, buf + fhoff, len, 0, 0);
+ _sys_write(state.raw_h, buf + fhoff, len, 0, 0);
free(buf);
}
diff --git a/src/user/app/netstack/fs.c b/src/user/app/netstack/fs.c
index ad6c23c..6d51c35 100644
--- a/src/user/app/netstack/fs.c
+++ b/src/user/app/netstack/fs.c
@@ -43,14 +43,14 @@ struct handle {
size_t readcap;
} tcp;
bool dead;
- handle_t reqh;
+ hid_t reqh;
};
static void tcp_listen_callback(struct tcp_conn *c, void *arg) {
struct handle *h = arg;
h->tcp.c = c;
- _syscall_fs_respond(h->reqh, h, 0, 0);
+ _sys_fs_respond(h->reqh, h, 0, 0);
h->reqh = -1;
}
@@ -63,7 +63,7 @@ static void tcp_recv_callback(void *arg) {
h->tcp.readcap = sizeof buf;
size_t len = tcpc_tryread(h->tcp.c, buf, h->tcp.readcap);
if (len > 0) {
- _syscall_fs_respond(h->reqh, buf, len, 0);
+ _sys_fs_respond(h->reqh, buf, len, 0);
h->reqh = -1;
}
}
@@ -73,7 +73,7 @@ static void tcp_close_callback(void *arg) {
struct handle *h = arg;
h->dead = true;
if (h->reqh >= 0) {
- _syscall_fs_respond(h->reqh, NULL, -ECONNRESET, 0);
+ _sys_fs_respond(h->reqh, NULL, -ECONNRESET, 0);
h->reqh = -1;
return;
}
@@ -82,14 +82,14 @@ static void tcp_close_callback(void *arg) {
static void udp_listen_callback(struct udp_conn *c, void *arg) {
struct handle *h = arg;
h->udp.c = c;
- _syscall_fs_respond(h->reqh, h, 0, 0);
+ _sys_fs_respond(h->reqh, h, 0, 0);
h->reqh = -1;
}
static void udp_recv_callback(const void *buf, size_t len, void *arg) {
struct handle *h = arg;
if (h->reqh >= 0) {
- _syscall_fs_respond(h->reqh, buf, len, 0);
+ _sys_fs_respond(h->reqh, buf, len, 0);
h->reqh = -1;
return;
}
@@ -106,14 +106,14 @@ static void udp_recv_callback(const void *buf, size_t len, void *arg) {
}
}
-static void recv_enqueue(struct handle *h, handle_t reqh, size_t readcap) {
+static void recv_enqueue(struct handle *h, hid_t reqh, size_t readcap) {
if (h->reqh > 0) {
// TODO queue
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
return;
}
if (h->type == H_UDP && h->udp.rx) {
- _syscall_fs_respond(reqh, h->udp.rx->buf, h->udp.rx->len, 0);
+ _sys_fs_respond(reqh, h->udp.rx->buf, h->udp.rx->len, 0);
h->udp.rx = h->udp.rx->next;
free(h->udp.rx);
return;
@@ -125,8 +125,8 @@ static void recv_enqueue(struct handle *h, handle_t reqh, size_t readcap) {
}
}
-static void fs_open(handle_t reqh, char *path, int flags) {
-#define respond(buf, val) do{ _syscall_fs_respond(reqh, buf, val, 0); return; }while(0)
+static void fs_open(hid_t reqh, char *path, int flags) {
+#define respond(buf, val) do{ _sys_fs_respond(reqh, buf, val, 0); return; }while(0)
struct handle *h;
if (*path != '/') respond(NULL, -1);
path++;
@@ -241,7 +241,7 @@ void fs_thread(void *arg) { (void)arg;
char *buf = malloc(buflen);
for (;;) {
struct ufs_request res;
- handle_t reqh = _syscall_fs_wait(buf, buflen, &res);
+ hid_t reqh = _sys_fs_wait(buf, buflen, &res);
if (reqh < 0) break;
struct handle *h = res.id;
long ret;
@@ -251,12 +251,12 @@ void fs_thread(void *arg) { (void)arg;
buf[res.len] = '\0';
fs_open(reqh, buf, res.flags);
} else {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
break;
case VFSOP_READ:
if (h->dead) {
- _syscall_fs_respond(reqh, NULL, -ECONNRESET, 0);
+ _sys_fs_respond(reqh, NULL, -ECONNRESET, 0);
break;
}
switch (h->type) {
@@ -275,44 +275,44 @@ void fs_thread(void *arg) { (void)arg;
arp_fsread(reqh, res.offset);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
break;
case VFSOP_WRITE:
if (h->dead) {
- _syscall_fs_respond(reqh, NULL, -ECONNRESET, 0);
+ _sys_fs_respond(reqh, NULL, -ECONNRESET, 0);
break;
}
switch (h->type) {
case H_ETHER:
- ret = _syscall_write(state.raw_h, buf, res.len, 0, 0);
- _syscall_fs_respond(reqh, NULL, ret, 0);
+ ret = _sys_write(state.raw_h, buf, res.len, 0, 0);
+ _sys_fs_respond(reqh, NULL, ret, 0);
break;
case H_TCP:
tcpc_send(h->tcp.c, buf, res.len);
- _syscall_fs_respond(reqh, NULL, res.len, 0);
+ _sys_fs_respond(reqh, NULL, res.len, 0);
break;
case H_UDP:
udpc_send(h->udp.c, buf, res.len);
- _syscall_fs_respond(reqh, NULL, res.len, 0);
+ _sys_fs_respond(reqh, NULL, res.len, 0);
break;
case H_ARP:
- _syscall_fs_respond(reqh, NULL, arp_fswrite(buf, res.len, res.offset), 0);
+ _sys_fs_respond(reqh, NULL, arp_fswrite(buf, res.len, res.offset), 0);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
break;
case VFSOP_CLOSE:
// TODO remove entries in queue
- // TODO why does close even have _syscall_fs_respond?
+ // TODO why does close even have _sys_fs_respond?
if (h->type == H_TCP) tcpc_close(h->tcp.c);
if (h->type == H_UDP) udpc_close(h->udp.c);
free(h);
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/app/netstack/netstack.c b/src/user/app/netstack/netstack.c
index 405be09..c2e9223 100644
--- a/src/user/app/netstack/netstack.c
+++ b/src/user/app/netstack/netstack.c
@@ -17,7 +17,7 @@ void network_thread(void *arg) { (void)arg;
const size_t buflen = 4096;
char *buf = malloc(buflen);
for (;;) {
- long ret = _syscall_read(state.raw_h, buf, buflen, -1);
+ long ret = _sys_read(state.raw_h, buf, buflen, -1);
if (ret < 0) break;
ether_parse((void*)buf, ret);
}
@@ -49,6 +49,6 @@ int main(int argc, char **argv) {
arp_request(state.gateway);
thread_create(0, network_thread, NULL);
thread_create(0, fs_thread, NULL);
- _syscall_await();
+ _sys_await();
return 0;
}
diff --git a/src/user/app/netstack/proto.h b/src/user/app/netstack/proto.h
index 4d881ca..8ea11ac 100644
--- a/src/user/app/netstack/proto.h
+++ b/src/user/app/netstack/proto.h
@@ -10,7 +10,7 @@ extern struct net_state {
mac_t mac;
uint32_t ip, gateway;
- handle_t raw_h;
+ hid_t raw_h;
} state;
enum { /* ethertype */
@@ -51,7 +51,7 @@ struct icmp {
* will break if i implement a scheduler*/
struct ethq {
struct ethq *next;
- handle_t h;
+ hid_t h;
};
extern struct ethq *ether_queue;
@@ -59,7 +59,7 @@ void arp_parse(const uint8_t *buf, size_t len);
void arp_request(uint32_t ip);
/* 0 on success, -1 on failure */
int arpcache_get(uint32_t ip, mac_t *mac);
-void arp_fsread(handle_t h, long offset);
+void arp_fsread(hid_t h, long offset);
long arp_fswrite(const char *buf, long len, long offset);
void icmp_parse(const uint8_t *buf, size_t len, struct ipv4 ip);
diff --git a/src/user/app/shell/builtins.c b/src/user/app/shell/builtins.c
index 870a6af..e0f848e 100644
--- a/src/user/app/shell/builtins.c
+++ b/src/user/app/shell/builtins.c
@@ -58,13 +58,13 @@ static void cmd_echo(int argc, char **argv) {
void cmd_getsize(int argc, char **argv) {
if (argc < 2) errx(1, "no arguments");
for (int i = 1; i < argc; i++) {
- handle_t h = camellia_open(argv[i], OPEN_READ);
+ hid_t h = camellia_open(argv[i], OPEN_READ);
if (h < 0) {
warn("error opening %s", argv[i]);
continue;
}
- printf("%s: %d\n", argv[i], (int)_syscall_getsize(h));
- _syscall_close(h);
+ printf("%s: %d\n", argv[i], (int)_sys_getsize(h));
+ _sys_close(h);
}
}
@@ -205,7 +205,7 @@ static void cmd_rm(int argc, char **argv) {
static void cmd_sleep(int argc, char **argv) {
if (argc < 2) errx(1, "no arguments");
- _syscall_sleep(strtol(argv[1], NULL, 0) * 1000);
+ _sys_sleep(strtol(argv[1], NULL, 0) * 1000);
}
static void cmd_touch(int argc, char **argv) {
diff --git a/src/user/app/shell/shell.c b/src/user/app/shell/shell.c
index 564daa8..5808de1 100644
--- a/src/user/app/shell/shell.c
+++ b/src/user/app/shell/shell.c
@@ -50,14 +50,14 @@ void run_args(int argc, char **argv, struct redir *redir) {
if (argc < 2) {
fprintf(stderr, "shadow: missing path\n");
} else {
- _syscall_mount(HANDLE_NULLFS, argv[1], strlen(argv[1]));
+ _sys_mount(HANDLE_NULLFS, argv[1], strlen(argv[1]));
}
} else if (!strcmp(argv[0], "procmnt")) {
if (argc < 2) {
fprintf(stderr, "procmnt: missing mountpoint\n");
return;
}
- _syscall_mount(HANDLE_PROCFS, argv[1], strlen(argv[1]));
+ _sys_mount(HANDLE_PROCFS, argv[1], strlen(argv[1]));
if (!fork2_n_mount("/")) {
fs_dir_inject(argv[1]);
exit(1);
@@ -79,7 +79,7 @@ void run_args(int argc, char **argv, struct redir *redir) {
}
if (fork()) {
- _syscall_await();
+ _sys_await();
return;
}
@@ -91,18 +91,18 @@ void run_args(int argc, char **argv, struct redir *redir) {
/* a workaround for file offsets not being preserved across exec()s.
* TODO document that weird behaviour of exec() */
- handle_t p[2];
- if (_syscall_pipe(p, 0) < 0) {
+ hid_t p[2];
+ if (_sys_pipe(p, 0) < 0) {
errx(1, "couldn't create redirection pipe");
}
- if (!_syscall_fork(FORK_NOREAP, NULL)) {
+ if (!_sys_fork(FORK_NOREAP, NULL)) {
/* the child forwards data from the pipe to the file */
const size_t buflen = 512;
char *buf = malloc(buflen);
if (!buf) err(1, "when redirecting");
close(p[1]);
for (;;) {
- long len = _syscall_read(p[0], buf, buflen, 0);
+ long len = _sys_read(p[0], buf, buflen, 0);
if (len < 0) exit(0);
fwrite(buf, 1, len, f);
if (ferror(f)) exit(0);
@@ -111,7 +111,7 @@ void run_args(int argc, char **argv, struct redir *redir) {
fclose(f);
close(p[0]);
- if (_syscall_dup(p[1], 1, 0) < 0) {
+ if (_sys_dup(p[1], 1, 0) < 0) {
errx(1, "dup() failed when redirecting");
}
}
diff --git a/src/user/app/tests/kernel/fdlimit.c b/src/user/app/tests/kernel/fdlimit.c
index d22af13..f332357 100644
--- a/src/user/app/tests/kernel/fdlimit.c
+++ b/src/user/app/tests/kernel/fdlimit.c
@@ -4,10 +4,10 @@
#include <unistd.h>
static void test_fdlimit_pipe(void) {
- handle_t ends[2];
- handle_t h[2] = {-1, -1};
+ hid_t ends[2];
+ hid_t h[2] = {-1, -1};
for (;;) {
- handle_t cur = _syscall_open("/", 1, OPEN_READ);
+ hid_t cur = _sys_open("/", 1, OPEN_READ);
if (cur == -EMFILE) break;
test(cur >= 0);
h[0] = h[1];
@@ -15,31 +15,31 @@ static void test_fdlimit_pipe(void) {
}
test(h[0] >= 0); /* we need at least two handles */
- test(_syscall_pipe(ends, 0) == -EMFILE);
- test(_syscall_open("/", 1, OPEN_READ) == -EMFILE);
+ test(_sys_pipe(ends, 0) == -EMFILE);
+ test(_sys_open("/", 1, OPEN_READ) == -EMFILE);
close(h[1]);
- test(_syscall_pipe(ends, 0) == -EMFILE);
- test(_syscall_open("/", 1, OPEN_READ) == h[1]);
- test(_syscall_open("/", 1, OPEN_READ) == -EMFILE);
+ test(_sys_pipe(ends, 0) == -EMFILE);
+ test(_sys_open("/", 1, OPEN_READ) == h[1]);
+ test(_sys_open("/", 1, OPEN_READ) == -EMFILE);
close(h[0]);
close(h[1]);
- test(_syscall_pipe(ends, 0) == 0);
+ test(_sys_pipe(ends, 0) == 0);
}
static void test_fdlimit_fork(void) {
for (;;) {
- handle_t cur = _syscall_open("/", 1, OPEN_READ);
+ hid_t cur = _sys_open("/", 1, OPEN_READ);
if (cur == -EMFILE) break;
test(cur >= 0);
}
- if (!_syscall_fork(0, NULL)) _syscall_exit(123);
+ if (!_sys_fork(0, NULL)) _sys_exit(123);
- test(_syscall_fork(FORK_NEWFS, NULL) == -EMFILE);
- test(_syscall_await() == 123);
- test(_syscall_await() == ~0);
+ test(_sys_fork(FORK_NEWFS, NULL) == -EMFILE);
+ test(_sys_await() == 123);
+ test(_sys_await() == ~0);
}
void r_k_fdlimit(void) {
diff --git a/src/user/app/tests/kernel/fs.c b/src/user/app/tests/kernel/fs.c
index 6669c41..b5684d7 100644
--- a/src/user/app/tests/kernel/fs.c
+++ b/src/user/app/tests/kernel/fs.c
@@ -5,34 +5,34 @@
#include <string.h>
static void test_unfinished_req(void) {
- handle_t h = -1;
- int ret = _syscall_fork(FORK_NEWFS, &h);
+ hid_t h = -1;
+ int ret = _sys_fork(FORK_NEWFS, &h);
test(0 <= ret);
if (ret == 0) {
// TODO make a similar test with all 0s passed to fs_wait
struct ufs_request res;
- _syscall_fs_wait(NULL, 0, &res);
+ _sys_fs_wait(NULL, 0, &res);
// TODO second fs_wait
exit(0);
} else {
test(0 <= h);
- test(_syscall_mount(h, "/", 1) == 0);
- int ret = _syscall_open("/", 1, 0);
+ test(_sys_mount(h, "/", 1) == 0);
+ int ret = _sys_open("/", 1, 0);
test(ret < 0);
// the handler quits while handling that call - but this syscall should return anyways
}
}
static void test_orphaned_fs(void) {
- handle_t h = -1;
- int ret = _syscall_fork(FORK_NEWFS, &h);
+ hid_t h = -1;
+ int ret = _sys_fork(FORK_NEWFS, &h);
test(0 <= ret);
if (ret == 0) {
exit(0);
} else {
test(0 <= h);
- test(_syscall_mount(h, "/", 1) == 0);
- int ret = _syscall_open("/", 1, 0);
+ test(_sys_mount(h, "/", 1) == 0);
+ int ret = _sys_open("/", 1, 0);
test(ret < 0);
}
}
@@ -41,32 +41,32 @@ static void test_fs_cleanup(void) {
const char *msg = "success";
int msglen = 8;
char buf[16];
- handle_t ends[2];
- test(_syscall_pipe(ends, 0) >= 0);
- if (!_syscall_fork(0, NULL)) {
- handle_t h = -1;
- if (_syscall_fork(FORK_NEWFS, &h) == 0) {
+ hid_t ends[2];
+ test(_sys_pipe(ends, 0) >= 0);
+ if (!_sys_fork(0, NULL)) {
+ hid_t h = -1;
+ if (_sys_fork(FORK_NEWFS, &h) == 0) {
for (;;) {
struct ufs_request req;
- handle_t reqh = _syscall_fs_wait(buf, sizeof buf, &req);
+ hid_t reqh = _sys_fs_wait(buf, sizeof buf, &req);
if (reqh < 0) break;
- _syscall_fs_respond(reqh, NULL, 0, 0); /* success */
+ _sys_fs_respond(reqh, NULL, 0, 0); /* success */
}
/* this is the test: does it break out of the loop
* when it should cleanup */
- _syscall_write(ends[1], msg, msglen, -1, 0);
+ _sys_write(ends[1], msg, msglen, -1, 0);
exit(0);
} else {
- test(_syscall_mount(h, "/", 1) == 0);
- h = _syscall_open("/", 1, 0);
+ test(_sys_mount(h, "/", 1) == 0);
+ h = _sys_open("/", 1, 0);
test(h >= 0);
- _syscall_close(h);
+ _sys_close(h);
// TODO another test without the delay
- _syscall_sleep(0);
+ _sys_sleep(0);
exit(0);
}
} else {
- test(_syscall_read(ends[0], buf, sizeof buf, 0) == msglen);
+ test(_sys_read(ends[0], buf, sizeof buf, 0) == msglen);
test(memcmp(buf, msg, msglen) == 0);
}
}
diff --git a/src/user/app/tests/kernel/misc.c b/src/user/app/tests/kernel/misc.c
index f6a8feb..b60ebc0 100644
--- a/src/user/app/tests/kernel/misc.c
+++ b/src/user/app/tests/kernel/misc.c
@@ -16,7 +16,7 @@ static void test_fault_kill(void) {
}
int await_cnt = 0;
- while (_syscall_await() != ~0) await_cnt++;
+ while (_sys_await() != ~0) await_cnt++;
test(await_cnt == 2);
}
@@ -24,32 +24,32 @@ static void test_efault(void) {
const char *str = "o, 16 characters";
char str2[16];
char *invalid = (void*)0x1000;
- handle_t h;
+ hid_t h;
memcpy(str2, str, 16);
- test((h = _syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE)) >= 0);
- test(_syscall_write(h, str, 16, 0, 0) == 16);
- test(_syscall_write(h, str2, 16, 0, 0) == 16);
+ test((h = _sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE)) >= 0);
+ test(_sys_write(h, str, 16, 0, 0) == 16);
+ test(_sys_write(h, str2, 16, 0, 0) == 16);
- test(_syscall_write(h, invalid, 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, invalid, 16, 0, 0) == -EFAULT);
/* x64 non-canonical pointers */
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x8000000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x1000000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0100000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0010000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0001000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str ^ 0x0000800000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x8000000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x1000000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0100000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0010000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0001000000000000), 16, 0, 0) == -EFAULT);
+ test(_sys_write(h, (void*)((uintptr_t)str2 ^ 0x0000800000000000), 16, 0, 0) == -EFAULT);
- test(_syscall_write(h, str, 16, 0, 0) == 16);
+ test(_sys_write(h, str, 16, 0, 0) == 16);
close(h);
}
diff --git a/src/user/app/tests/kernel/miscsyscall.c b/src/user/app/tests/kernel/miscsyscall.c
index 58a9afb..c90560e 100644
--- a/src/user/app/tests/kernel/miscsyscall.c
+++ b/src/user/app/tests/kernel/miscsyscall.c
@@ -17,7 +17,7 @@ static void test_await(void) {
if (!fork())
exit(i);
- while ((ret = _syscall_await()) != ~0) {
+ while ((ret = _sys_await()) != ~0) {
test(0 <= ret && ret < 16);
counts[ret]++;
}
@@ -30,114 +30,114 @@ static void test_await2(void) {
/* hangs on failure */
if (!fork()) {
if (!fork()) {
- for (;;) _syscall_sleep(1000000000);
+ for (;;) _sys_sleep(1000000000);
} else {
exit(123);
}
}
- test(_syscall_await() == 123);
- test(_syscall_await() == ~0); /* don't wait for tombstone */
- _syscall_filicide();
+ test(_sys_await() == 123);
+ test(_sys_await() == ~0); /* don't wait for tombstone */
+ _sys_filicide();
}
static void test_pipe(void) {
const char *pipe_msgs[2] = {"hello", "world"};
- handle_t ends[2];
+ hid_t ends[2];
char buf[16];
/* test regular reads / writes */
- test(_syscall_pipe(ends, 0) >= 0);
+ test(_sys_pipe(ends, 0) >= 0);
if (!fork()) {
/* those repeated asserts ensure that you can't read/write to the wrong ends */
- test(_syscall_read(ends[1], buf, 16, 0) < 0);
- test(_syscall_write(ends[0], buf, 16, 0, 0) < 0);
+ test(_sys_read(ends[1], buf, 16, 0) < 0);
+ test(_sys_write(ends[0], buf, 16, 0, 0) < 0);
- test(5 == _syscall_write(ends[1], pipe_msgs[0], 5, -1, 0));
+ test(5 == _sys_write(ends[1], pipe_msgs[0], 5, -1, 0));
- test(_syscall_read(ends[1], buf, 16, 0) < 0);
- test(_syscall_write(ends[0], buf, 16, 0, 0) < 0);
+ test(_sys_read(ends[1], buf, 16, 0) < 0);
+ test(_sys_write(ends[0], buf, 16, 0, 0) < 0);
- test(5 == _syscall_write(ends[1], pipe_msgs[1], 5, -1, 0));
+ test(5 == _sys_write(ends[1], pipe_msgs[1], 5, -1, 0));
exit(0);
} else {
- test(_syscall_read(ends[1], buf, 16, 0) < 0);
- test(_syscall_write(ends[0], buf, 16, 0, 0) < 0);
+ test(_sys_read(ends[1], buf, 16, 0) < 0);
+ test(_sys_write(ends[0], buf, 16, 0, 0) < 0);
- test(5 == _syscall_read(ends[0], buf, 16, 0));
+ test(5 == _sys_read(ends[0], buf, 16, 0));
test(!memcmp(buf, pipe_msgs[0], 5));
- test(_syscall_read(ends[1], buf, 16, 0) < 0);
- test(_syscall_write(ends[0], buf, 16, 0, 0) < 0);
+ test(_sys_read(ends[1], buf, 16, 0) < 0);
+ test(_sys_write(ends[0], buf, 16, 0, 0) < 0);
- test(5 == _syscall_read(ends[0], buf, 16, 0));
+ test(5 == _sys_read(ends[0], buf, 16, 0));
test(!memcmp(buf, pipe_msgs[1], 5));
- _syscall_await();
+ _sys_await();
}
close(ends[0]);
close(ends[1]);
/* writing to pipes with one end closed */
- test(_syscall_pipe(ends, 0) >= 0);
+ test(_sys_pipe(ends, 0) >= 0);
for (int i = 0; i < 16; i++) {
if (!fork()) {
close(ends[1]);
- test(_syscall_read(ends[0], buf, 16, 0) < 0);
+ test(_sys_read(ends[0], buf, 16, 0) < 0);
exit(0);
}
}
close(ends[1]);
for (int i = 0; i < 16; i++)
- _syscall_await();
+ _sys_await();
close(ends[0]);
- test(_syscall_pipe(ends, 0) >= 0);
+ test(_sys_pipe(ends, 0) >= 0);
for (int i = 0; i < 16; i++) {
if (!fork()) {
close(ends[0]);
- test(_syscall_write(ends[1], buf, 16, 0, 0) < 0);
+ test(_sys_write(ends[1], buf, 16, 0, 0) < 0);
exit(0);
}
}
close(ends[0]);
for (int i = 0; i < 16; i++)
- _syscall_await();
+ _sys_await();
close(ends[1]);
/* queueing */
- test(_syscall_pipe(ends, 0) >= 0);
+ test(_sys_pipe(ends, 0) >= 0);
for (int i = 0; i < 16; i++) {
if (!fork()) {
- test(_syscall_write(ends[1], pipe_msgs[0], 5, -1, 0) == 5);
+ test(_sys_write(ends[1], pipe_msgs[0], 5, -1, 0) == 5);
exit(0);
}
}
close(ends[1]);
for (int i = 0; i < 16; i++) {
- test(_syscall_read(ends[0], buf, sizeof buf, 0) == 5);
- _syscall_await();
+ test(_sys_read(ends[0], buf, sizeof buf, 0) == 5);
+ _sys_await();
}
- test(_syscall_read(ends[0], buf, sizeof buf, 0) < 0);
+ test(_sys_read(ends[0], buf, sizeof buf, 0) < 0);
close(ends[0]);
- test(_syscall_pipe(ends, 0) >= 0);
+ test(_sys_pipe(ends, 0) >= 0);
for (int i = 0; i < 16; i++) {
if (!fork()) {
memset(buf, 0, sizeof buf);
- test(_syscall_read(ends[0], buf, 5, -1) == 5);
+ test(_sys_read(ends[0], buf, 5, -1) == 5);
test(!memcmp(buf, pipe_msgs[1], 5));
exit(0);
}
}
close(ends[0]);
for (int i = 0; i < 16; i++) {
- test(_syscall_write(ends[1], pipe_msgs[1], 5, -1, 0) == 5);
- _syscall_await();
+ test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) == 5);
+ _sys_await();
}
- test(_syscall_write(ends[1], pipe_msgs[1], 5, -1, 0) < 0);
+ test(_sys_write(ends[1], pipe_msgs[1], 5, -1, 0) < 0);
close(ends[1]);
@@ -147,65 +147,65 @@ static void test_pipe(void) {
static void test_memflag(void) {
void *page = (void*)0x77777000;
- _syscall_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page
+ _sys_memflag(page, 4096, MEMFLAG_PRESENT); // allocate page
memset(page, 77, 4096); // write to it
- _syscall_memflag(page, 4096, 0); // free it
+ _sys_memflag(page, 4096, 0); // free it
if (!fork()) {
memset(page, 11, 4096); // should segfault
exit(0);
} else {
- test(_syscall_await() != 0); // test if the process crashed
+ test(_sys_await() != 0); // test if the process crashed
}
char *pages[4];
for (size_t i = 0; i < 4; i++) {
- pages[i] = _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE);
- test(pages[i] == _syscall_memflag(NULL, 4096, MEMFLAG_FINDFREE | MEMFLAG_PRESENT));
+ pages[i] = _sys_memflag(NULL, 4096, MEMFLAG_FINDFREE);
+ test(pages[i] == _sys_memflag(NULL, 4096, MEMFLAG_FINDFREE | MEMFLAG_PRESENT));
if (i > 0) test(pages[i] != pages[i-1]);
*pages[i] = 0x77;
}
for (size_t i = 0; i < 4; i++)
- _syscall_memflag(pages, 4096, MEMFLAG_PRESENT);
+ _sys_memflag(pages, 4096, MEMFLAG_PRESENT);
}
static void test_dup(void) {
- handle_t pipe[2];
- handle_t h1, h2;
- test(_syscall_pipe(pipe, 0) >= 0);
+ hid_t pipe[2];
+ hid_t h1, h2;
+ test(_sys_pipe(pipe, 0) >= 0);
if (!fork()) {
close(pipe[0]);
- h1 = _syscall_dup(pipe[1], -1, 0);
+ h1 = _sys_dup(pipe[1], -1, 0);
test(h1 >= 0);
test(h1 != pipe[1]);
- h2 = _syscall_dup(h1, -1, 0);
+ h2 = _sys_dup(h1, -1, 0);
test(h2 >= 0);
test(h2 != pipe[1] && h2 != h1);
- _syscall_write(pipe[1], "og", 2, 0, 0);
- _syscall_write(h1, "h1", 2, 0, 0);
- _syscall_write(h2, "h2", 2, 0, 0);
+ _sys_write(pipe[1], "og", 2, 0, 0);
+ _sys_write(h1, "h1", 2, 0, 0);
+ _sys_write(h2, "h2", 2, 0, 0);
close(pipe[1]);
- _syscall_write(h1, "h1", 2, 0, 0);
- _syscall_write(h2, "h2", 2, 0, 0);
+ _sys_write(h1, "h1", 2, 0, 0);
+ _sys_write(h2, "h2", 2, 0, 0);
- test(_syscall_dup(h1, pipe[1], 0) == pipe[1]);
- test(_syscall_dup(h2, pipe[1], 0) == pipe[1]);
- test(_syscall_dup(h1, pipe[1], 0) == pipe[1]);
- test(_syscall_dup(h2, pipe[1], 0) == pipe[1]);
+ test(_sys_dup(h1, pipe[1], 0) == pipe[1]);
+ test(_sys_dup(h2, pipe[1], 0) == pipe[1]);
+ test(_sys_dup(h1, pipe[1], 0) == pipe[1]);
+ test(_sys_dup(h2, pipe[1], 0) == pipe[1]);
close(h1);
close(h2);
- test(_syscall_dup(pipe[1], h2, 0) == h2);
- _syscall_write(h2, "h2", 2, 0, 0);
+ test(_sys_dup(pipe[1], h2, 0) == h2);
+ _sys_write(h2, "h2", 2, 0, 0);
close(h2);
- test(_syscall_dup(pipe[1], h1, 0) == h1);
- _syscall_write(h1, "h1", 2, 0, 0);
+ test(_sys_dup(pipe[1], h1, 0) == h1);
+ _sys_write(h1, "h1", 2, 0, 0);
close(h1);
exit(0);
@@ -213,10 +213,10 @@ static void test_dup(void) {
char buf[16];
size_t count = 0;
close(pipe[1]);
- while (_syscall_read(pipe[0], buf, sizeof buf, 0) >= 0)
+ while (_sys_read(pipe[0], buf, sizeof buf, 0) >= 0)
count++;
test(count == 7);
- _syscall_await();
+ _sys_await();
}
@@ -226,47 +226,47 @@ static void test_dup(void) {
static void test_execbuf(void) {
if (!fork()) {
uint64_t buf[] = {
- EXECBUF_SYSCALL, _SYSCALL_EXIT, 123, 0, 0, 0, 0,
+ EXECBUF_SYSCALL, _SYS_EXIT, 123, 0, 0, 0, 0,
};
- _syscall_execbuf(buf, sizeof buf);
+ _sys_execbuf(buf, sizeof buf);
test_fail();
} else {
- test(_syscall_await() == 123);
+ test(_sys_await() == 123);
}
}
static void test_sleep(void) {
- handle_t reader;
+ hid_t reader;
FILE *writer;
if (!forkpipe(&writer, &reader)) {
if (!fork()) {
if (!fork()) {
- _syscall_sleep(100);
+ _sys_sleep(100);
fprintf(writer, "1");
- _syscall_sleep(200);
+ _sys_sleep(200);
fprintf(writer, "3");
- _syscall_sleep(200);
+ _sys_sleep(200);
fprintf(writer, "5");
- _syscall_exit(0);
+ _sys_exit(0);
}
if (!fork()) {
fprintf(writer, "0");
- _syscall_sleep(200);
+ _sys_sleep(200);
fprintf(writer, "2");
- _syscall_sleep(200);
+ _sys_sleep(200);
fprintf(writer, "4");
/* get killed while asleep
* a peaceful death, i suppose. */
- for (;;) _syscall_sleep(1000000000);
+ for (;;) _sys_sleep(1000000000);
}
- _syscall_await();
- _syscall_filicide();
- _syscall_exit(0);
+ _sys_await();
+ _sys_filicide();
+ _sys_exit(0);
}
/* this part checks if, after killing an asleep process,
* other processes can still wake up */
- _syscall_sleep(600);
+ _sys_sleep(600);
fprintf(writer, "6");
exit(0);
} else {
@@ -275,7 +275,7 @@ static void test_sleep(void) {
size_t pos = 0;
for (;;) {
char buf[128];
- long ret = _syscall_read(reader, buf, sizeof buf, 0);
+ long ret = _sys_read(reader, buf, sizeof buf, 0);
if (ret < 0) break;
test(pos + ret <= target);
test(memcmp(buf, expected + pos, ret) == 0);
@@ -286,8 +286,8 @@ static void test_sleep(void) {
}
static void test_badopen(void) {
- test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE) >= 0);
- test(_syscall_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL);
+ test(_sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE | OPEN_WRITE) >= 0);
+ test(_sys_open(TMPFILEPATH, strlen(TMPFILEPATH), OPEN_CREATE) == -EINVAL);
}
void r_k_miscsyscall(void) {
diff --git a/src/user/app/tests/kernel/path.c b/src/user/app/tests/kernel/path.c
index 2bce344..5392681 100644
--- a/src/user/app/tests/kernel/path.c
+++ b/src/user/app/tests/kernel/path.c
@@ -94,11 +94,11 @@ static void test_mount_resolve(void) {
for (size_t i = 0; i < sizeof(testcases) / sizeof(testcases[0]); i++) {
const char *input = testcases[i][0];
const char *expected = testcases[i][1];
- handle_t h = _syscall_open(input, strlen(input), 0);
+ hid_t h = _sys_open(input, strlen(input), 0);
test(h >= 0);
- int len = _syscall_read(h, buf, sizeof buf, 0);
+ int len = _sys_read(h, buf, sizeof buf, 0);
test(len == (int)strlen(expected) && !memcmp(expected, buf, len));
- _syscall_close(h);
+ _sys_close(h);
}
}
diff --git a/src/user/app/tests/kernel/threads.c b/src/user/app/tests/kernel/threads.c
index cb7111d..abca41c 100644
--- a/src/user/app/tests/kernel/threads.c
+++ b/src/user/app/tests/kernel/threads.c
@@ -18,13 +18,13 @@ static void test_basic_thread(void) {
test(global_n == 10);
}
-handle_t global_h;
+hid_t global_h;
static void shared_handle(void *sem) {
- handle_t ends[2];
- test(_syscall_pipe(ends, 0) >= 0);
+ hid_t ends[2];
+ test(_sys_pipe(ends, 0) >= 0);
global_h = ends[0];
esem_signal(sem);
- _syscall_write(ends[1], "Hello!", 7, -1, 0);
+ _sys_write(ends[1], "Hello!", 7, -1, 0);
}
static void test_shared_handle(void) {
struct evil_sem *sem = esem_new(0);
@@ -34,7 +34,7 @@ static void test_shared_handle(void) {
esem_wait(sem);
test(global_h >= 0);
- test(_syscall_read(global_h, buf, sizeof buf, 0) == 7);
+ test(_sys_read(global_h, buf, sizeof buf, 0) == 7);
test(!strcmp("Hello!", buf));
}
@@ -44,7 +44,7 @@ static void many_thread(void *arg) {
static void test_many_threads(void) {
uint64_t n = 0;
for (int i = 0; i < 10; i++) thread_create(0, many_thread, &n);
- for (int i = 0; i < 10; i++) _syscall_await();
+ for (int i = 0; i < 10; i++) _sys_await();
test(n == 100);
}
diff --git a/src/user/app/tests/libc/esemaphore.c b/src/user/app/tests/libc/esemaphore.c
index f1856ff..2f1d4bc 100644
--- a/src/user/app/tests/libc/esemaphore.c
+++ b/src/user/app/tests/libc/esemaphore.c
@@ -6,37 +6,37 @@
#include <unistd.h>
#include <user/lib/esemaphore.h>
-static void odd(handle_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
- _syscall_write(out, "1", 1, -1, 0);
+static void odd(hid_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
+ _sys_write(out, "1", 1, -1, 0);
esem_signal(sem1);
esem_wait(sem2);
- _syscall_write(out, "3", 1, -1, 0);
+ _sys_write(out, "3", 1, -1, 0);
esem_signal(sem1);
esem_wait(sem2);
- _syscall_write(out, "5", 1, -1, 0);
+ _sys_write(out, "5", 1, -1, 0);
esem_signal(sem1);
}
-static void even(handle_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
+static void even(hid_t out, struct evil_sem *sem1, struct evil_sem *sem2) {
esem_wait(sem1);
- _syscall_write(out, "2", 1, -1, 0);
+ _sys_write(out, "2", 1, -1, 0);
esem_signal(sem2);
esem_wait(sem1);
- _syscall_write(out, "4", 1, -1, 0);
+ _sys_write(out, "4", 1, -1, 0);
esem_signal(sem2);
esem_wait(sem1);
- _syscall_write(out, "6", 1, -1, 0);
+ _sys_write(out, "6", 1, -1, 0);
esem_signal(sem2);
}
static void test_semaphore(void) {
struct evil_sem *sem1, *sem2;
- handle_t pipe[2];
- test(_syscall_pipe(pipe, 0) >= 0);
+ hid_t pipe[2];
+ test(_sys_pipe(pipe, 0) >= 0);
if (!fork()) {
sem1 = esem_new(0);
@@ -47,12 +47,12 @@ static void test_semaphore(void) {
exit(69);
} else {
even(pipe[1], sem1, sem2);
- test(_syscall_await() == 69);
+ test(_sys_await() == 69);
}
esem_free(sem1);
esem_free(sem2);
- _syscall_write(pipe[1], "|", 1, -1, 0);
+ _sys_write(pipe[1], "|", 1, -1, 0);
sem1 = esem_new(0);
sem2 = esem_new(0);
@@ -62,13 +62,13 @@ static void test_semaphore(void) {
exit(69);
} else {
odd(pipe[1], sem1, sem2);
- test(_syscall_await() == 69);
- _syscall_await();
+ test(_sys_await() == 69);
+ _sys_await();
}
esem_free(sem1);
esem_free(sem2);
- _syscall_filicide();
+ _sys_filicide();
exit(0);
} else {
close(pipe[1]);
@@ -76,7 +76,7 @@ static void test_semaphore(void) {
char buf[16];
size_t pos = 0;
for (;;) {
- int ret = _syscall_read(pipe[0], buf + pos, sizeof(buf) - pos, 0);
+ int ret = _sys_read(pipe[0], buf + pos, sizeof(buf) - pos, 0);
if (ret < 0) break;
pos += ret;
}
@@ -86,7 +86,7 @@ static void test_semaphore(void) {
test_fail();
}
- _syscall_await();
+ _sys_await();
}
}
diff --git a/src/user/app/tests/stress.c b/src/user/app/tests/stress.c
index 1df462a..1ef018c 100644
--- a/src/user/app/tests/stress.c
+++ b/src/user/app/tests/stress.c
@@ -11,7 +11,7 @@ static void run_forked(void (*fn)()) {
} else {
/* successful tests must return 0
* TODO add a better fail msg */
- if (_syscall_await() != 0) test_fail();
+ if (_sys_await() != 0) test_fail();
}
}
@@ -19,7 +19,7 @@ static void run_forked(void (*fn)()) {
static void stress_fork(void) {
for (size_t i = 0; i < 2048; i++) {
if (!fork()) exit(0);
- _syscall_await();
+ _sys_await();
}
}
diff --git a/src/user/app/tests/tests.c b/src/user/app/tests/tests.c
index f2f9aa5..7139fc7 100644
--- a/src/user/app/tests/tests.c
+++ b/src/user/app/tests/tests.c
@@ -10,19 +10,19 @@ FILE *fail_trig;
void run_test(void (*fn)()) {
if (!fork()) {
fn();
- _syscall_filicide();
+ _sys_filicide();
exit(0);
} else {
/* successful tests must return 0 */
- if (_syscall_await() != 0) {
+ if (_sys_await() != 0) {
test_failf("%p, base %p", (void*)fn - (void*)_image_base, _image_base);
}
}
}
-int forkpipe(FILE **f, handle_t *h) {
- handle_t ends[2];
- if (_syscall_pipe(ends, 0) < 0) {
+int forkpipe(FILE **f, hid_t *h) {
+ hid_t ends[2];
+ if (_sys_pipe(ends, 0) < 0) {
fprintf(stderr, "couldn't create pipe\n");
exit(1);
}
@@ -40,7 +40,7 @@ int forkpipe(FILE **f, handle_t *h) {
}
int main(void) {
- handle_t reader;
+ hid_t reader;
if (!forkpipe(&fail_trig, &reader)) {
r_k_miscsyscall();
r_k_fs();
@@ -57,7 +57,7 @@ int main(void) {
} else {
for (;;) {
char buf[128];
- long ret = _syscall_read(reader, buf, sizeof buf, 0);
+ long ret = _sys_read(reader, buf, sizeof buf, 0);
if (ret < 0) break;
printf("\033[31mFAIL\033[0m ");
fwrite(buf, ret, 1, stdout);
diff --git a/src/user/app/tests/tests.h b/src/user/app/tests/tests.h
index e93653e..5037e1a 100644
--- a/src/user/app/tests/tests.h
+++ b/src/user/app/tests/tests.h
@@ -21,7 +21,7 @@ void r_s_ringbuf(void);
extern FILE *fail_trig;
-int forkpipe(FILE **f, handle_t *h);
+int forkpipe(FILE **f, hid_t *h);
#define argify(str) str, sizeof(str) - 1
#define test_fail() do { \
diff --git a/src/user/app/tmpfs/tmpfs.c b/src/user/app/tmpfs/tmpfs.c
index c55da59..6d58790 100644
--- a/src/user/app/tmpfs/tmpfs.c
+++ b/src/user/app/tmpfs/tmpfs.c
@@ -123,14 +123,14 @@ int main(void) {
for (;;) {
struct ufs_request req;
- handle_t reqh = ufs_wait(buf, buflen, &req);
+ hid_t reqh = ufs_wait(buf, buflen, &req);
struct node *ptr = req.id;
if (reqh < 0) break;
switch (req.op) {
case VFSOP_OPEN:
ptr = tmpfs_open(buf, &req);
- _syscall_fs_respond(reqh, ptr, ptr ? 0 : -ENOENT, 0);
+ _sys_fs_respond(reqh, ptr, ptr ? 0 : -ENOENT, 0);
break;
case VFSOP_READ:
@@ -140,16 +140,16 @@ int main(void) {
for (struct node *iter = ptr->child; iter; iter = iter->sibling) {
dir_appendl(&db, iter->name, iter->namelen);
}
- _syscall_fs_respond(reqh, buf, dir_finish(&db), 0);
+ _sys_fs_respond(reqh, buf, dir_finish(&db), 0);
} else {
fs_normslice(&req.offset, &req.len, ptr->size, false);
- _syscall_fs_respond(reqh, ptr->buf + req.offset, req.len, 0);
+ _sys_fs_respond(reqh, ptr->buf + req.offset, req.len, 0);
}
break;
case VFSOP_WRITE:
if (ptr->directory) {
- _syscall_fs_respond(reqh, NULL, -ENOSYS, 0);
+ _sys_fs_respond(reqh, NULL, -ENOSYS, 0);
break;
}
@@ -163,7 +163,7 @@ int main(void) {
if ((req.flags & WRITE_TRUNCATE) || ptr->size < req.offset + req.len) {
ptr->size = req.offset + req.len;
}
- _syscall_fs_respond(reqh, NULL, req.len, 0);
+ _sys_fs_respond(reqh, NULL, req.len, 0);
break;
case VFSOP_GETSIZE:
@@ -174,23 +174,23 @@ int main(void) {
for (struct node *iter = ptr->child; iter; iter = iter->sibling) {
dir_append(&db, iter->name);
}
- _syscall_fs_respond(reqh, NULL, dir_finish(&db), 0);
+ _sys_fs_respond(reqh, NULL, dir_finish(&db), 0);
} else {
- _syscall_fs_respond(reqh, NULL, ptr->size, 0);
+ _sys_fs_respond(reqh, NULL, ptr->size, 0);
}
break;
case VFSOP_REMOVE:
- _syscall_fs_respond(reqh, NULL, node_remove(ptr), 0);
+ _sys_fs_respond(reqh, NULL, node_remove(ptr), 0);
break;
case VFSOP_CLOSE:
node_close(ptr);
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/bootstrap/entry.S b/src/user/bootstrap/entry.S
index ecd60dd..04b4238 100644
--- a/src/user/bootstrap/entry.S
+++ b/src/user/bootstrap/entry.S
@@ -9,14 +9,14 @@
.global _start
.type _start, @function
_start:
- mov $_SYSCALL_MEMFLAG, %rdi
+ mov $_SYS_MEMFLAG, %rdi
mov $(STACK_TOP & ~0xFFF - (STACK_PAGES - 1) * 0x1000), %rsi
mov $(STACK_PAGES * 0x1000), %rdx
mov $MEMFLAG_PRESENT, %r10
syscall
mov $(STACK_TOP & ~0xF), %rsp
- mov $_SYSCALL_MEMFLAG, %rdi
+ mov $_SYS_MEMFLAG, %rdi
mov $_bss_start, %rsi
mov $_bss_end, %rdx
sub $_bss_start, %rdx
diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c
index 577f1d8..f2938b9 100644
--- a/src/user/bootstrap/main.c
+++ b/src/user/bootstrap/main.c
@@ -14,7 +14,7 @@ extern char _initrd;
__attribute__((section(".text")))
_Noreturn void main(void) {
- _syscall_memflag(_libc_psdata, 1, MEMFLAG_PRESENT);
+ _sys_memflag(_libc_psdata, 1, MEMFLAG_PRESENT);
setprogname("bootstrap");
setproctitle(NULL);
@@ -25,7 +25,7 @@ _Noreturn void main(void) {
fs_whitelist(l);
}
- _syscall_mount(HANDLE_PROCFS, "/proc/", strlen("/proc/"));
+ _sys_mount(HANDLE_PROCFS, "/proc/", strlen("/proc/"));
MOUNT_AT("/") { fs_dir_inject("/proc/"); }
MOUNT_AT("/init/") { tar_driver(&_initrd); }
@@ -40,5 +40,5 @@ _Noreturn void main(void) {
} else {
_klogf("couldn't find init.elf");
}
- _syscall_exit(1);
+ _sys_exit(1);
}
diff --git a/src/user/lib/_start2.c b/src/user/lib/_start2.c
index 2cf8667..648c0c6 100644
--- a/src/user/lib/_start2.c
+++ b/src/user/lib/_start2.c
@@ -26,14 +26,14 @@ _Noreturn void _start2(struct execdata *ed) {
elf_selfreloc();
/* done first so it isn't allocated elsewhere by accident */
- _syscall_memflag(_libc_psdata, 1, MEMFLAG_PRESENT);
+ _sys_memflag(_libc_psdata, 1, MEMFLAG_PRESENT);
if (ed->argv[0]) {
strcpy(_libc_psdata, ed->argv[0]);
} else {
strcpy(_libc_psdata, "?");
}
- _syscall_intr_set(intr_trampoline);
+ _sys_intr_set(intr_trampoline);
intr_set(intr_default);
__setinitialcwd(ed->cwd);
diff --git a/src/user/lib/assert.c b/src/user/lib/assert.c
index f42d696..0c46450 100644
--- a/src/user/lib/assert.c
+++ b/src/user/lib/assert.c
@@ -4,5 +4,5 @@
_Noreturn void __badassert(const char *func, const char *file, int line) {
fprintf(stderr, "assertion failure %s:%s:%u\n", file, func, line);
- _syscall_exit(1);
+ _sys_exit(1);
}
diff --git a/src/user/lib/camellia.c b/src/user/lib/camellia.c
index 1aa8402..4e092e4 100644
--- a/src/user/lib/camellia.c
+++ b/src/user/lib/camellia.c
@@ -5,8 +5,8 @@
#include <string.h>
#include <unistd.h>
-handle_t camellia_open(const char *path, int flags) {
- handle_t ret;
+hid_t camellia_open(const char *path, int flags) {
+ hid_t ret;
char *buf;
size_t len;
@@ -20,7 +20,7 @@ handle_t camellia_open(const char *path, int flags) {
if (!buf)
return -errno;
absolutepath(buf, path, len);
- ret = _syscall_open(buf, strlen(buf), flags);
+ ret = _sys_open(buf, strlen(buf), flags);
free(buf);
if (ret < 0)
diff --git a/src/user/lib/compat.c b/src/user/lib/compat.c
index 4634f57..3ec47f9 100644
--- a/src/user/lib/compat.c
+++ b/src/user/lib/compat.c
@@ -4,17 +4,17 @@
#define eprintf(fmt, ...) fprintf(stderr, "user/lib/compat: "fmt"\n" __VA_OPT__(,) __VA_ARGS__)
-static handle_t h = -1;
+static hid_t h = -1;
long c0_fs_wait(char *buf, long len, struct ufs_request *res) {
if (h != -1) {
eprintf("didn't respond to request!");
c0_fs_respond(NULL, -1, 0);
}
- h = _syscall_fs_wait(buf, len, res);
+ h = _sys_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);
+ ret = _sys_fs_respond(h, buf, ret, flags);
h = -1;
return ret;
}
diff --git a/src/user/lib/draw/draw.c b/src/user/lib/draw/draw.c
index 95a8921..3fb6a99 100644
--- a/src/user/lib/draw/draw.c
+++ b/src/user/lib/draw/draw.c
@@ -43,11 +43,11 @@ int fb_setup(struct framebuf *fb, const char *base) {
fb->bpp = strtol(spec, &spec, 0);
if (fb->bpp != 32) return -EINVAL;
- fb->len = _syscall_getsize(fb->fd);
+ fb->len = _sys_getsize(fb->fd);
fb->pitch = fb->len / fb->height;
fb->b = malloc(fb->len);
- _syscall_read(fb->fd, fb->b, fb->len, 0);
+ _sys_read(fb->fd, fb->b, fb->len, 0);
return 0;
}
diff --git a/src/user/lib/draw/draw.h b/src/user/lib/draw/draw.h
index 98316fe..5e614be 100644
--- a/src/user/lib/draw/draw.h
+++ b/src/user/lib/draw/draw.h
@@ -8,7 +8,7 @@ struct framebuf {
uint8_t bpp;
char *b;
- handle_t fd;
+ hid_t fd;
};
struct rect { uint32_t x1, y1, x2, y2; };
diff --git a/src/user/lib/draw/flush.c b/src/user/lib/draw/flush.c
index 060fdaf..3b4a978 100644
--- a/src/user/lib/draw/flush.c
+++ b/src/user/lib/draw/flush.c
@@ -5,7 +5,7 @@
static void flush_combined(struct rect pix, struct framebuf *fb) {
size_t low = fb->pitch * pix.y1 + 4 * pix.x1;
size_t high = fb->pitch * pix.y2 + 4 * pix.y2 + 4;
- _syscall_write(fb->fd, fb->b + low, high - low, low, 0);
+ _sys_write(fb->fd, fb->b + low, high - low, low, 0);
}
static void flush_split(struct rect pix, struct framebuf *fb) {
@@ -21,14 +21,14 @@ static void flush_split(struct rect pix, struct framebuf *fb) {
size_t high = fb->pitch * y + 4 * pix.x2 + 4;
execbuf[epos++] = EXECBUF_SYSCALL;
- execbuf[epos++] = _SYSCALL_WRITE;
+ execbuf[epos++] = _SYS_WRITE;
execbuf[epos++] = fb->fd;
execbuf[epos++] = (uintptr_t)fb->b + low;
execbuf[epos++] = high - low;
execbuf[epos++] = low;
execbuf[epos++] = 0;
}
- _syscall_execbuf(execbuf, epos * sizeof(uint64_t));
+ _sys_execbuf(execbuf, epos * sizeof(uint64_t));
}
void dirty_flush(struct rect *d, struct framebuf *fb) {
diff --git a/src/user/lib/elfload.S b/src/user/lib/elfload.S
index 0f15c06..78d5b3c 100644
--- a/src/user/lib/elfload.S
+++ b/src/user/lib/elfload.S
@@ -15,6 +15,6 @@ _freejmp_chstack:
// _Noreturn void execbuf_chstack(void *stack, void __user *buf, size_t len);
execbuf_chstack:
mov %rdi, %rsp
- mov $_SYSCALL_EXECBUF, %rdi
+ mov $_SYS_EXECBUF, %rdi
syscall
hlt // if execbuf failed we might as well crash
diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c
index a4ee91e..cb7ce58 100644
--- a/src/user/lib/elfload.c
+++ b/src/user/lib/elfload.c
@@ -46,7 +46,7 @@ static bool load_phdr(const void *elf, void *exebase, size_t idx) {
}
// TODO overlap check
// TODO don't ignore flags
- _syscall_memflag(exebase + phdr->p_vaddr, phdr->p_memsz, MEMFLAG_PRESENT);
+ _sys_memflag(exebase + phdr->p_vaddr, phdr->p_memsz, MEMFLAG_PRESENT);
// TODO check that filesz <= memsz
memcpy(exebase + phdr->p_vaddr, elf + phdr->p_offset, phdr->p_filesz);
return true;
@@ -122,8 +122,8 @@ void _freejmp(void *entry, void *low, size_t imglen, const char **argv, char **e
uintptr_t high = (uintptr_t)low + imglen;
uint64_t buf[] = {
- EXECBUF_SYSCALL, _SYSCALL_MEMFLAG, 0, (uintptr_t)low, 0, 0, 0,
- EXECBUF_SYSCALL, _SYSCALL_MEMFLAG, high, ~0 - 0xF000 - high, 0, 0, 0,
+ EXECBUF_SYSCALL, _SYS_MEMFLAG, 0, (uintptr_t)low, 0, 0, 0,
+ EXECBUF_SYSCALL, _SYS_MEMFLAG, high, ~0 - 0xF000 - high, 0, 0, 0,
EXECBUF_JMP, (uintptr_t)entry,
};
execbuf_chstack(stack, buf, sizeof buf);
@@ -137,7 +137,7 @@ static void *elf_loadmem(struct Elf64_Ehdr *ehdr) {
exebase = (void*)0;
break;
case ET_DYN:
- exebase = _syscall_memflag((void*)0x1000, spread, MEMFLAG_FINDFREE);
+ exebase = _sys_memflag((void*)0x1000, spread, MEMFLAG_FINDFREE);
if (!exebase)
return NULL;
break;
@@ -146,7 +146,7 @@ static void *elf_loadmem(struct Elf64_Ehdr *ehdr) {
}
for (size_t phi = 0; phi < ehdr->e_phnum; phi++) {
if (!load_phdr((void*)ehdr, exebase, phi)) {
- _syscall_memflag(exebase, spread, 0);
+ _sys_memflag(exebase, spread, 0);
return NULL;
}
}
@@ -160,7 +160,7 @@ void elf_exec(void *base, char **argv, char **envp) {
void *exebase = elf_loadmem(ehdr);
if (!exebase) return;
- void *newstack = _syscall_memflag((void*)0x11000, 0x1000, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
+ void *newstack = _sys_memflag((void*)0x11000, 0x1000, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
if (!newstack) return;
_freejmp_chstack(exebase + ehdr->e_entry, exebase, elf_spread(ehdr) + 0x1000, (const char**)argv, envp, newstack);
diff --git a/src/user/lib/esemaphore.c b/src/user/lib/esemaphore.c
index f58b510..3a3aa7f 100644
--- a/src/user/lib/esemaphore.c
+++ b/src/user/lib/esemaphore.c
@@ -5,27 +5,27 @@
#include <user/lib/esemaphore.h>
void esem_signal(struct evil_sem *sem) {
- _syscall_write(sem->signal, NULL, 0, 0, 0);
+ _sys_write(sem->signal, NULL, 0, 0, 0);
}
void esem_wait(struct evil_sem *sem) {
- _syscall_read(sem->wait, NULL, 0, 0);
+ _sys_read(sem->wait, NULL, 0, 0);
}
struct evil_sem *esem_new(int value) {
- handle_t ends_wait[2], ends_signal[2];
+ hid_t ends_wait[2], ends_signal[2];
struct evil_sem *sem;
if (value < 0) return NULL;
- if (_syscall_pipe(ends_wait, 0) < 0) return NULL;
- if (_syscall_pipe(ends_signal, 0) < 0) goto fail_signal;
+ if (_sys_pipe(ends_wait, 0) < 0) return NULL;
+ if (_sys_pipe(ends_signal, 0) < 0) goto fail_signal;
if (!(sem = malloc(sizeof *sem))) goto fail_malloc;
- if (!_syscall_fork(FORK_NOREAP, NULL)) {
+ if (!_sys_fork(FORK_NOREAP, NULL)) {
close(ends_signal[1]);
- while (_syscall_read(ends_signal[0], NULL, 0, 0) >= 0) {
- if (!_syscall_fork(FORK_NOREAP, NULL)) {
- _syscall_write(ends_wait[1], NULL, 0, 0, 0);
+ while (_sys_read(ends_signal[0], NULL, 0, 0) >= 0) {
+ if (!_sys_fork(FORK_NOREAP, NULL)) {
+ _sys_write(ends_wait[1], NULL, 0, 0, 0);
exit(0);
}
}
diff --git a/src/user/lib/esemaphore.h b/src/user/lib/esemaphore.h
index 4a16c2e..9cc85e0 100644
--- a/src/user/lib/esemaphore.h
+++ b/src/user/lib/esemaphore.h
@@ -2,7 +2,7 @@
#include <camellia/types.h>
struct evil_sem {
- handle_t wait, signal;
+ hid_t wait, signal;
};
void esem_signal(struct evil_sem *sem);
diff --git a/src/user/lib/fs/dir.c b/src/user/lib/fs/dir.c
index 71b2209..b7f840d 100644
--- a/src/user/lib/fs/dir.c
+++ b/src/user/lib/fs/dir.c
@@ -45,13 +45,13 @@ bool dir_appendl(struct dirbuild *db, const char *name, size_t len) {
return false;
}
-bool dir_append_from(struct dirbuild *db, handle_t h) {
+bool dir_append_from(struct dirbuild *db, hid_t h) {
if (db->error) return true;
if (db->buf && db->bpos == db->blen) return false;
int ret;
if (db->buf) {
- ret = _syscall_read(h, db->buf + db->bpos, db->blen - db->bpos, db->offset);
+ ret = _sys_read(h, db->buf + db->bpos, db->blen - db->bpos, db->offset);
if (ret < 0) {
db->error = ret;
return true;
@@ -63,7 +63,7 @@ bool dir_append_from(struct dirbuild *db, handle_t h) {
} /* else ret == 0, EOF, need getsize */
}
- ret = _syscall_getsize(h);
+ ret = _sys_getsize(h);
if (ret < 0) {
db->error = ret;
return true;
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index ee0b54c..c68d2be 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -11,9 +11,9 @@
#include <camellia/fs/misc.h>
bool fork2_n_mount(const char *path) {
- handle_t h;
- if (_syscall_fork(FORK_NEWFS, &h) > 0) { /* parent */
- _syscall_mount(h, path, strlen(path));
+ hid_t h;
+ if (_sys_fork(FORK_NEWFS, &h) > 0) { /* parent */
+ _sys_mount(h, path, strlen(path));
close(h);
return true;
}
@@ -34,7 +34,7 @@ static int dir_seglen(const char *path) {
return len;
}
-void forward_open(handle_t reqh, const char *path, long len, int flags) {
+void forward_open(hid_t reqh, const char *path, long len, int flags) {
// TODO use threads
// TODO solve for more complex cases, e.g. fs_union
/* done in a separate thread/process because open() can block,
@@ -43,8 +43,8 @@ void forward_open(handle_t reqh, const char *path, long len, int flags) {
* for example, running `httpd` in one term would prevent you from doing
* basically anything on the second term, because fs_dir_inject would be
* stuck on open()ing the socket */
- if (!_syscall_fork(FORK_NOREAP, NULL)) {
- _syscall_fs_respond(reqh, NULL, _syscall_open(path, len, flags), FSR_DELEGATE);
+ if (!_sys_fork(FORK_NOREAP, NULL)) {
+ _sys_fs_respond(reqh, NULL, _sys_open(path, len, flags), FSR_DELEGATE);
exit(0);
}
close(reqh);
@@ -58,13 +58,13 @@ void fs_passthru(const char *prefix) {
for (;;) {
struct ufs_request res;
- handle_t reqh = _syscall_fs_wait(buf, buflen, &res);
+ hid_t reqh = _sys_fs_wait(buf, buflen, &res);
if (reqh < 0) break;
switch (res.op) {
case VFSOP_OPEN:
if (prefix) {
if (prefix_len + res.len > buflen) {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
@@ -76,7 +76,7 @@ void fs_passthru(const char *prefix) {
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
@@ -114,7 +114,7 @@ void fs_union(const char **list) {
char *path = post - prefixlen;
memcpy(path, prefix, prefixlen);
- ret = _syscall_open(path, prefixlen + res.len, res.flags);
+ ret = _sys_open(path, prefixlen + res.len, res.flags);
post[res.len] = '\0';
}
@@ -134,10 +134,10 @@ void fs_union(const char **list) {
size_t prefixlen = strlen(prefix);
// TODO only open the directories once
// TODO ensure trailing slash
- handle_t h = _syscall_open(prefix, prefixlen, OPEN_READ);
+ hid_t h = _sys_open(prefix, prefixlen, OPEN_READ);
if (h < 0) continue;
end = end || dir_append_from(&db, h);
- _syscall_close(h);
+ _sys_close(h);
}
c0_fs_respond(target, dir_finish(&db), 0);
break;
@@ -163,7 +163,7 @@ void fs_dir_inject(const char *path) {
for (;;) {
struct ufs_request res;
- handle_t reqh = _syscall_fs_wait(buf, buflen, &res);
+ hid_t reqh = _sys_fs_wait(buf, buflen, &res);
if (reqh < 0) break;
struct fs_dir_handle *data = res.id;
switch (res.op) {
@@ -174,10 +174,10 @@ void fs_dir_inject(const char *path) {
{
/* opening a directory that we're injecting into */
data = malloc(sizeof *data);
- data->delegate = _syscall_open(buf, res.len, res.flags);
+ data->delegate = _sys_open(buf, res.len, res.flags);
data->inject = path + res.len;
data->inject_len = dir_seglen(data->inject);
- _syscall_fs_respond(reqh, data, 0, 0);
+ _sys_fs_respond(reqh, data, 0, 0);
} else {
forward_open(reqh, buf, res.len, res.flags);
}
@@ -187,7 +187,7 @@ void fs_dir_inject(const char *path) {
if (data->delegate >= 0)
close(data->delegate);
free(data);
- _syscall_fs_respond(reqh, NULL, 0, 0);
+ _sys_fs_respond(reqh, NULL, 0, 0);
break;
case VFSOP_READ:
@@ -199,25 +199,25 @@ 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(reqh, target, dir_finish(&db), 0);
+ _sys_fs_respond(reqh, target, dir_finish(&db), 0);
break;
default:
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
exit(0);
}
-handle_t ufs_wait(char *buf, size_t len, struct ufs_request *req) {
- handle_t reqh;
+hid_t ufs_wait(char *buf, size_t len, struct ufs_request *req) {
+ hid_t reqh;
for (;;) {
- reqh = _syscall_fs_wait(buf, len, req);
+ reqh = _sys_fs_wait(buf, len, req);
if (reqh < 0) break;
if (req->op == VFSOP_OPEN) {
if (req->len == len) {
- _syscall_fs_respond(reqh, NULL, -ENAMETOOLONG, 0);
+ _sys_fs_respond(reqh, NULL, -ENAMETOOLONG, 0);
continue;
}
buf[req->len] = '\0';
diff --git a/src/user/lib/fs/whitelist.c b/src/user/lib/fs/whitelist.c
index 5612d9a..54a79c3 100644
--- a/src/user/lib/fs/whitelist.c
+++ b/src/user/lib/fs/whitelist.c
@@ -43,7 +43,7 @@ void fs_whitelist(const char **whitelist) {
if (!buf) exit(1);
for (;;) {
struct ufs_request res;
- handle_t reqh = _syscall_fs_wait(buf, buflen, &res);
+ hid_t reqh = _sys_fs_wait(buf, buflen, &res);
if (reqh < 0) break;
char *ipath = res.id; /* the path of the open()ed directory */
@@ -70,7 +70,7 @@ void fs_whitelist(const char **whitelist) {
}
}
if (error) {
- _syscall_fs_respond(reqh, NULL, -EACCES, 0);
+ _sys_fs_respond(reqh, NULL, -EACCES, 0);
} else if (passthru) {
forward_open(reqh, buf, res.len, res.flags);
} else if (inject) {
@@ -78,9 +78,9 @@ void fs_whitelist(const char **whitelist) {
ipath = malloc(res.len + 1);
memcpy(ipath, buf, res.len);
ipath[res.len] = '\0';
- _syscall_fs_respond(reqh, ipath, 0, 0);
+ _sys_fs_respond(reqh, ipath, 0, 0);
} else {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
}
break;
}
@@ -96,16 +96,16 @@ void fs_whitelist(const char **whitelist) {
if (ilen < elen && !memcmp(ipath, *entry, ilen))
dir_appendl(&db, *entry + ilen, dir_seglen2(*entry + ilen, elen - ilen));
}
- _syscall_fs_respond(reqh, target, dir_finish(&db), 0);
+ _sys_fs_respond(reqh, target, dir_finish(&db), 0);
break;
}
case VFSOP_CLOSE: {
free(ipath);
- _syscall_fs_respond(reqh, NULL, 0, 0);
+ _sys_fs_respond(reqh, NULL, 0, 0);
break;
}
default: {
- _syscall_fs_respond(reqh, NULL, -1, 0);
+ _sys_fs_respond(reqh, NULL, -1, 0);
break;
}
}
diff --git a/src/user/lib/include/camellia.h b/src/user/lib/include/camellia.h
index f9b9f00..2e4998b 100644
--- a/src/user/lib/include/camellia.h
+++ b/src/user/lib/include/camellia.h
@@ -2,4 +2,4 @@
#include <camellia/flags.h>
#include <camellia/types.h>
-handle_t camellia_open(const char *path, int flags);
+hid_t camellia_open(const char *path, int flags);
diff --git a/src/user/lib/include/camellia/fs/dir.h b/src/user/lib/include/camellia/fs/dir.h
index c3bbfe7..d34a652 100644
--- a/src/user/lib/include/camellia/fs/dir.h
+++ b/src/user/lib/include/camellia/fs/dir.h
@@ -13,5 +13,5 @@ struct dirbuild {
void dir_start(struct dirbuild *db, long offset, char *buf, size_t buflen);
bool dir_append(struct dirbuild *db, const char *name);
bool dir_appendl(struct dirbuild *db, const char *name, size_t len);
-bool dir_append_from(struct dirbuild *db, handle_t h);
+bool dir_append_from(struct dirbuild *db, hid_t h);
long dir_finish(struct dirbuild *db);
diff --git a/src/user/lib/include/camellia/fs/misc.h b/src/user/lib/include/camellia/fs/misc.h
index 35184e1..c84c5b6 100644
--- a/src/user/lib/include/camellia/fs/misc.h
+++ b/src/user/lib/include/camellia/fs/misc.h
@@ -4,7 +4,7 @@
bool fork2_n_mount(const char *path);
-void forward_open(handle_t reqh, const char *path, long len, int flags);
+void forward_open(hid_t reqh, const char *path, long len, int flags);
void fs_passthru(const char *prefix);
void fs_whitelist(const char **list);
@@ -16,8 +16,8 @@ bool mount_at_pred(const char *path);
// TODO separate fs drivers and wrappers around syscalls
-/** like _syscall_fs_wait, but ensures *buf is a null terminated string on VFSOP_OPEN */
-handle_t ufs_wait(char *buf, size_t len, struct ufs_request *req);
+/** like _sys_fs_wait, but ensures *buf is a null terminated string on VFSOP_OPEN */
+hid_t ufs_wait(char *buf, size_t len, struct ufs_request *req);
/** Mounts something and injects its path into the fs */
#define MOUNT_AT(path) for (; mount_at_pred(path); exit(1))
diff --git a/src/user/lib/include/stdio.h b/src/user/lib/include/stdio.h
index 5ee0878..a030f13 100644
--- a/src/user/lib/include/stdio.h
+++ b/src/user/lib/include/stdio.h
@@ -21,7 +21,7 @@
#define BUFSIZ 1024
/* stop fread() from trying to fill the entire buffer before returning
- * i.e. it will call _syscall_read() exactly once */
+ * i.e. it will call _sys_read() exactly once */
#define FEXT_NOFILL 1
int printf(const char *restrict fmt, ...);
diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h
index d13767b..c55cd29 100644
--- a/src/user/lib/include/unistd.h
+++ b/src/user/lib/include/unistd.h
@@ -1,9 +1,9 @@
#pragma once
-#include <camellia/types.h> // TODO only needed because of handle_t
+#include <camellia/types.h> // TODO only needed because of hid_t
#include <user/lib/vendor/getopt/getopt.h>
int fork(void);
-int close(handle_t h);
+int close(hid_t h);
_Noreturn void _exit(int);
int unlink(const char *path);
diff --git a/src/user/lib/mman.c b/src/user/lib/mman.c
index b41b8ff..32eeb2a 100644
--- a/src/user/lib/mman.c
+++ b/src/user/lib/mman.c
@@ -13,12 +13,12 @@ void *mmap(void *addr, size_t len, int prot, int flags, int fd, off_t off) {
return NULL;
}
- void *p = _syscall_memflag(addr, len, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
+ void *p = _sys_memflag(addr, len, MEMFLAG_FINDFREE | MEMFLAG_PRESENT);
if (!p) errno = ENOMEM;
return p;
}
int munmap(void *addr, size_t len) {
- _syscall_memflag(addr, len, 0);
+ _sys_memflag(addr, len, 0);
return 0;
}
diff --git a/src/user/lib/printf.c b/src/user/lib/printf.c
index a2f21d8..ad1fd06 100644
--- a/src/user/lib/printf.c
+++ b/src/user/lib/printf.c
@@ -51,6 +51,6 @@ int _klogf(const char *fmt, ...) {
va_start(argp, fmt);
ret = vsnprintf(buf, sizeof buf, fmt, argp);
va_end(argp);
- _syscall_debug_klog(buf, ret);
+ _sys_debug_klog(buf, ret);
return ret;
}
diff --git a/src/user/lib/stdio/file.c b/src/user/lib/stdio/file.c
index 531d44b..49ff861 100644
--- a/src/user/lib/stdio/file.c
+++ b/src/user/lib/stdio/file.c
@@ -18,7 +18,7 @@ FILE *const stderr = &_stderr_null;
FILE *fopen(const char *path, const char *mode) {
FILE *f;
- handle_t h;
+ hid_t h;
int flags = 0;
if (!path) {
errno = 1;
@@ -48,7 +48,7 @@ FILE *fopen(const char *path, const char *mode) {
if (h < 0) return NULL;
if (mode[0] == 'w')
- _syscall_write(h, NULL, 0, 0, WRITE_TRUNCATE);
+ _sys_write(h, NULL, 0, 0, WRITE_TRUNCATE);
f = fdopen(h, mode);
if (!f) close(h);
@@ -65,7 +65,7 @@ FILE *fopen(const char *path, const char *mode) {
if (f->fd == f2->fd) {
f2->fd = -1;
} else {
- if (_syscall_dup(f2->fd, f->fd, 0) < 0) goto fail2;
+ if (_sys_dup(f2->fd, f->fd, 0) < 0) goto fail2;
}
f->pos = f2->pos;
f->eof = f2->eof;
@@ -92,7 +92,7 @@ FILE *fdopen(int fd, const char *mode) {
}
FILE *file_clone(const FILE *f, const char *mode) {
- handle_t h = _syscall_dup(f->fd, -1, 0);
+ hid_t h = _sys_dup(f->fd, -1, 0);
FILE *f2;
if (h < 0) return NULL;
@@ -159,7 +159,7 @@ size_t fread(void *restrict ptr, size_t size, size_t nitems, FILE *restrict f) {
return 0;
while (pos < total) {
- long res = _syscall_read(f->fd, buf + pos, total - pos, f->pos);
+ long res = _sys_read(f->fd, buf + pos, total - pos, f->pos);
if (res < 0) {
f->error = true;
errno = -res;
@@ -187,7 +187,7 @@ size_t fwrite(const void *restrict ptr, size_t size, size_t nitems, FILE *restri
return 0;
while (pos < total) {
- long res = _syscall_write(f->fd, buf + pos, total - pos, f->pos, 0);
+ long res = _sys_write(f->fd, buf + pos, total - pos, f->pos, 0);
if (res < 0) {
f->error = true;
errno = -res;
@@ -253,7 +253,7 @@ int fseeko(FILE *f, off_t offset, int whence) {
base = f->pos;
break;
case SEEK_END:
- base = _syscall_getsize(f->fd);
+ base = _sys_getsize(f->fd);
if (base < 0)
base = -1;
break;
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index 4e471ba..85afb25 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -6,7 +6,7 @@
#include <user/lib/panic.h>
_Noreturn void abort(void) {
- _syscall_exit(1);
+ _sys_exit(1);
}
static const char *progname;
@@ -32,7 +32,7 @@ void setproctitle(const char *fmt, ...) {
int mkstemp(char *template) {
// TODO randomize template
- handle_t h = camellia_open(template, OPEN_CREATE | OPEN_RW);
+ hid_t h = camellia_open(template, OPEN_CREATE | OPEN_RW);
if (h < 0) {
errno = -h;
return -1;
diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c
index d42c2ee..f7eaddb 100644
--- a/src/user/lib/syscall.c
+++ b/src/user/lib/syscall.c
@@ -5,88 +5,88 @@
#include <camellia/syscalls.h>
-_Noreturn void _syscall_exit(long ret) {
- _syscall(_SYSCALL_EXIT, ret, 0, 0, 0, 0);
+_Noreturn void _sys_exit(long ret) {
+ _syscall(_SYS_EXIT, ret, 0, 0, 0, 0);
__builtin_unreachable();
}
-long _syscall_await(void) {
- return _syscall(_SYSCALL_AWAIT, 0, 0, 0, 0, 0);
+long _sys_await(void) {
+ return _syscall(_SYS_AWAIT, 0, 0, 0, 0, 0);
}
-long _syscall_fork(int flags, handle_t __user *fs_front) {
- return _syscall(_SYSCALL_FORK, (long)flags, (long)fs_front, 0, 0, 0);
+long _sys_fork(int flags, hid_t __user *fs_front) {
+ return _syscall(_SYS_FORK, (long)flags, (long)fs_front, 0, 0, 0);
}
-handle_t _syscall_open(const char __user *path, long len, int flags) {
- return (handle_t)_syscall(_SYSCALL_OPEN, (long)path, len, (long)flags, 0, 0);
+hid_t _sys_open(const char __user *path, long len, int flags) {
+ return (hid_t)_syscall(_SYS_OPEN, (long)path, len, (long)flags, 0, 0);
}
-long _syscall_mount(handle_t h, const char __user *path, long len) {
- return _syscall(_SYSCALL_MOUNT, (long)h, (long)path, len, 0, 0);
+long _sys_mount(hid_t h, const char __user *path, long len) {
+ return _syscall(_SYS_MOUNT, (long)h, (long)path, len, 0, 0);
}
-handle_t _syscall_dup(handle_t from, handle_t to, int flags) {
- return (handle_t)_syscall(_SYSCALL_DUP, (long)from, (long)to, (long)flags, 0, 0);
+hid_t _sys_dup(hid_t from, hid_t to, int flags) {
+ return (hid_t)_syscall(_SYS_DUP, (long)from, (long)to, (long)flags, 0, 0);
}
-long _syscall_read(handle_t h, void __user *buf, size_t len, long offset) {
- return _syscall(_SYSCALL_READ, (long)h, (long)buf, (long)len, offset, 0);
+long _sys_read(hid_t h, void __user *buf, size_t len, long offset) {
+ return _syscall(_SYS_READ, (long)h, (long)buf, (long)len, offset, 0);
}
-long _syscall_write(handle_t h, const void __user *buf, size_t len, long offset, int flags) {
- return _syscall(_SYSCALL_WRITE, (long)h, (long)buf, (long)len, offset, (long)flags);
+long _sys_write(hid_t h, const void __user *buf, size_t len, long offset, int flags) {
+ return _syscall(_SYS_WRITE, (long)h, (long)buf, (long)len, offset, (long)flags);
}
-long _syscall_getsize(handle_t h) {
- return _syscall(_SYSCALL_GETSIZE, (long)h, 0, 0, 0, 0);
+long _sys_getsize(hid_t h) {
+ return _syscall(_SYS_GETSIZE, (long)h, 0, 0, 0, 0);
}
-long _syscall_remove(handle_t h) {
- return _syscall(_SYSCALL_REMOVE, (long)h, 0, 0, 0, 0);
+long _sys_remove(hid_t h) {
+ return _syscall(_SYS_REMOVE, (long)h, 0, 0, 0, 0);
}
-long _syscall_close(handle_t h) {
- return _syscall(_SYSCALL_CLOSE, (long)h, 0, 0, 0, 0);
+long _sys_close(hid_t h) {
+ return _syscall(_SYS_CLOSE, (long)h, 0, 0, 0, 0);
}
-handle_t _syscall_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res) {
- return (handle_t)_syscall(_SYSCALL_FS_WAIT, (long)buf, max_len, (long)res, 0, 0);
+hid_t _sys_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res) {
+ return (hid_t)_syscall(_SYS_FS_WAIT, (long)buf, max_len, (long)res, 0, 0);
}
-long _syscall_fs_respond(handle_t hid, const void __user *buf, long ret, int flags) {
- return _syscall(_SYSCALL_FS_RESPOND, (long)hid, (long)buf, ret, (long)flags, 0);
+long _sys_fs_respond(hid_t hid, const void __user *buf, long ret, int flags) {
+ return _syscall(_SYS_FS_RESPOND, (long)hid, (long)buf, ret, (long)flags, 0);
}
-void __user *_syscall_memflag(void __user *addr, size_t len, int flags) {
- return (void __user *)_syscall(_SYSCALL_MEMFLAG, (long)addr, (long)len, (long)flags, 0, 0);
+void __user *_sys_memflag(void __user *addr, size_t len, int flags) {
+ return (void __user *)_syscall(_SYS_MEMFLAG, (long)addr, (long)len, (long)flags, 0, 0);
}
-long _syscall_pipe(handle_t __user user_ends[2], int flags) {
- return _syscall(_SYSCALL_PIPE, (long)user_ends, (long)flags, 0, 0, 0);
+long _sys_pipe(hid_t __user user_ends[2], int flags) {
+ return _syscall(_SYS_PIPE, (long)user_ends, (long)flags, 0, 0, 0);
}
-void _syscall_sleep(long ms) {
- return (void)_syscall(_SYSCALL_SLEEP, ms, 0, 0, 0, 0);
+void _sys_sleep(long ms) {
+ return (void)_syscall(_SYS_SLEEP, ms, 0, 0, 0, 0);
}
-void _syscall_filicide(void) {
- return (void)_syscall(_SYSCALL_FILICIDE, 0, 0, 0, 0, 0);
+void _sys_filicide(void) {
+ return (void)_syscall(_SYS_FILICIDE, 0, 0, 0, 0, 0);
}
-void _syscall_intr(void) {
- return (void)_syscall(_SYSCALL_INTR, 0, 0, 0, 0, 0);
+void _sys_intr(void) {
+ return (void)_syscall(_SYS_INTR, 0, 0, 0, 0, 0);
}
-void _syscall_intr_set(void __user *ip) {
- return (void)_syscall(_SYSCALL_INTR_SET, (long)ip, 0, 0, 0, 0);
+void _sys_intr_set(void __user *ip) {
+ return (void)_syscall(_SYS_INTR_SET, (long)ip, 0, 0, 0, 0);
}
-long _syscall_execbuf(void __user *buf, size_t len) {
- return _syscall(_SYSCALL_EXECBUF, (long)buf, (long)len, 0, 0, 0);
+long _sys_execbuf(void __user *buf, size_t len) {
+ return _syscall(_SYS_EXECBUF, (long)buf, (long)len, 0, 0, 0);
}
-void _syscall_debug_klog(const void __user *buf, size_t len) {
- return (void)_syscall(_SYSCALL_DEBUG_KLOG, (long)buf, (long)len, 0, 0, 0);
+void _sys_debug_klog(const void __user *buf, size_t len) {
+ return (void)_syscall(_SYS_DEBUG_KLOG, (long)buf, (long)len, 0, 0, 0);
}
diff --git a/src/user/lib/syscall.c.awk b/src/user/lib/syscall.c.awk
index 192df6a..591a6f0 100644
--- a/src/user/lib/syscall.c.awk
+++ b/src/user/lib/syscall.c.awk
@@ -14,7 +14,7 @@ BEGIN {
sub(/;/, " {");
print $0;
- name = substr($0, match($0, /_syscall_[^(]+/), RLENGTH);
+ name = substr($0, match($0, /_sys_[^(]+/), RLENGTH);
rets = substr($0, 0, RSTART - 1);
sub(/ *$/, "", rets)
diff --git a/src/user/lib/thread.S b/src/user/lib/thread.S
index 1a27c30..2900544 100644
--- a/src/user/lib/thread.S
+++ b/src/user/lib/thread.S
@@ -18,7 +18,7 @@ thread_creates:
mov %rdi, %rsi
or $(FORK_SHAREMEM | FORK_SHAREHANDLE), %rsi
- mov $_SYSCALL_FORK, %rdi
+ mov $_SYS_FORK, %rdi
xor %rdx, %rdx
syscall
@@ -34,7 +34,7 @@ thread_creates:
mov %r13, %rdi
call *%r12
- mov $_SYSCALL_EXIT, %rdi
+ mov $_SYS_EXIT, %rdi
xor %rsi, %rsi
syscall
hlt /* if all else fails... */
diff --git a/src/user/lib/unistd.c b/src/user/lib/unistd.c
index cb862f8..f8edd25 100644
--- a/src/user/lib/unistd.c
+++ b/src/user/lib/unistd.c
@@ -11,22 +11,22 @@
int errno = 0;
int fork(void) {
- return _syscall_fork(0, NULL);
+ return _sys_fork(0, NULL);
}
-int close(handle_t h) {
- return _syscall_close(h);
+int close(hid_t h) {
+ return _sys_close(h);
}
_Noreturn void exit(int c) {
- _syscall_exit(c);
+ _sys_exit(c);
}
_Noreturn void _exit(int c) { exit(c); };
int unlink(const char *path) {
- handle_t h = camellia_open(path, OPEN_WRITE);
+ hid_t h = camellia_open(path, OPEN_WRITE);
if (h < 0) return errno = -h, -1;
- long ret = _syscall_remove(h);
+ long ret = _sys_remove(h);
if (ret < 0) return errno = -ret, -1;
return 0;
}
@@ -79,7 +79,7 @@ static const char *getrealcwd(void) {
}
int chdir(const char *path) {
- handle_t h;
+ hid_t h;
char *tmp;
size_t len = absolutepath(NULL, path, 0) + 1; /* +1 for the trailing slash */
if (cwdcapacity < len) {