summaryrefslogtreecommitdiff
path: root/src/user/lib
diff options
context:
space:
mode:
authordzwdz2023-01-25 20:16:22 +0100
committerdzwdz2023-01-25 20:16:22 +0100
commit17bfb0ef0a48330b1d54e61fe3c30d83528d2d90 (patch)
treeb3d4aed1f408edcb17fe5c86fccaeacaa2a5a48a /src/user/lib
parent2ad6ee8ed15d1bf898645a16dbc06991a3c1425e (diff)
style: typedef structs, shorter namespaces
I've wanted to do this for a while, and since I've just had a relatively large refactor commit (pcpy), this is as good of a time as any. Typedefing structs was mostly inspired by Plan 9's coding style. It makes some lines of code much shorter at basically no expense. Everything related to userland kept old-style struct definitions, so as not to force that style onto other people. I also considered changing SCREAMING_ENUM_FIELDS to NicerLookingCamelcase, but I didn't, just in case that'd be confusing.
Diffstat (limited to 'src/user/lib')
-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
27 files changed, 136 insertions, 136 deletions
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) {