summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/kernel/arch/amd64/boot.c6
-rw-r--r--src/kernel/arch/amd64/driver/fsroot.c4
-rw-r--r--src/kernel/arch/amd64/driver/pata.c4
-rw-r--r--src/kernel/arch/amd64/driver/ps2.c8
-rw-r--r--src/kernel/arch/amd64/driver/rtl8139.c10
-rw-r--r--src/kernel/arch/amd64/driver/serial.c6
-rw-r--r--src/kernel/arch/amd64/driver/util.c12
-rw-r--r--src/kernel/arch/amd64/driver/util.h10
-rw-r--r--src/kernel/arch/amd64/driver/video.c8
-rw-r--r--src/kernel/arch/amd64/driver/video.h4
-rw-r--r--src/kernel/arch/amd64/interrupts/isr.c4
-rw-r--r--src/kernel/arch/amd64/pagedir.c22
-rw-r--r--src/kernel/arch/amd64/paging.h2
-rw-r--r--src/kernel/arch/amd64/registers.h6
-rw-r--r--src/kernel/arch/amd64/sysenter.c8
-rw-r--r--src/kernel/arch/amd64/sysenter.h3
-rw-r--r--src/kernel/arch/amd64/time.c16
-rw-r--r--src/kernel/arch/generic.h27
-rw-r--r--src/kernel/execbuf.c12
-rw-r--r--src/kernel/execbuf.h2
-rw-r--r--src/kernel/handle.c8
-rw-r--r--src/kernel/handle.h19
-rw-r--r--src/kernel/mem/virt.c22
-rw-r--r--src/kernel/mem/virt.h12
-rw-r--r--src/kernel/pipe.c22
-rw-r--r--src/kernel/pipe.h4
-rwxr-xr-xsrc/kernel/proc.c184
-rw-r--r--src/kernel/proc.h72
-rw-r--r--src/kernel/ring.c2
-rw-r--r--src/kernel/ring.h4
-rw-r--r--src/kernel/syscalls.c226
-rw-r--r--src/kernel/types.h17
-rw-r--r--src/kernel/vfs/mount.c22
-rw-r--r--src/kernel/vfs/mount.h21
-rw-r--r--src/kernel/vfs/procfs.c38
-rw-r--r--src/kernel/vfs/procfs.h2
-rw-r--r--src/kernel/vfs/request.c46
-rw-r--r--src/kernel/vfs/request.h48
-rw-r--r--src/shared/include/camellia/syscalls.h86
-rw-r--r--src/shared/include/camellia/types.h6
-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
101 files changed, 972 insertions, 959 deletions
diff --git a/src/kernel/arch/amd64/boot.c b/src/kernel/arch/amd64/boot.c
index ed19b79..d78d4f6 100644
--- a/src/kernel/arch/amd64/boot.c
+++ b/src/kernel/arch/amd64/boot.c
@@ -28,7 +28,7 @@ static void *mbi_tag(void *mbi, uint32_t type) {
}
void kmain_early(void *mbi) {
- struct fb_info vid;
+ GfxInfo vid;
struct {
void *addr; size_t len;
} init;
@@ -78,8 +78,8 @@ void kmain_early(void *mbi) {
pci_init();
kprintf("running init...\n");
- process_seed(init.addr, init.len);
- process_switch_any();
+ proc_seed(init.addr, init.len);
+ proc_switch_any();
}
void shutdown(void) {
diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c
index 6217e29..6d3676d 100644
--- a/src/kernel/arch/amd64/driver/fsroot.c
+++ b/src/kernel/arch/amd64/driver/fsroot.c
@@ -8,7 +8,7 @@
#include <kernel/vfs/request.h>
#include <shared/mem.h>
-static int handle(struct vfs_request *req) {
+static int handle(VfsReq *req) {
// TODO document directory read format
// TODO don't hardcode
const char dir[] =
@@ -31,7 +31,7 @@ static int handle(struct vfs_request *req) {
}
}
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
vfsreq_finish_short(req, handle(req));
}
diff --git a/src/kernel/arch/amd64/driver/pata.c b/src/kernel/arch/amd64/driver/pata.c
index 6928b4e..b0ed592 100644
--- a/src/kernel/arch/amd64/driver/pata.c
+++ b/src/kernel/arch/amd64/driver/pata.c
@@ -11,13 +11,13 @@
static const int root_id = 100;
-static void accept(struct vfs_request *req);
+static void accept(VfsReq *req);
void pata_init(void) {
ata_init();
vfs_root_register("/ata", accept);
}
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
int ret;
long id = (long __force)req->id;
char wbuf[4096];
diff --git a/src/kernel/arch/amd64/driver/ps2.c b/src/kernel/arch/amd64/driver/ps2.c
index d0629e6..cdcbf19 100644
--- a/src/kernel/arch/amd64/driver/ps2.c
+++ b/src/kernel/arch/amd64/driver/ps2.c
@@ -17,10 +17,10 @@ static volatile ring_t kb_backlog = {(void*)kb_buf, sizeof kb_buf, 0, 0};
static volatile uint8_t mouse_buf[64];
static volatile ring_t mouse_backlog = {(void*)mouse_buf, sizeof mouse_buf, 0, 0};
-static void accept(struct vfs_request *req);
+static void accept(VfsReq *req);
-static struct vfs_request *kb_queue = NULL;
-static struct vfs_request *mouse_queue = NULL;
+static VfsReq *kb_queue = NULL;
+static VfsReq *mouse_queue = NULL;
static void wait_out(void) {
while ((port_in8(PS2 + 4) & 2) != 0);
@@ -77,7 +77,7 @@ enum {
H_MOUSE,
};
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
// when you fix something here go also fix it in the COM1 driver
int ret;
switch (req->type) {
diff --git a/src/kernel/arch/amd64/driver/rtl8139.c b/src/kernel/arch/amd64/driver/rtl8139.c
index 1face38..dd11102 100644
--- a/src/kernel/arch/amd64/driver/rtl8139.c
+++ b/src/kernel/arch/amd64/driver/rtl8139.c
@@ -10,8 +10,8 @@
#define WAIT -1000
-static void accept(struct vfs_request *req);
-static struct vfs_request *blocked_on = NULL;
+static void accept(VfsReq *req);
+static VfsReq *blocked_on = NULL;
enum {
@@ -105,7 +105,7 @@ void rtl8139_irq(void) {
port_out16(iobase + INTRSTATUS, status);
}
-static int try_rx(struct process *proc, void __user *dest, size_t dlen) {
+static int try_rx(Proc *proc, void __user *dest, size_t dlen) {
uint16_t flags, size;
/* bit 0 - Rx Buffer Empty */
if (port_in8(iobase + CMD) & 1) return WAIT;
@@ -140,7 +140,7 @@ static int try_rx(struct process *proc, void __user *dest, size_t dlen) {
return size;
}
-static int try_tx(struct process *proc, const void __user *src, size_t slen) {
+static int try_tx(Proc *proc, const void __user *src, size_t slen) {
static uint8_t desc = 0;
if (slen > 0xFFF) return -1;
@@ -164,7 +164,7 @@ static int try_tx(struct process *proc, const void __user *src, size_t slen) {
return slen;
}
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
if (!req->caller) {
vfsreq_finish_short(req, -1);
return;
diff --git a/src/kernel/arch/amd64/driver/serial.c b/src/kernel/arch/amd64/driver/serial.c
index 12c4151..6fe4500 100644
--- a/src/kernel/arch/amd64/driver/serial.c
+++ b/src/kernel/arch/amd64/driver/serial.c
@@ -14,8 +14,8 @@ static volatile ring_t backlog = {(void*)backlog_buf, sizeof backlog_buf, 0, 0};
static const int COM1 = 0x3f8;
-static void accept(struct vfs_request *req);
-static struct vfs_request *hung_reads = NULL;
+static void accept(VfsReq *req);
+static VfsReq *hung_reads = NULL;
void serial_init(void) { vfs_root_register("/com1", accept); }
@@ -59,7 +59,7 @@ void serial_write(const char *buf, size_t len) {
serial_putchar(buf[i]);
}
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
int ret;
bool valid;
switch (req->type) {
diff --git a/src/kernel/arch/amd64/driver/util.c b/src/kernel/arch/amd64/driver/util.c
index b2c33c6..957005c 100644
--- a/src/kernel/arch/amd64/driver/util.c
+++ b/src/kernel/arch/amd64/driver/util.c
@@ -5,7 +5,7 @@
#include <kernel/proc.h>
#include <kernel/vfs/request.h>
-int req_readcopy(struct vfs_request *req, const void *buf, size_t len) {
+int req_readcopy(VfsReq *req, const void *buf, size_t len) {
if (!req->caller) return -1;
assert(req->type == VFSOP_READ);
fs_normslice(&req->offset, &req->output.len, len, false);
@@ -14,7 +14,7 @@ int req_readcopy(struct vfs_request *req, const void *buf, size_t len) {
return req->output.len;
}
-void postqueue_join(struct vfs_request **queue, struct vfs_request *req) {
+void postqueue_join(VfsReq **queue, VfsReq *req) {
if (req->postqueue_next)
panic_invalid_state();
@@ -23,16 +23,16 @@ void postqueue_join(struct vfs_request **queue, struct vfs_request *req) {
*queue = req;
}
-bool postqueue_pop(struct vfs_request **queue, void (*accept)(struct vfs_request *)) {
- struct vfs_request *req = *queue;
+bool postqueue_pop(VfsReq **queue, void (*accept)(VfsReq *)) {
+ VfsReq *req = *queue;
if (req == NULL) return false;
*queue = req->postqueue_next;
accept(req);
return true;
}
-void postqueue_ringreadall(struct vfs_request **queue, ring_t *r) {
- struct vfs_request *req;
+void postqueue_ringreadall(VfsReq **queue, ring_t *r) {
+ VfsReq *req;
char tmp[64];
size_t mlen = 0;
if (ring_used(r) == 0) return;
diff --git a/src/kernel/arch/amd64/driver/util.h b/src/kernel/arch/amd64/driver/util.h
index 06ca672..5827fa9 100644
--- a/src/kernel/arch/amd64/driver/util.h
+++ b/src/kernel/arch/amd64/driver/util.h
@@ -1,10 +1,10 @@
#pragma once
+#include <kernel/types.h>
#include <shared/container/ring.h>
#include <stdbool.h>
#include <stddef.h>
-struct vfs_request;
-int req_readcopy(struct vfs_request *req, const void *buf, size_t len);
+int req_readcopy(VfsReq *req, const void *buf, size_t len);
/* compare request path. path MUST be a static string */
#define reqpathcmp(req, path) _reqpathcmp(req, ""path"", sizeof(path) - 1)
@@ -13,9 +13,9 @@ int req_readcopy(struct vfs_request *req, const void *buf, size_t len);
req->input.len == plen && \
memcmp(req->input.buf_kern, path, plen) == 0)
-void postqueue_join(struct vfs_request **queue, struct vfs_request *req);
-bool postqueue_pop(struct vfs_request **queue, void (*accept)(struct vfs_request *));
+void postqueue_join(VfsReq **queue, VfsReq *req);
+bool postqueue_pop(VfsReq **queue, void (*accept)(VfsReq *));
/** If there are any pending read requests, and the ring buffer isn't empty, fulfill them
* all with a single read. */
-void postqueue_ringreadall(struct vfs_request **queue, ring_t *r);
+void postqueue_ringreadall(VfsReq **queue, ring_t *r);
diff --git a/src/kernel/arch/amd64/driver/video.c b/src/kernel/arch/amd64/driver/video.c
index 4cd6b0b..d7046b4 100644
--- a/src/kernel/arch/amd64/driver/video.c
+++ b/src/kernel/arch/amd64/driver/video.c
@@ -9,7 +9,7 @@
#include <shared/mem.h>
#include <shared/printf.h>
-static struct fb_info fb;
+static GfxInfo fb;
static char namebuf[64];
static size_t namelen;
@@ -18,7 +18,7 @@ enum {
H_FB,
};
-static int handle(struct vfs_request *req) {
+static int handle(VfsReq *req) {
switch (req->type) {
case VFSOP_OPEN:
if (!req->input.kern) panic_invalid_state();
@@ -54,7 +54,7 @@ static int handle(struct vfs_request *req) {
}
}
-static void accept(struct vfs_request *req) {
+static void accept(VfsReq *req) {
if (req->caller) {
vfsreq_finish_short(req, handle(req));
} else {
@@ -62,7 +62,7 @@ static void accept(struct vfs_request *req) {
}
}
-void video_init(struct fb_info fb_) {
+void video_init(GfxInfo fb_) {
fb = fb_;
snprintf(namebuf, sizeof namebuf, "%ux%ux%u", fb.width, fb.height, fb.bpp);
namelen = strlen(namebuf);
diff --git a/src/kernel/arch/amd64/driver/video.h b/src/kernel/arch/amd64/driver/video.h
index dfc1710..e9dd8ae 100644
--- a/src/kernel/arch/amd64/driver/video.h
+++ b/src/kernel/arch/amd64/driver/video.h
@@ -1,7 +1,7 @@
#pragma once
#include <stdint.h>
-struct fb_info {
+struct GfxInfo {
char *b;
uint32_t width, height;
uint32_t pitch; /* width in bytes of a single scanline */
@@ -9,4 +9,4 @@ struct fb_info {
uint8_t bpp;
};
-void video_init(struct fb_info);
+void video_init(GfxInfo);
diff --git a/src/kernel/arch/amd64/interrupts/isr.c b/src/kernel/arch/amd64/interrupts/isr.c
index 994519d..1059530 100644
--- a/src/kernel/arch/amd64/interrupts/isr.c
+++ b/src/kernel/arch/amd64/interrupts/isr.c
@@ -62,8 +62,8 @@ void isr_stage3(int interrupt, uint64_t *stackframe) {
log_interrupt(interrupt, stackframe);
cpu_halt();
} else {
- process_kill(process_current, interrupt);
- process_switch_any();
+ proc_kill(proc_cur, interrupt);
+ proc_switch_any();
}
}
}
diff --git a/src/kernel/arch/amd64/pagedir.c b/src/kernel/arch/amd64/pagedir.c
index 4189774..9250a01 100644
--- a/src/kernel/arch/amd64/pagedir.c
+++ b/src/kernel/arch/amd64/pagedir.c
@@ -31,11 +31,11 @@ static __user void *addr_canonize(const __user void *addr) {
}
-struct pagedir *pagedir_new(void) {
+Pagedir *pagedir_new(void) {
return page_zalloc(1);
}
-void pagedir_free(struct pagedir *dir) {
+void pagedir_free(Pagedir *dir) {
for (int i = 0; i < 512; i++) {
if (!dir->e[i].present) continue;
assert(!dir->e[i].large);
@@ -66,7 +66,7 @@ void pagedir_free(struct pagedir *dir) {
}
static pe_generic_t*
-get_entry(struct pagedir *dir, const void __user *virt) {
+get_entry(Pagedir *dir, const void __user *virt) {
pe_generic_t *pml4e, *pdpte, *pde, *pte;
const union virt_addr v = {.full = (void __user *)virt};
@@ -88,7 +88,7 @@ get_entry(struct pagedir *dir, const void __user *virt) {
return pte;
}
-void pagedir_unmap_user(struct pagedir *dir, void __user *virt, size_t len) {
+void pagedir_unmap_user(Pagedir *dir, void __user *virt, size_t len) {
// TODO rewrite this
const void __user *end = addr_canonize(virt + len);
union virt_addr v = {.full = virt};
@@ -144,7 +144,7 @@ void pagedir_unmap_user(struct pagedir *dir, void __user *virt, size_t len) {
}
}
-void pagedir_map(struct pagedir *dir, void __user *virt, void *phys,
+void pagedir_map(Pagedir *dir, void __user *virt, void *phys,
bool user, bool writeable)
{
pe_generic_t *pml4e, *pdpte, *pde, *pte;
@@ -191,13 +191,13 @@ void pagedir_map(struct pagedir *dir, void __user *virt, void *phys,
}
extern void *pagedir_current;
-void pagedir_switch(struct pagedir *dir) {
+void pagedir_switch(Pagedir *dir) {
pagedir_current = dir;
}
// creates a new pagedir with exact copies of the user pages
-struct pagedir *pagedir_copy(const struct pagedir *pml4_old) {
- struct pagedir *pml4_new = page_zalloc(1);
+Pagedir *pagedir_copy(const Pagedir *pml4_old) {
+ Pagedir *pml4_new = page_zalloc(1);
for (int i = 0; i < 512; i++) {
if (!pml4_old->e[i].present) continue;
@@ -239,12 +239,12 @@ struct pagedir *pagedir_copy(const struct pagedir *pml4_old) {
return pml4_new;
}
-bool pagedir_iskern(struct pagedir *dir, const void __user *virt) {
+bool pagedir_iskern(Pagedir *dir, const void __user *virt) {
pe_generic_t *page = get_entry(dir, virt);
return page && page->present && !page->user;
}
-void *pagedir_virt2phys(struct pagedir *dir, const void __user *virt,
+void *pagedir_virt2phys(Pagedir *dir, const void __user *virt,
bool user, bool writeable)
{
pe_generic_t *page = get_entry(dir, virt);
@@ -255,7 +255,7 @@ void *pagedir_virt2phys(struct pagedir *dir, const void __user *virt,
return addr_extract(*page) + ((uintptr_t)virt & PAGE_MASK);
}
-void __user *pagedir_findfree(struct pagedir *dir, char __user *start, size_t len) {
+void __user *pagedir_findfree(Pagedir *dir, char __user *start, size_t len) {
// TODO dogshit slow
pe_generic_t *page;
char __user *iter;
diff --git a/src/kernel/arch/amd64/paging.h b/src/kernel/arch/amd64/paging.h
index 156c0c5..70752b0 100644
--- a/src/kernel/arch/amd64/paging.h
+++ b/src/kernel/arch/amd64/paging.h
@@ -31,7 +31,7 @@ typedef union pe_generic_t {
void *as_ptr;
} pe_generic_t; // pageentry_generic
-struct pagedir { /* on amd64 actually points to pml4. the name is like this for historical reasons */
+struct Pagedir { /* on amd64 actually points to pml4 */
pe_generic_t e[512];
} __attribute__((packed));
diff --git a/src/kernel/arch/amd64/registers.h b/src/kernel/arch/amd64/registers.h
index b8f6248..5fd09c9 100644
--- a/src/kernel/arch/amd64/registers.h
+++ b/src/kernel/arch/amd64/registers.h
@@ -1,9 +1,9 @@
#pragma once
-#include <camellia/types.h>
+#include <kernel/types.h>
#include <stdint.h>
/* requires 16-byte alignment */
-struct registers {
+struct CpuRegs {
uint64_t r15, r14, r13, r12, r11, r10, r9, r8;
uint64_t rdi, rsi;
userptr_t rbp, rsp;
@@ -12,7 +12,7 @@ struct registers {
} __attribute__((__packed__));
// saves a return value according to the SysV ABI
-static inline uint64_t regs_savereturn(struct registers *regs, uint64_t value) {
+static inline uint64_t regs_savereturn(CpuRegs *regs, uint64_t value) {
regs->rax = value;
return value;
}
diff --git a/src/kernel/arch/amd64/sysenter.c b/src/kernel/arch/amd64/sysenter.c
index 459247f..5a96e33 100644
--- a/src/kernel/arch/amd64/sysenter.c
+++ b/src/kernel/arch/amd64/sysenter.c
@@ -3,16 +3,16 @@
#include <kernel/arch/generic.h>
#include <kernel/proc.h>
-struct registers _sysexit_regs;
+CpuRegs _sysexit_regs;
-_Noreturn void sysexit(struct registers regs) {
+_Noreturn void sysexit(CpuRegs regs) {
_sysexit_regs = regs;
_sysexit_real();
}
_Noreturn void sysenter_stage2(void) {
- struct registers *regs = &process_current->regs;
+ CpuRegs *regs = &proc_cur->regs;
*regs = _sysexit_regs;
_syscall(regs->rdi, regs->rsi, regs->rdx, regs->r10, regs->r8, regs->r9);
- process_switch_any();
+ proc_switch_any();
}
diff --git a/src/kernel/arch/amd64/sysenter.h b/src/kernel/arch/amd64/sysenter.h
index d1274de..03a9f45 100644
--- a/src/kernel/arch/amd64/sysenter.h
+++ b/src/kernel/arch/amd64/sysenter.h
@@ -1,7 +1,8 @@
#pragma once
+#include <kernel/types.h>
// sysenter.c
-extern struct registers _sysexit_regs;
+extern CpuRegs _sysexit_regs;
_Noreturn void sysenter_stage2(void);
// sysenter.s
diff --git a/src/kernel/arch/amd64/time.c b/src/kernel/arch/amd64/time.c
index d6e53dd..0e40521 100644
--- a/src/kernel/arch/amd64/time.c
+++ b/src/kernel/arch/amd64/time.c
@@ -3,7 +3,7 @@
#include <kernel/proc.h>
static uint64_t uptime = 0, goal = ~0;
-static struct process *scheduled = NULL;
+static Proc *scheduled = NULL;
uint64_t uptime_ms(void) { return uptime; }
@@ -16,18 +16,18 @@ void pit_irq(void) {
uptime++;
if (uptime < goal) return;
- struct process *p = scheduled;
+ Proc *p = scheduled;
assert(p);
scheduled = p->waits4timer.next;
- process_transition(p, PS_RUNNING);
+ proc_setstate(p, PS_RUNNING);
update_goal();
}
-void timer_schedule(struct process *p, uint64_t time) {
- process_transition(p, PS_WAITS4TIMER);
+void timer_schedule(Proc *p, uint64_t time) {
+ proc_setstate(p, PS_WAITS4TIMER);
p->waits4timer.goal = time;
- struct process **slot = &scheduled;
+ Proc **slot = &scheduled;
while (*slot && (*slot)->waits4timer.goal <= time) {
assert((*slot)->state == PS_WAITS4TIMER);
slot = &(*slot)->waits4timer.next;
@@ -37,10 +37,10 @@ void timer_schedule(struct process *p, uint64_t time) {
update_goal();
}
-void timer_deschedule(struct process *p) {
+void timer_deschedule(Proc *p) {
assert(p->state == PS_WAITS4TIMER);
- struct process **slot = &scheduled;
+ Proc **slot = &scheduled;
while (*slot && *slot != p)
slot = &(*slot)->waits4timer.next;
assert(*slot);
diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h
index 0cf4d50..647badc 100644
--- a/src/kernel/arch/generic.h
+++ b/src/kernel/arch/generic.h
@@ -1,10 +1,9 @@
#pragma once
-#include <camellia/types.h>
#include <kernel/arch/amd64/registers.h>
+#include <kernel/types.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
-struct process;
// i have no idea where else to put it
// some code assumes that it's a power of 2
@@ -25,28 +24,28 @@ void shutdown(void);
void cpu_pause(void);
uint64_t uptime_ms(void);
-void timer_schedule(struct process *p, uint64_t time);
-void timer_deschedule(struct process *p);
+void timer_schedule(Proc *p, uint64_t time);
+void timer_deschedule(Proc *p);
// src/arch/i386/sysenter.s
-_Noreturn void sysexit(struct registers);
+_Noreturn void sysexit(CpuRegs);
// all of those can allocate memory
-struct pagedir *pagedir_new(void);
-struct pagedir *pagedir_copy(const struct pagedir *orig);
+Pagedir *pagedir_new(void);
+Pagedir *pagedir_copy(const Pagedir *orig);
-void pagedir_free(struct pagedir *);
-void pagedir_unmap_user(struct pagedir *dir, void __user *virt, size_t len);
-void pagedir_map(struct pagedir *dir, void __user *virt, void *phys,
+void pagedir_free(Pagedir *);
+void pagedir_unmap_user(Pagedir *dir, void __user *virt, size_t len);
+void pagedir_map(Pagedir *dir, void __user *virt, void *phys,
bool user, bool writeable);
-bool pagedir_iskern(struct pagedir *, const void __user *virt);
+bool pagedir_iskern(Pagedir *, const void __user *virt);
-void __user *pagedir_findfree(struct pagedir *dir, char __user *start, size_t len);
+void __user *pagedir_findfree(Pagedir *dir, char __user *start, size_t len);
-void pagedir_switch(struct pagedir *);
+void pagedir_switch(Pagedir *);
// return 0 on failure
-void *pagedir_virt2phys(struct pagedir *dir, const void __user *virt,
+void *pagedir_virt2phys(Pagedir *dir, const void __user *virt,
bool user, bool writeable);
int kprintf(const char *fmt, ...);
diff --git a/src/kernel/execbuf.c b/src/kernel/execbuf.c
index 7170de2..8f7e22e 100644
--- a/src/kernel/execbuf.c
+++ b/src/kernel/execbuf.c
@@ -5,13 +5,13 @@
#include <kernel/panic.h>
#include <shared/mem.h>
-_Noreturn static void halt(struct process *proc) {
+_Noreturn static void halt(Proc *proc) {
kfree(proc->execbuf.buf);
proc->execbuf.buf = NULL;
- process_switch_any();
+ proc_switch_any();
}
-static void try_fetch(struct process *proc, uint64_t *buf, size_t amt) {
+static void try_fetch(Proc *proc, uint64_t *buf, size_t amt) {
size_t bytes = amt * sizeof(uint64_t);
if (proc->execbuf.pos + bytes > proc->execbuf.len)
halt(proc);
@@ -19,10 +19,10 @@ static void try_fetch(struct process *proc, uint64_t *buf, size_t amt) {
proc->execbuf.pos += bytes;
}
-_Noreturn void execbuf_run(struct process *proc) {
+_Noreturn void execbuf_run(Proc *proc) {
uint64_t buf[6];
- assert(proc == process_current); // idiotic, but needed because of _syscall.
+ assert(proc == proc_cur); // idiotic, but needed because of _syscall.
assert(proc->state == PS_RUNNING);
assert(proc->execbuf.buf);
@@ -31,7 +31,7 @@ _Noreturn void execbuf_run(struct process *proc) {
case EXECBUF_SYSCALL:
try_fetch(proc, buf, 6);
_syscall(buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
- process_switch_any();
+ proc_switch_any();
case EXECBUF_JMP:
try_fetch(proc, buf, 1);
diff --git a/src/kernel/execbuf.h b/src/kernel/execbuf.h
index 02ada92..e28cb76 100644
--- a/src/kernel/execbuf.h
+++ b/src/kernel/execbuf.h
@@ -1,4 +1,4 @@
#pragma once
#include <kernel/proc.h>
-_Noreturn void execbuf_run(struct process *proc);
+_Noreturn void execbuf_run(Proc *proc);
diff --git a/src/kernel/handle.c b/src/kernel/handle.c
index fabe559..156be12 100644
--- a/src/kernel/handle.c
+++ b/src/kernel/handle.c
@@ -6,20 +6,20 @@
#include <kernel/vfs/request.h>
#include <shared/mem.h>
-struct handle *handle_init(enum handle_type type) {
- struct handle *h = kzalloc(sizeof *h);
+Handle *handle_init(enum handle_type type) {
+ Handle *h = kzalloc(sizeof *h);
h->type = type;
h->refcount = 1;
return h;
}
-void handle_close(struct handle *h) {
+void handle_close(Handle *h) {
if (!h) return;
assert(h->refcount > 0);
if (--(h->refcount) > 0) return;
if (h->type == HANDLE_FILE) {
- vfsreq_create((struct vfs_request) {
+ vfsreq_create((VfsReq) {
.type = VFSOP_CLOSE,
.id = h->file_id,
.caller = NULL,
diff --git a/src/kernel/handle.h b/src/kernel/handle.h
index 19d5953..21b4364 100644
--- a/src/kernel/handle.h
+++ b/src/kernel/handle.h
@@ -1,8 +1,5 @@
#pragma once
-
-enum handle_type; // forward declaration for proc.h
-
-#include <camellia/types.h>
+#include <kernel/types.h>
#include <kernel/vfs/mount.h>
#include <kernel/vfs/request.h>
#include <stddef.h>
@@ -15,19 +12,19 @@ enum handle_type {
HANDLE_FS_REQ,
};
-struct handle {
+struct Handle {
enum handle_type type;
- struct vfs_backend *backend; // HANDLE_FILE | HANDLE_FS_FRONT
+ VfsBackend *backend; // HANDLE_FILE | HANDLE_FS_FRONT
void __user *file_id; // only applicable to HANDLE_FILE
bool readable, writeable; /* HANDLE_FILE | HANDLE_PIPE */
- struct vfs_request *req; /* HANDLE_FS_REQ */
+ VfsReq *req; /* HANDLE_FS_REQ */
struct {
- struct process *queued;
- struct handle *sister; // the other end, not included in refcount
+ Proc *queued;
+ Handle *sister; // the other end, not included in refcount
} pipe;
size_t refcount;
};
-struct handle *handle_init(enum handle_type);
-void handle_close(struct handle *);
+Handle *handle_init(enum handle_type);
+void handle_close(Handle *);
diff --git a/src/kernel/mem/virt.c b/src/kernel/mem/virt.c
index 8bf5e69..1ac6fbc 100644
--- a/src/kernel/mem/virt.c
+++ b/src/kernel/mem/virt.c
@@ -18,7 +18,7 @@ struct virt_iter {
void __user *_virt;
size_t _remaining;
- struct pagedir *_pages;
+ Pagedir *_pages;
bool _user;
bool _writeable;
};
@@ -30,12 +30,12 @@ struct virt_cpy_error { // unused
/* if pages == NULL, creates an iterator over physical memory. */
static void virt_iter_new(
struct virt_iter *iter, void __user *virt, size_t length,
- struct pagedir *pages, bool user, bool writeable
+ Pagedir *pages, bool user, bool writeable
);
static bool virt_iter_next(struct virt_iter *);
static size_t virt_cpy(
- struct pagedir *dest_pages, void __user *dest,
- struct pagedir *src_pages, const void __user *src,
+ Pagedir *dest_pages, void __user *dest,
+ Pagedir *src_pages, const void __user *src,
size_t length, struct virt_cpy_error *err
);
@@ -43,7 +43,7 @@ static size_t virt_cpy(
static void
virt_iter_new(
struct virt_iter *iter, void __user *virt, size_t length,
- struct pagedir *pages, bool user, bool writeable
+ Pagedir *pages, bool user, bool writeable
) {
iter->frag = NULL;
iter->frag_len = 0;
@@ -94,8 +94,8 @@ virt_iter_next(struct virt_iter *iter)
static size_t
virt_cpy(
- struct pagedir *dest_pages, void __user *dest,
- struct pagedir *src_pages, const void __user *src,
+ Pagedir *dest_pages, void __user *dest,
+ Pagedir *src_pages, const void __user *src,
size_t length, struct virt_cpy_error *err
) {
struct virt_iter dest_iter, src_iter;
@@ -132,7 +132,7 @@ virt_cpy(
}
size_t
-pcpy_to(struct process *p, __user void *dst, const void *src, size_t len)
+pcpy_to(Proc *p, __user void *dst, const void *src, size_t len)
{
assert(p);
if (!p->pages) return 0;
@@ -140,7 +140,7 @@ pcpy_to(struct process *p, __user void *dst, const void *src, size_t len)
}
size_t
-pcpy_from(struct process *p, void *dst, const __user void *src, size_t len)
+pcpy_from(Proc *p, void *dst, const __user void *src, size_t len)
{
assert(p);
if (!p->pages) return 0;
@@ -149,8 +149,8 @@ pcpy_from(struct process *p, void *dst, const __user void *src, size_t len)
size_t
pcpy_bi(
- struct process *dstp, __user void *dst,
- struct process *srcp, const __user void *src,
+ Proc *dstp, __user void *dst,
+ Proc *srcp, const __user void *src,
size_t len
) {
assert(dstp && srcp);
diff --git a/src/kernel/mem/virt.h b/src/kernel/mem/virt.h
index fc35078..7c9380e 100644
--- a/src/kernel/mem/virt.h
+++ b/src/kernel/mem/virt.h
@@ -1,14 +1,12 @@
// move this to proc.h, maybe?
#pragma once
-#include <camellia/types.h>
+#include <kernel/types.h>
#include <stddef.h>
-struct process;
-
-size_t pcpy_to(struct process *p, __user void *dst, const void *src, size_t len);
-size_t pcpy_from(struct process *p, void *dst, const __user void *src, size_t len);
+size_t pcpy_to(Proc *p, __user void *dst, const void *src, size_t len);
+size_t pcpy_from(Proc *p, void *dst, const __user void *src, size_t len);
size_t pcpy_bi(
- struct process *dstp, __user void *dst,
- struct process *srcp, const __user void *src,
+ Proc *dstp, __user void *dst,
+ Proc *srcp, const __user void *src,
size_t len
);
diff --git a/src/kernel/pipe.c b/src/kernel/pipe.c
index 29e68e2..3ac52d3 100644
--- a/src/kernel/pipe.c
+++ b/src/kernel/pipe.c
@@ -3,9 +3,9 @@
#include <kernel/pipe.h>
#include <kernel/util.h>
-static void pipe_trytransfer(struct handle *h);
+static void pipe_trytransfer(Handle *h);
-void pipe_joinqueue(struct handle *h, struct process *proc, void __user *pbuf, size_t pbuflen) {
+void pipe_joinqueue(Handle *h, Proc *proc, void __user *pbuf, size_t pbuflen) {
assert(h && h->type == HANDLE_PIPE);
assert(h->readable ^ h->writeable);
if (!h->pipe.sister) {
@@ -13,13 +13,13 @@ void pipe_joinqueue(struct handle *h, struct process *proc, void __user *pbuf, s
return;
}
- struct process **slot = &h->pipe.queued;
+ Proc **slot = &h->pipe.queued;
while (*slot) {
assert((*slot)->state == PS_WAITS4PIPE);
slot = &((*slot)->waits4pipe.next);
}
- process_transition(proc, PS_WAITS4PIPE);
+ proc_setstate(proc, PS_WAITS4PIPE);
*slot = proc;
proc->waits4pipe.pipe = h;
proc->waits4pipe.buf = pbuf;
@@ -28,8 +28,8 @@ void pipe_joinqueue(struct handle *h, struct process *proc, void __user *pbuf, s
pipe_trytransfer(h);
}
-static void pipe_trytransfer(struct handle *h) {
- struct process *rdr, *wtr;
+static void pipe_trytransfer(Handle *h) {
+ Proc *rdr, *wtr;
int len;
assert(h && h->type == HANDLE_PIPE);
assert(h->readable ^ h->writeable);
@@ -52,17 +52,17 @@ static void pipe_trytransfer(struct handle *h) {
);
h->pipe.queued = h->pipe.queued->waits4pipe.next;
h->pipe.sister->pipe.queued = h->pipe.sister->pipe.queued->waits4pipe.next;
- process_transition(rdr, PS_RUNNING);
- process_transition(wtr, PS_RUNNING);
+ proc_setstate(rdr, PS_RUNNING);
+ proc_setstate(wtr, PS_RUNNING);
regs_savereturn(&rdr->regs, len);
regs_savereturn(&wtr->regs, len);
}
-void pipe_invalidate_end(struct handle *h) {
- struct process *p = h->pipe.queued;
+void pipe_invalidate_end(Handle *h) {
+ Proc *p = h->pipe.queued;
while (p) {
assert(p->state == PS_WAITS4PIPE);
- process_transition(p, PS_RUNNING);
+ proc_setstate(p, PS_RUNNING);
regs_savereturn(&p->regs, -1);
p = p->waits4pipe.next;
}
diff --git a/src/kernel/pipe.h b/src/kernel/pipe.h
index bcdfb86..24414f8 100644
--- a/src/kernel/pipe.h
+++ b/src/kernel/pipe.h
@@ -3,6 +3,6 @@
#include <stdbool.h>
/* eventually transitions to PS_RUNNING */
-void pipe_joinqueue(struct handle *h, struct process *proc, void __user *pbuf, size_t pbuflen);
+void pipe_joinqueue(Handle *h, Proc *proc, void __user *pbuf, size_t pbuflen);
-void pipe_invalidate_end(struct handle *h);
+void pipe_invalidate_end(Handle *h);
diff --git a/src/kernel/proc.c b/src/kernel/proc.c
index 109316e..93fef1a 100755
--- a/src/kernel/proc.c
+++ b/src/kernel/proc.c
@@ -11,46 +11,46 @@
#include <shared/mem.h>
#include <stdint.h>
-static struct process *process_first = NULL;
-static struct process *process_forgotten = NULL; /* linked list */
-struct process *process_current;
+static Proc *proc_first = NULL;
+static Proc *proc_forgotten = NULL; /* linked list */
+Proc *proc_cur;
static uint32_t next_pid = 1;
/** Removes a process from the process tree. */
-static void process_forget(struct process *p);
-static void process_free_forgotten(void);
-static _Noreturn void process_switch(struct process *proc);
-
-
-struct process *process_seed(void *data, size_t datalen) {
- assert(!process_first);
- process_first = kzalloc(sizeof *process_first);
- process_first->state = PS_RUNNING;
- process_first->pages = pagedir_new();
- process_first->mount = vfs_mount_seed();
- process_first->globalid = next_pid++;
- process_first->cid = 1;
- process_first->nextcid = 1;
- process_first->_handles = kzalloc(sizeof(struct handle) * HANDLE_MAX);
+static void proc_forget(Proc *p);
+static void proc_free_forgotten(void);
+static _Noreturn void proc_switch(Proc *proc);
+
+
+Proc *proc_seed(void *data, size_t datalen) {
+ assert(!proc_first);
+ proc_first = kzalloc(sizeof *proc_first);
+ proc_first->state = PS_RUNNING;
+ proc_first->pages = pagedir_new();
+ proc_first->mount = vfs_mount_seed();
+ proc_first->globalid = next_pid++;
+ proc_first->cid = 1;
+ proc_first->nextcid = 1;
+ proc_first->_handles = kzalloc(sizeof(Handle) * HANDLE_MAX);
// map .shared
extern char _shared_len;
for (size_t p = 0; p < (size_t)&_shared_len; p += PAGE_SIZE)
- pagedir_map(process_first->pages, (userptr_t)p, (void*)p, false, true);
+ pagedir_map(proc_first->pages, (userptr_t)p, (void*)p, false, true);
// map the init module as rw
void __user *init_base = (userptr_t)0x200000;
for (uintptr_t off = 0; off < datalen; off += PAGE_SIZE)
- pagedir_map(process_first->pages, init_base + off, data + off, true, true);
- process_first->regs.rcx = (uintptr_t)init_base; // SYSRET jumps to %rcx
+ pagedir_map(proc_first->pages, init_base + off, data + off, true, true);
+ proc_first->regs.rcx = (uintptr_t)init_base; // SYSRET jumps to %rcx
- return process_first;
+ return proc_first;
}
-struct process *process_fork(struct process *parent, int flags) {
- struct process *child = kzalloc(sizeof *child);
+Proc *proc_fork(Proc *parent, int flags) {
+ Proc *child = kzalloc(sizeof *child);
if (flags & FORK_SHAREMEM) {
if (!parent->pages_refcount) {
@@ -100,8 +100,8 @@ struct process *process_fork(struct process *parent, int flags) {
child->handles_refcount = parent->handles_refcount;
child->_handles = parent->_handles;
} else {
- child->_handles = kzalloc(sizeof(struct handle) * HANDLE_MAX);
- for (handle_t h = 0; h < HANDLE_MAX; h++) {
+ child->_handles = kzalloc(sizeof(Handle) * HANDLE_MAX);
+ for (hid_t h = 0; h < HANDLE_MAX; h++) {
child->_handles[h] = parent->_handles[h];
if (child->_handles[h])
child->_handles[h]->refcount++;
@@ -123,7 +123,7 @@ static bool unref(uint64_t *refcount) {
return false;
}
-void process_kill(struct process *p, int ret) {
+void proc_kill(Proc *p, int ret) {
if (proc_alive(p)) {
if (p->controlled) {
// TODO vfs_backend_user_handlerdown
@@ -145,7 +145,7 @@ void process_kill(struct process *p, int ret) {
}
if (p->state == PS_WAITS4PIPE) {
- struct process **iter = &p->waits4pipe.pipe->pipe.queued;
+ Proc **iter = &p->waits4pipe.pipe->pipe.queued;
while (*iter && *iter != p) {
assert((*iter)->state == PS_WAITS4PIPE);
iter = &(*iter)->waits4pipe.next;
@@ -159,8 +159,8 @@ void process_kill(struct process *p, int ret) {
}
if (unref(p->handles_refcount)) {
- for (handle_t hid = 0; hid < HANDLE_MAX; hid++)
- process_handle_close(p, hid);
+ for (hid_t hid = 0; hid < HANDLE_MAX; hid++)
+ proc_handle_close(p, hid);
kfree(p->_handles);
}
p->_handles = NULL;
@@ -168,14 +168,14 @@ void process_kill(struct process *p, int ret) {
vfs_mount_remref(p->mount);
p->mount = NULL;
- process_transition(p, PS_DYING);
+ proc_setstate(p, PS_DYING);
p->death_msg = ret;
/* tombstone TOREAP children */
- for (struct process *it = p->child; it; ) {
- struct process *sibling = it->sibling;
+ for (Proc *it = p->child; it; ) {
+ Proc *sibling = it->sibling;
if (it->state == PS_TOREAP) {
- process_tryreap(it);
+ proc_tryreap(it);
}
it = sibling;
}
@@ -193,45 +193,45 @@ void process_kill(struct process *p, int ret) {
if (p->state == PS_DYING) {
if (p->parent && proc_alive(p->parent)) {
- process_transition(p, PS_TOREAP);
+ proc_setstate(p, PS_TOREAP);
} else {
- process_transition(p, PS_TOMBSTONE);
+ proc_setstate(p, PS_TOMBSTONE);
}
}
- if (p == process_first && p->child) {
+ if (p == proc_first && p->child) {
_panic("init killed prematurely");
}
- process_tryreap(p);
+ proc_tryreap(p);
- if (p == process_first) {
- process_free_forgotten();
+ if (p == proc_first) {
+ proc_free_forgotten();
shutdown();
}
}
-void process_filicide(struct process *parent, int ret) {
+void proc_filicide(Proc *parent, int ret) {
/* Kill deeper descendants. */
- struct process *child, *child2;
+ Proc *child, *child2;
for (child = parent->child; child; child = child2) {
child2 = child->sibling;
// O(n^2), but doable in linear time
while (child->child) {
- struct process *p = child->child;
+ Proc *p = child->child;
while (p->child) p = p->child;
p->noreap = true;
- process_kill(p, ret);
+ proc_kill(p, ret);
}
if (proc_alive(child)) {
- process_kill(child, ret);
+ proc_kill(child, ret);
}
child = NULL;
}
}
-void process_tryreap(struct process *dead) {
- struct process *parent;
+void proc_tryreap(Proc *dead) {
+ Proc *parent;
assert(dead && !proc_alive(dead));
parent = dead->parent;
if (parent) assert(parent->child);
@@ -243,20 +243,20 @@ void process_tryreap(struct process *dead) {
return; /* don't reap yet */
}
regs_savereturn(&parent->regs, dead->death_msg);
- process_transition(parent, PS_RUNNING);
+ proc_setstate(parent, PS_RUNNING);
}
/* can't be reaped anymore */
- process_transition(dead, PS_TOMBSTONE);
+ proc_setstate(dead, PS_TOMBSTONE);
dead->noreap = true;
}
assert(dead->state == PS_TOMBSTONE);
- for (struct process *p = dead->child; p; p = p->sibling) {
+ for (Proc *p = dead->child; p; p = p->sibling) {
assert(p->state != PS_TOREAP);
}
if (dead->child) {
- struct process *p = dead->child;
+ Proc *p = dead->child;
while (p->child) p = p->child;
if (p->state == PS_TOREAP) {
assert(proc_alive(p->parent));
@@ -269,16 +269,16 @@ void process_tryreap(struct process *dead) {
handle_close(dead->specialh.procfs);
assert(dead->refcount == 0);
if (parent) { /* not applicable to init */
- process_forget(dead);
+ proc_forget(dead);
// TODO force gcc to optimize the tail call here
if (!proc_alive(parent)) {
- process_tryreap(parent);
+ proc_tryreap(parent);
}
}
}
-void process_intr(struct process *p) {
+void proc_intr(Proc *p) {
if (!p->intr_fn) return;
/* save old rsp,rip */
@@ -294,7 +294,7 @@ void process_intr(struct process *p) {
}
/** Removes a process from the process tree. */
-static void process_forget(struct process *p) {
+static void proc_forget(Proc *p) {
assert(p->parent);
assert(p->parent->child);
assert(!p->child);
@@ -303,7 +303,7 @@ static void process_forget(struct process *p) {
p->parent->child = p->sibling;
} else {
// this would be simpler if siblings were a doubly linked list
- struct process *prev = p->parent->child;
+ Proc *prev = p->parent->child;
while (prev->sibling != p) {
prev = prev->sibling;
assert(prev);
@@ -312,24 +312,24 @@ static void process_forget(struct process *p) {
}
p->parent = NULL;
- p->sibling = process_forgotten;
- process_forgotten = p;
- process_transition(p, PS_FORGOTTEN);
+ p->sibling = proc_forgotten;
+ proc_forgotten = p;
+ proc_setstate(p, PS_FORGOTTEN);
}
-static void process_free_forgotten(void) {
- while (process_forgotten) {
- struct process *p = process_forgotten;
- process_forgotten = p->sibling;
+static void proc_free_forgotten(void) {
+ while (proc_forgotten) {
+ Proc *p = proc_forgotten;
+ proc_forgotten = p->sibling;
- process_transition(p, PS_FREED);
+ proc_setstate(p, PS_FREED);
kfree(p);
}
}
-static _Noreturn void process_switch(struct process *proc) {
+static _Noreturn void proc_switch(Proc *proc) {
assert(proc->state == PS_RUNNING);
- process_current = proc;
+ proc_cur = proc;
pagedir_switch(proc->pages);
if (proc->execbuf.buf)
execbuf_run(proc);
@@ -337,25 +337,25 @@ static _Noreturn void process_switch(struct process *proc) {
sysexit(proc->regs);
}
-_Noreturn void process_switch_any(void) {
+_Noreturn void proc_switch_any(void) {
/* At this point there will be no leftover pointers to forgotten
* processes on the stack, so it's safe to free them. */
- process_free_forgotten();
+ proc_free_forgotten();
for (;;) {
- if (process_current && process_current->state == PS_RUNNING)
- process_switch(process_current);
+ if (proc_cur && proc_cur->state == PS_RUNNING)
+ proc_switch(proc_cur);
- for (struct process *p = process_first; p; p = process_next(p, NULL)) {
+ for (Proc *p = proc_first; p; p = proc_next(p, NULL)) {
if (p->state == PS_RUNNING)
- process_switch(p);
+ proc_switch(p);
}
cpu_pause();
}
}
-struct process *process_next(struct process *p, struct process *root) {
+Proc *proc_next(Proc *p, Proc *root) {
/* depth-first search, the order is:
* 1
* / \
@@ -376,17 +376,17 @@ struct process *process_next(struct process *p, struct process *root) {
return p->sibling;
}
-handle_t process_find_free_handle(struct process *proc, handle_t start_at) {
- for (handle_t hid = start_at; hid < HANDLE_MAX; hid++) {
+hid_t proc_find_free_handle(Proc *proc, hid_t start_at) {
+ for (hid_t hid = start_at; hid < HANDLE_MAX; hid++) {
if (proc->_handles[hid] == NULL)
return hid;
}
return -1;
}
-struct handle *process_handle_get(struct process *p, handle_t id) {
+Handle *proc_handle_get(Proc *p, hid_t id) {
if (id == HANDLE_NULLFS) {
- static struct handle h = (struct handle){
+ static Handle h = (Handle){
.type = HANDLE_FS_FRONT,
.backend = NULL,
.refcount = 2, /* never free */
@@ -394,8 +394,8 @@ struct handle *process_handle_get(struct process *p, handle_t id) {
return &h;
} else if (id == HANDLE_PROCFS) {
if (!p->specialh.procfs) {
- struct handle *h = kmalloc(sizeof *h);
- *h = (struct handle){
+ Handle *h = kmalloc(sizeof *h);
+ *h = (Handle){
.type = HANDLE_FS_FRONT,
.backend = procfs_backend(p),
.refcount = 1,
@@ -410,19 +410,19 @@ struct handle *process_handle_get(struct process *p, handle_t id) {
}
}
-handle_t process_handle_init(struct process *p, enum handle_type type, struct handle **hs) {
- handle_t hid = process_find_free_handle(p, 1);
+hid_t proc_handle_init(Proc *p, enum handle_type type, Handle **hs) {
+ hid_t hid = proc_find_free_handle(p, 1);
if (hid < 0) return -1;
p->_handles[hid] = handle_init(type);
if (hs) *hs = p->_handles[hid];
return hid;
}
-handle_t process_handle_dup(struct process *p, handle_t from, handle_t to) {
- struct handle *fromh, **toh;
+hid_t proc_handle_dup(Proc *p, hid_t from, hid_t to) {
+ Handle *fromh, **toh;
if (to < 0) {
- to = process_find_free_handle(p, 0);
+ to = proc_find_free_handle(p, 0);
if (to < 0) return -EMFILE;
} else if (to >= HANDLE_MAX) {
return -EBADF;
@@ -430,7 +430,7 @@ handle_t process_handle_dup(struct process *p, handle_t from, handle_t to) {
if (to == from) return to;
toh = &p->_handles[to];
- fromh = process_handle_get(p, from);
+ fromh = proc_handle_get(p, from);
if (*toh) handle_close(*toh);
*toh = fromh;
@@ -439,18 +439,18 @@ handle_t process_handle_dup(struct process *p, handle_t from, handle_t to) {
return to;
}
-struct handle *process_handle_take(struct process *p, handle_t hid) {
+Handle *proc_hid_take(Proc *p, hid_t hid) {
if (hid < 0 || hid >= HANDLE_MAX) {
- return process_handle_get(p, hid);
+ return proc_handle_get(p, hid);
}
- struct handle *h = p->_handles[hid];
+ Handle *h = p->_handles[hid];
p->_handles[hid] = NULL;
return h;
}
-handle_t process_handle_put(struct process *p, struct handle *h) {
+hid_t proc_handle_put(Proc *p, Handle *h) {
assert(h);
- handle_t hid = process_find_free_handle(p, 1);
+ hid_t hid = proc_find_free_handle(p, 1);
if (hid < 0) {
handle_close(h);
return hid;
@@ -459,7 +459,7 @@ handle_t process_handle_put(struct process *p, struct handle *h) {
return hid;
}
-void process_transition(struct process *p, enum process_state state) {
+void proc_setstate(Proc *p, enum proc_state state) {
assert(p->state != PS_FREED);
if (state == PS_FREED) {
assert(p->state == PS_FORGOTTEN);
@@ -471,7 +471,7 @@ void process_transition(struct process *p, enum process_state state) {
assert(p->state == PS_DYING);
assert(!p->parent || proc_alive(p->parent));
- for (struct process *it = p->child; it; it = it->sibling) {
+ for (Proc *it = p->child; it; it = it->sibling) {
assert(p->state != PS_TOREAP);
}
} else if (state != PS_RUNNING && state != PS_DYING) {
diff --git a/src/kernel/proc.h b/src/kernel/proc.h
index 041dbd0..5120778 100644
--- a/src/kernel/proc.h
+++ b/src/kernel/proc.h
@@ -1,15 +1,15 @@
#pragma once
#include <kernel/arch/generic.h>
#include <kernel/handle.h>
+#include <kernel/types.h>
#include <stdbool.h>
-struct vfs_mount;
#define HANDLE_MAX 16
-/* legal transitions described by process_transition */
-enum process_state {
+/* legal transitions described by proc_setstate */
+enum proc_state {
PS_RUNNING,
- PS_DYING, /* during process_kill - mostly treated as alive */
+ PS_DYING, /* during proc_kill - mostly treated as alive */
PS_TOREAP, /* return message not collected */
PS_TOMBSTONE, /* fully dead, supports alive children */
/* not in the process tree, waits for free.
@@ -33,15 +33,15 @@ enum process_state {
&& p->state != PS_FREED \
)
-struct process {
- struct pagedir *pages;
+struct Proc {
+ Pagedir *pages;
/* if NULL, refcount == 1. kmalloc'd */
uint64_t *pages_refcount;
- struct registers regs;
- struct process *sibling, *child, *parent;
+ CpuRegs regs;
+ Proc *sibling, *child, *parent;
- enum process_state state;
+ enum proc_state state;
union { /* saved value, meaning depends on .state */
int death_msg; // PS_DEAD
struct {
@@ -50,23 +50,23 @@ struct process {
struct ufs_request __user *res;
} awaited_req; // PS_WAITS4REQUEST
struct {
- struct handle *pipe;
+ Handle *pipe;
char __user *buf;
size_t len;
- struct process *next;
+ Proc *next;
} waits4pipe;
struct {
/* managed by timer_schedule */
uint64_t goal;
- struct process *next;
+ Proc *next;
} waits4timer;
};
- struct vfs_mount *mount;
- struct handle **_handles; /* points to struct handle *[HANDLE_MAX] */
+ VfsMount *mount;
+ Handle **_handles; /* points to Handle *[HANDLE_MAX] */
uint64_t *handles_refcount; /* works just like pages_refcount */
struct {
- struct handle *procfs;
+ Handle *procfs;
} specialh;
uint32_t cid; /* child id. unique amongst all of this process' siblings */
@@ -76,10 +76,10 @@ struct process {
bool noreap;
/* allocated once, the requests from WAITS4FS get stored here */
- struct vfs_request *reqslot;
+ VfsReq *reqslot;
/* vfs_backend controlled (not exclusively) by this process */
- struct vfs_backend *controlled;
+ VfsBackend *controlled;
/* interrupt handler */
void __user *intr_fn;
@@ -91,40 +91,40 @@ struct process {
} execbuf;
};
-extern struct process *process_current;
+extern Proc *proc_cur;
/** Creates the root process. */
-struct process *process_seed(void *data, size_t datalen);
-struct process *process_fork(struct process *parent, int flags);
+Proc *proc_seed(void *data, size_t datalen);
+Proc *proc_fork(Proc *parent, int flags);
-void process_kill(struct process *proc, int ret);
+void proc_kill(Proc *proc, int ret);
/** Kills all descendants. */
-void process_filicide(struct process *proc, int ret);
+void proc_filicide(Proc *proc, int ret);
/** Tries to reap a dead process / free a tombstone. */
-void process_tryreap(struct process *dead);
+void proc_tryreap(Proc *dead);
-void process_intr(struct process *proc);
+void proc_intr(Proc *proc);
/** Switches execution to any running process. */
-_Noreturn void process_switch_any(void);
+_Noreturn void proc_switch_any(void);
/** Used for iterating over all processes */
-struct process *process_next(struct process *p, struct process *root);
+Proc *proc_next(Proc *p, Proc *root);
-handle_t process_find_free_handle(struct process *proc, handle_t start_at);
-struct handle *process_handle_get(struct process *, handle_t);
-handle_t process_handle_init(struct process *, enum handle_type, struct handle **);
-handle_t process_handle_dup(struct process *p, handle_t from, handle_t to);
-static inline void process_handle_close(struct process *p, handle_t hid) {
+hid_t proc_find_free_handle(Proc *proc, hid_t start_at);
+Handle *proc_handle_get(Proc *, hid_t);
+hid_t proc_handle_init(Proc *, enum handle_type, Handle **);
+hid_t proc_handle_dup(Proc *p, hid_t from, hid_t to);
+static inline void proc_handle_close(Proc *p, hid_t hid) {
// TODO test
- process_handle_dup(p, -1, hid);
+ proc_handle_dup(p, -1, hid);
}
/* Gets a handle and removes the process' reference to it, without decreasing the refcount.
- * Meant to be used together with process_handle_put. */
-struct handle *process_handle_take(struct process *, handle_t);
+ * Meant to be used together with proc_handle_put. */
+Handle *proc_hid_take(Proc *, hid_t);
/* Put a handle in a process, taking the ownership away from the caller.
* Doesn't increase the refcount on success, decreases it on failure. */
-handle_t process_handle_put(struct process *, struct handle *);
+hid_t proc_handle_put(Proc *, Handle *);
-void process_transition(struct process *, enum process_state);
+void proc_setstate(Proc *, enum proc_state);
diff --git a/src/kernel/ring.c b/src/kernel/ring.c
index 6c03333..2cb6961 100644
--- a/src/kernel/ring.c
+++ b/src/kernel/ring.c
@@ -1,7 +1,7 @@
#include <kernel/mem/virt.h>
#include <kernel/ring.h>
-size_t ring_to_virt(ring_t *r, struct process *proc, void __user *ubuf, size_t max) {
+size_t ring_to_virt(ring_t *r, Proc *proc, void __user *ubuf, size_t max) {
char tmp[32];
if (max > sizeof tmp) max = sizeof tmp;
max = ring_get(r, tmp, max);
diff --git a/src/kernel/ring.h b/src/kernel/ring.h
index 15f4682..89770d0 100644
--- a/src/kernel/ring.h
+++ b/src/kernel/ring.h
@@ -1,6 +1,6 @@
#pragma once
// TODO merge into driver/util.h
+#include <kernel/types.h>
#include <shared/container/ring.h>
-struct pagedir;
-size_t ring_to_virt(ring_t *r, struct process *proc, void __user *ubuf, size_t max);
+size_t ring_to_virt(ring_t *r, Proc *proc, void __user *ubuf, size_t max);
diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c
index 4b03ef4..1ab2efd 100644
--- a/src/kernel/syscalls.c
+++ b/src/kernel/syscalls.c
@@ -13,50 +13,50 @@
#include <stdint.h>
#define SYSCALL_RETURN(val) do { \
- assert(process_current->state == PS_RUNNING); \
- regs_savereturn(&process_current->regs, (long)(val)); \
+ assert(proc_cur->state == PS_RUNNING); \
+ regs_savereturn(&proc_cur->regs, (long)(val)); \
return 0; \
} while (0)
-_Noreturn void _syscall_exit(long ret) {
- process_kill(process_current, ret);
- process_switch_any();
+_Noreturn void _sys_exit(long ret) {
+ proc_kill(proc_cur, ret);
+ proc_switch_any();
}
-long _syscall_await(void) {
+long _sys_await(void) {
bool has_children = false;
- process_transition(process_current, PS_WAITS4CHILDDEATH);
+ proc_setstate(proc_cur, PS_WAITS4CHILDDEATH);
- for (struct process *iter = process_current->child;
+ for (Proc *iter = proc_cur->child;
iter; iter = iter->sibling)
{
if (iter->noreap) continue;
has_children = true;
if (iter->state == PS_TOREAP) {
- process_tryreap(iter);
+ proc_tryreap(iter);
return 0; // dummy
}
}
if (!has_children) {
- process_transition(process_current, PS_RUNNING);
+ proc_setstate(proc_cur, PS_RUNNING);
SYSCALL_RETURN(~0); // TODO errno
}
return 0; // dummy
}
-long _syscall_fork(int flags, handle_t __user *fs_front) {
- struct process *child;
+long _sys_fork(int flags, hid_t __user *fs_front) {
+ Proc *child;
- child = process_fork(process_current, flags);
+ child = proc_fork(proc_cur, flags);
regs_savereturn(&child->regs, 0);
if (flags & FORK_NEWFS) {
- struct handle *h;
- handle_t hid = process_handle_init(process_current, HANDLE_FS_FRONT, &h);
+ Handle *h;
+ hid_t hid = proc_handle_init(proc_cur, HANDLE_FS_FRONT, &h);
if (hid < 0) {
child->noreap = true;
- process_kill(child, -EMFILE);
+ proc_kill(child, -EMFILE);
SYSCALL_RETURN(-EMFILE);
}
@@ -72,14 +72,14 @@ long _syscall_fork(int flags, handle_t __user *fs_front) {
/* failure ignored. if you pass an invalid pointer to this function,
* you just don't receive the handle. you'll probably segfault
* trying to access it anyways */
- pcpy_to(process_current, fs_front, &hid, sizeof hid);
+ pcpy_to(proc_cur, fs_front, &hid, sizeof hid);
}
}
SYSCALL_RETURN(child->cid);
}
-handle_t _syscall_open(const char __user *path, long len, int flags) {
- struct vfs_mount *mount;
+hid_t _sys_open(const char __user *path, long len, int flags) {
+ VfsMount *mount;
char *path_buf = NULL;
if (flags & ~(OPEN_RW | OPEN_CREATE)) SYSCALL_RETURN(-ENOSYS);
@@ -90,14 +90,14 @@ handle_t _syscall_open(const char __user *path, long len, int flags) {
* handles in the meantime anyways, or free some up. */
path_buf = kmalloc(len);
- if (pcpy_from(process_current, path_buf, path, len) < (size_t)len) {
+ if (pcpy_from(proc_cur, path_buf, path, len) < (size_t)len) {
goto fail;
}
len = path_simplify(path_buf, path_buf, len);
if (len == 0) goto fail;
- mount = vfs_mount_resolve(process_current->mount, path_buf, len);
+ mount = vfs_mount_resolve(proc_cur->mount, path_buf, len);
if (!mount) goto fail;
if (mount->prefix_len > 0) { // strip prefix
@@ -107,14 +107,14 @@ handle_t _syscall_open(const char __user *path, long len, int flags) {
memcpy(path_buf, path_buf + mount->prefix_len, len);
}
- vfsreq_create((struct vfs_request) {
+ vfsreq_create((VfsReq) {
.type = VFSOP_OPEN,
.input = {
.kern = true,
.buf_kern = path_buf,
.len = len,
},
- .caller = process_current,
+ .caller = proc_cur,
.backend = mount->backend,
.flags = flags,
});
@@ -124,16 +124,16 @@ fail:
SYSCALL_RETURN(-1);
}
-long _syscall_mount(handle_t hid, const char __user *path, long len) {
- struct vfs_mount *mount = NULL;
- struct vfs_backend *backend = NULL;
+long _sys_mount(hid_t hid, const char __user *path, long len) {
+ VfsMount *mount = NULL;
+ VfsBackend *backend = NULL;
char *path_buf = NULL;
if (PATH_MAX < len)
SYSCALL_RETURN(-1);
path_buf = kmalloc(len);
- if (pcpy_from(process_current, path_buf, path, len) < (size_t)len) {
+ if (pcpy_from(proc_cur, path_buf, path, len) < (size_t)len) {
goto fail;
}
@@ -147,7 +147,7 @@ long _syscall_mount(handle_t hid, const char __user *path, long len) {
len--;
}
- struct handle *handle = process_handle_get(process_current, hid);
+ Handle *handle = proc_handle_get(proc_cur, hid);
if (!handle || handle->type != HANDLE_FS_FRONT)
goto fail;
backend = handle->backend;
@@ -159,13 +159,13 @@ long _syscall_mount(handle_t hid, const char __user *path, long len) {
// append to mount list
// TODO move to kernel/vfs/mount.c
mount = kmalloc(sizeof *mount);
- mount->prev = process_current->mount;
+ mount->prev = proc_cur->mount;
mount->prefix = path_buf;
mount->prefix_owned = true;
mount->prefix_len = len;
mount->backend = backend;
mount->refs = 1;
- process_current->mount = mount;
+ proc_cur->mount = mount;
kmalloc_sanity(mount);
kmalloc_sanity(mount->prefix);
@@ -177,19 +177,19 @@ fail:
SYSCALL_RETURN(-1);
}
-handle_t _syscall_dup(handle_t from, handle_t to, int flags) {
+hid_t _sys_dup(hid_t from, hid_t to, int flags) {
if (flags != 0) SYSCALL_RETURN(-ENOSYS);
- SYSCALL_RETURN(process_handle_dup(process_current, from, to));
+ SYSCALL_RETURN(proc_handle_dup(proc_cur, from, to));
}
static long simple_vfsop(
- enum vfs_operation vfsop, handle_t hid, void __user *buf,
+ enum vfs_op vfsop, hid_t hid, void __user *buf,
size_t len, long offset, int flags)
{
assert(vfsop == VFSOP_READ
|| vfsop == VFSOP_WRITE
|| vfsop == VFSOP_GETSIZE);
- struct handle *h = process_handle_get(process_current, hid);
+ Handle *h = proc_handle_get(proc_cur, hid);
if (!h) SYSCALL_RETURN(-EBADF);
// TODO those checks really need some comprehensive tests
if (vfsop == VFSOP_READ && !h->readable)
@@ -198,11 +198,11 @@ static long simple_vfsop(
SYSCALL_RETURN(-EACCES);
if (h->type == HANDLE_FILE) {
- struct vfs_request req = (struct vfs_request){
+ VfsReq req = (VfsReq){
.type = vfsop,
.backend = h->backend,
.id = h->file_id,
- .caller = process_current,
+ .caller = proc_cur,
.offset = offset,
.flags = flags,
};
@@ -218,60 +218,60 @@ static long simple_vfsop(
} else if (h->type == HANDLE_PIPE) {
if (vfsop == VFSOP_READ || vfsop == VFSOP_WRITE) {
/* already checked if this is the correct pipe end */
- pipe_joinqueue(h, process_current, buf, len);
+ pipe_joinqueue(h, proc_cur, buf, len);
} else SYSCALL_RETURN(-ENOSYS);
} else SYSCALL_RETURN(-ENOSYS);
return 0;
}
-long _syscall_read(handle_t hid, void __user *buf, size_t len, long offset) {
+long _sys_read(hid_t hid, void __user *buf, size_t len, long offset) {
simple_vfsop(VFSOP_READ, hid, buf, len, offset, 0);
return 0;
}
-long _syscall_write(handle_t hid, const void __user *buf, size_t len, long offset, int flags) {
+long _sys_write(hid_t hid, const void __user *buf, size_t len, long offset, int flags) {
if (flags & ~(WRITE_TRUNCATE))
SYSCALL_RETURN(-ENOSYS);
simple_vfsop(VFSOP_WRITE, hid, (userptr_t)buf, len, offset, flags);
return 0;
}
-long _syscall_getsize(handle_t hid) {
+long _sys_getsize(hid_t hid) {
simple_vfsop(VFSOP_GETSIZE, hid, NULL, 0, 0, 0);
return 0;
}
-long _syscall_remove(handle_t hid) {
- struct handle *h = process_handle_get(process_current, hid);
+long _sys_remove(hid_t hid) {
+ Handle *h = proc_handle_get(proc_cur, hid);
if (!h) SYSCALL_RETURN(-EBADF);
if (h->type != HANDLE_FILE) {
- process_handle_close(process_current, hid);
+ proc_handle_close(proc_cur, hid);
SYSCALL_RETURN(-ENOSYS);
}
if (!h->writeable) {
- process_handle_close(process_current, hid);
+ proc_handle_close(proc_cur, hid);
SYSCALL_RETURN(-EACCES);
}
- vfsreq_create((struct vfs_request) {
+ vfsreq_create((VfsReq) {
.type = VFSOP_REMOVE,
.id = h->file_id,
- .caller = process_current,
+ .caller = proc_cur,
.backend = h->backend,
});
- process_handle_close(process_current, hid);
+ proc_handle_close(proc_cur, hid);
return -1; // dummy
}
-long _syscall_close(handle_t hid) {
- if (!process_handle_get(process_current, hid)) {
+long _sys_close(hid_t hid) {
+ if (!proc_handle_get(proc_cur, hid)) {
SYSCALL_RETURN(-EBADF);
}
- process_handle_close(process_current, hid);
+ proc_handle_close(proc_cur, hid);
SYSCALL_RETURN(0);
}
-handle_t _syscall_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res) {
- struct vfs_backend *backend = process_current->controlled;
+hid_t _sys_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res) {
+ VfsBackend *backend = proc_cur->controlled;
// TODO can be used to tell if you're init
if (!backend) SYSCALL_RETURN(-1);
if (backend->usehcnt == 0) {
@@ -279,22 +279,22 @@ handle_t _syscall_fs_wait(char __user *buf, long max_len, struct ufs_request __u
SYSCALL_RETURN(-EPIPE);
}
- process_transition(process_current, PS_WAITS4REQUEST);
+ proc_setstate(proc_cur, PS_WAITS4REQUEST);
if (backend->user.handler)
panic_unimplemented();
- backend->user.handler = process_current;
- process_current->awaited_req.buf = buf;
- process_current->awaited_req.max_len = max_len;
- process_current->awaited_req.res = res;
+ backend->user.handler = proc_cur;
+ proc_cur->awaited_req.buf = buf;
+ proc_cur->awaited_req.max_len = max_len;
+ proc_cur->awaited_req.res = res;
vfs_backend_tryaccept(backend); // sets return value
return -1; // dummy
}
-long _syscall_fs_respond(handle_t hid, const void __user *buf, long ret, int flags) {
- struct handle *h = process_handle_get(process_current, hid);
+long _sys_fs_respond(hid_t hid, const void __user *buf, long ret, int flags) {
+ Handle *h = proc_handle_get(proc_cur, hid);
if (!h || h->type != HANDLE_FS_REQ) SYSCALL_RETURN(-EBADF);
- struct vfs_request *req = h->req;
+ VfsReq *req = h->req;
if (req) {
if (req->output.len > 0 && ret > 0) {
// if this vfsop outputs data and ret is positive, it's the length of the buffer
@@ -303,19 +303,19 @@ long _syscall_fs_respond(handle_t hid, const void __user *buf, long ret, int fla
ret = min(ret, capped_cast32(req->output.len));
ret = pcpy_bi(
req->caller, req->output.buf,
- process_current, buf,
+ proc_cur, buf,
ret
);
}
- vfsreq_finish(req, (void __user *)buf, ret, flags, process_current);
+ vfsreq_finish(req, (void __user *)buf, ret, flags, proc_cur);
}
h->req = NULL;
- process_handle_close(process_current, hid);
+ proc_handle_close(proc_cur, hid);
SYSCALL_RETURN(0);
}
-void __user *_syscall_memflag(void __user *addr, size_t len, int flags) {
- struct pagedir *pages = process_current->pages;
+void __user *_sys_memflag(void __user *addr, size_t len, int flags) {
+ Pagedir *pages = proc_cur->pages;
void *phys;
addr = (userptr_t)((uintptr_t __force)addr & ~PAGE_MASK); // align to page boundary
@@ -348,16 +348,16 @@ void __user *_syscall_memflag(void __user *addr, size_t len, int flags) {
SYSCALL_RETURN((uintptr_t)addr);
}
-long _syscall_pipe(handle_t __user user_ends[2], int flags) {
+long _sys_pipe(hid_t __user user_ends[2], int flags) {
if (flags) SYSCALL_RETURN(-ENOSYS);
- handle_t ends[2];
- struct handle *rend, *wend;
- ends[0] = process_handle_init(process_current, HANDLE_PIPE, &rend);
- ends[1] = process_handle_init(process_current, HANDLE_PIPE, &wend);
+ hid_t ends[2];
+ Handle *rend, *wend;
+ ends[0] = proc_handle_init(proc_cur, HANDLE_PIPE, &rend);
+ ends[1] = proc_handle_init(proc_cur, HANDLE_PIPE, &wend);
if (ends[0] < 0 || ends[1] < 0) {
- process_handle_close(process_current, ends[0]);
- process_handle_close(process_current, ends[1]);
+ proc_handle_close(proc_cur, ends[0]);
+ proc_handle_close(proc_cur, ends[1]);
SYSCALL_RETURN(-EMFILE);
}
wend->pipe.sister = rend;
@@ -365,55 +365,55 @@ long _syscall_pipe(handle_t __user user_ends[2], int flags) {
wend->writeable = true;
rend->readable = true;
- pcpy_to(process_current, user_ends, ends, sizeof ends);
+ pcpy_to(proc_cur, user_ends, ends, sizeof ends);
SYSCALL_RETURN(0);
}
-void _syscall_sleep(long ms) {
+void _sys_sleep(long ms) {
// TODO no overflow check - can leak current uptime
- timer_schedule(process_current, uptime_ms() + ms);
+ timer_schedule(proc_cur, uptime_ms() + ms);
}
-void _syscall_filicide(void) {
- process_filicide(process_current, -1);
+void _sys_filicide(void) {
+ proc_filicide(proc_cur, -1);
}
-void _syscall_intr(void) {
- for (struct process *p = process_current->child; p; p = process_next(p, process_current)) {
- process_intr(p);
+void _sys_intr(void) {
+ for (Proc *p = proc_cur->child; p; p = proc_next(p, proc_cur)) {
+ proc_intr(p);
}
}
-void _syscall_intr_set(void __user *ip) {
- process_current->intr_fn = ip;
+void _sys_intr_set(void __user *ip) {
+ proc_cur->intr_fn = ip;
}
-long _syscall_execbuf(void __user *ubuf, size_t len) {
+long _sys_execbuf(void __user *ubuf, size_t len) {
if (len == 0) SYSCALL_RETURN(0);
if (len > EXECBUF_MAX_LEN)
SYSCALL_RETURN(-1);
- if (process_current->execbuf.buf)
+ if (proc_cur->execbuf.buf)
SYSCALL_RETURN(-1);
// TODO consider supporting nesting execbufs
char *kbuf = kmalloc(len);
- if (pcpy_from(process_current, kbuf, ubuf, len) < len) {
+ if (pcpy_from(proc_cur, kbuf, ubuf, len) < len) {
kfree(kbuf);
SYSCALL_RETURN(-1);
}
- process_current->execbuf.buf = kbuf;
- process_current->execbuf.len = len;
- process_current->execbuf.pos = 0;
+ proc_cur->execbuf.buf = kbuf;
+ proc_cur->execbuf.len = len;
+ proc_cur->execbuf.pos = 0;
SYSCALL_RETURN(0);
}
-void _syscall_debug_klog(const void __user *buf, size_t len) {
+void _sys_debug_klog(const void __user *buf, size_t len) {
if (false) {
static char kbuf[256];
if (len >= sizeof(kbuf)) len = sizeof(kbuf) - 1;
- pcpy_from(process_current, kbuf, buf, len);
+ pcpy_from(proc_cur, kbuf, buf, len);
kbuf[len] = '\0';
- kprintf("[klog] %x\t%s\n", process_current->globalid, kbuf);
+ kprintf("[klog] %x\t%s\n", proc_cur->globalid, kbuf);
}
}
@@ -421,30 +421,30 @@ long _syscall(long num, long a, long b, long c, long d, long e) {
/* note: this isn't the only place where syscalls get called from!
* see execbuf */
switch (num) {
- break; case _SYSCALL_EXIT: _syscall_exit(a);
- break; case _SYSCALL_AWAIT: _syscall_await();
- break; case _SYSCALL_FORK: _syscall_fork(a, (userptr_t)b);
- break; case _SYSCALL_OPEN: _syscall_open((userptr_t)a, b, c);
- break; case _SYSCALL_MOUNT: _syscall_mount(a, (userptr_t)b, c);
- break; case _SYSCALL_DUP: _syscall_dup(a, b, c);
- break; case _SYSCALL_READ: _syscall_read(a, (userptr_t)b, c, d);
- break; case _SYSCALL_WRITE: _syscall_write(a, (userptr_t)b, c, d, e);
- break; case _SYSCALL_GETSIZE: _syscall_getsize(a);
- break; case _SYSCALL_REMOVE: _syscall_remove(a);
- break; case _SYSCALL_CLOSE: _syscall_close(a);
- break; case _SYSCALL_FS_WAIT: _syscall_fs_wait((userptr_t)a, b, (userptr_t)c);
- break; case _SYSCALL_FS_RESPOND: _syscall_fs_respond(a, (userptr_t)b, c, d);
- break; case _SYSCALL_MEMFLAG: _syscall_memflag((userptr_t)a, b, c);
- break; case _SYSCALL_PIPE: _syscall_pipe((userptr_t)a, b);
- break; case _SYSCALL_SLEEP: _syscall_sleep(a);
- break; case _SYSCALL_FILICIDE: _syscall_filicide();
- break; case _SYSCALL_INTR: _syscall_intr();
- break; case _SYSCALL_INTR_SET: _syscall_intr_set((userptr_t)a);
- break; case _SYSCALL_EXECBUF: _syscall_execbuf((userptr_t)a, b);
- break; case _SYSCALL_DEBUG_KLOG: _syscall_debug_klog((userptr_t)a, b);
+ break; case _SYS_EXIT: _sys_exit(a);
+ break; case _SYS_AWAIT: _sys_await();
+ break; case _SYS_FORK: _sys_fork(a, (userptr_t)b);
+ break; case _SYS_OPEN: _sys_open((userptr_t)a, b, c);
+ break; case _SYS_MOUNT: _sys_mount(a, (userptr_t)b, c);
+ break; case _SYS_DUP: _sys_dup(a, b, c);
+ break; case _SYS_READ: _sys_read(a, (userptr_t)b, c, d);
+ break; case _SYS_WRITE: _sys_write(a, (userptr_t)b, c, d, e);
+ break; case _SYS_GETSIZE: _sys_getsize(a);
+ break; case _SYS_REMOVE: _sys_remove(a);
+ break; case _SYS_CLOSE: _sys_close(a);
+ break; case _SYS_FS_WAIT: _sys_fs_wait((userptr_t)a, b, (userptr_t)c);
+ break; case _SYS_FS_RESPOND: _sys_fs_respond(a, (userptr_t)b, c, d);
+ break; case _SYS_MEMFLAG: _sys_memflag((userptr_t)a, b, c);
+ break; case _SYS_PIPE: _sys_pipe((userptr_t)a, b);
+ break; case _SYS_SLEEP: _sys_sleep(a);
+ break; case _SYS_FILICIDE: _sys_filicide();
+ break; case _SYS_INTR: _sys_intr();
+ break; case _SYS_INTR_SET: _sys_intr_set((userptr_t)a);
+ break; case _SYS_EXECBUF: _sys_execbuf((userptr_t)a, b);
+ break; case _SYS_DEBUG_KLOG: _sys_debug_klog((userptr_t)a, b);
break;
default:
- regs_savereturn(&process_current->regs, -1);
+ regs_savereturn(&proc_cur->regs, -1);
break;
}
/* return value is unused. execution continues in sysenter_stage2 */
diff --git a/src/kernel/types.h b/src/kernel/types.h
new file mode 100644
index 0000000..e186479
--- /dev/null
+++ b/src/kernel/types.h
@@ -0,0 +1,17 @@
+#pragma once
+#include <camellia/types.h>
+
+#define FORWARD_STRUCT(name) struct name; typedef struct name name;
+
+FORWARD_STRUCT(CpuRegs)
+FORWARD_STRUCT(Handle)
+FORWARD_STRUCT(Pagedir)
+FORWARD_STRUCT(Proc)
+FORWARD_STRUCT(VfsBackend)
+FORWARD_STRUCT(VfsMount)
+FORWARD_STRUCT(VfsReq)
+
+/* arch-specific stuff */
+FORWARD_STRUCT(GfxInfo)
+
+#undef FORWARD_STRUCT
diff --git a/src/kernel/vfs/mount.c b/src/kernel/vfs/mount.c
index 2815bb9..2518989 100644
--- a/src/kernel/vfs/mount.c
+++ b/src/kernel/vfs/mount.c
@@ -3,22 +3,22 @@
#include <kernel/vfs/mount.h>
#include <shared/mem.h>
-static struct vfs_mount *mount_root = NULL;
+static VfsMount *mount_root = NULL;
-struct vfs_mount *vfs_mount_seed(void) {
+VfsMount *vfs_mount_seed(void) {
return mount_root;
}
-void vfs_root_register(const char *path, void (*accept)(struct vfs_request *)) {
- struct vfs_backend *backend = kmalloc(sizeof *backend);
- struct vfs_mount *mount = kmalloc(sizeof *mount);
- *backend = (struct vfs_backend) {
+void vfs_root_register(const char *path, void (*accept)(VfsReq *)) {
+ VfsBackend *backend = kmalloc(sizeof *backend);
+ VfsMount *mount = kmalloc(sizeof *mount);
+ *backend = (VfsBackend) {
.is_user = false,
.usehcnt = 1,
.provhcnt = 1,
.kern.accept = accept,
};
- *mount = (struct vfs_mount){
+ *mount = (VfsMount){
.prev = mount_root,
.prefix = path,
.prefix_len = strlen(path),
@@ -29,8 +29,8 @@ void vfs_root_register(const char *path, void (*accept)(struct vfs_request *)) {
}
-struct vfs_mount *vfs_mount_resolve(
- struct vfs_mount *top, const char *path, size_t path_len)
+VfsMount *vfs_mount_resolve(
+ VfsMount *top, const char *path, size_t path_len)
{
for (; top; top = top->prev) {
if (top->prefix_len > path_len)
@@ -49,12 +49,12 @@ struct vfs_mount *vfs_mount_resolve(
return top;
}
-void vfs_mount_remref(struct vfs_mount *mnt) {
+void vfs_mount_remref(VfsMount *mnt) {
assert(mnt);
assert(mnt->refs > 0);
if (--(mnt->refs) > 0) return;
- struct vfs_mount *prev = mnt->prev;
+ VfsMount *prev = mnt->prev;
if (mnt->backend) {
vfs_backend_refdown(mnt->backend, true);
}
diff --git a/src/kernel/vfs/mount.h b/src/kernel/vfs/mount.h
index 6efdaa7..2e10dec 100644
--- a/src/kernel/vfs/mount.h
+++ b/src/kernel/vfs/mount.h
@@ -1,24 +1,25 @@
#pragma once
+#include <kernel/types.h>
#include <kernel/vfs/request.h>
#include <stddef.h>
-struct vfs_mount {
- struct vfs_mount *prev;
+struct VfsMount {
+ VfsMount *prev;
const char *prefix;
size_t prefix_len;
bool prefix_owned;
- struct vfs_backend *backend;
+ VfsBackend *backend;
size_t refs; /* counts all references, atm from:
- * - struct vfs_mount
- * - struct proc
+ * - VfsMount
+ * - Proc
*/
};
// prepares init's filesystem view
-struct vfs_mount *vfs_mount_seed(void);
-struct vfs_mount *vfs_mount_resolve(
- struct vfs_mount *top, const char *path, size_t path_len);
+VfsMount *vfs_mount_seed(void);
+VfsMount *vfs_mount_resolve(
+ VfsMount *top, const char *path, size_t path_len);
/** Decrements the reference count, potentially freeing the mount. */
-void vfs_mount_remref(struct vfs_mount *mnt);
+void vfs_mount_remref(VfsMount *mnt);
-void vfs_root_register(const char *path, void (*accept)(struct vfs_request *));
+void vfs_root_register(const char *path, void (*accept)(VfsReq *));
diff --git a/src/kernel/vfs/procfs.c b/src/kernel/vfs/procfs.c
index 78dad0d..2a8dd93 100644
--- a/src/kernel/vfs/procfs.c
+++ b/src/kernel/vfs/procfs.c
@@ -18,14 +18,14 @@ struct phandle {
enum phandle_type type;
};
-static struct phandle *openpath(const char *path, size_t len, struct process *root);
-static struct process *findgid(uint32_t gid, struct process *root);
-static void procfs_accept(struct vfs_request *req);
-static void procfs_cleanup(struct vfs_backend *be);
+static struct phandle *openpath(const char *path, size_t len, Proc *root);
+static Proc *findgid(uint32_t gid, Proc *root);
+static void procfs_accept(VfsReq *req);
+static void procfs_cleanup(VfsBackend *be);
static int isdigit(int c);
static struct phandle *
-openpath(const char *path, size_t len, struct process *p)
+openpath(const char *path, size_t len, Proc *p)
{
struct phandle *h;
enum phandle_type type;
@@ -71,21 +71,21 @@ openpath(const char *path, size_t len, struct process *p)
return h;
}
-static struct process *
-findgid(uint32_t gid, struct process *root)
+static Proc *
+findgid(uint32_t gid, Proc *root)
{
- for (struct process *p = root; p; p = process_next(p, root)) {
+ for (Proc *p = root; p; p = proc_next(p, root)) {
if (p->globalid == gid) return p;
}
return NULL;
}
static void
-procfs_accept(struct vfs_request *req)
+procfs_accept(VfsReq *req)
{
- struct process *root = req->backend->kern.data;
+ Proc *root = req->backend->kern.data;
struct phandle *h = (__force void*)req->id;
- struct process *p;
+ Proc *p;
char buf[512];
assert(root);
if (req->type == VFSOP_OPEN) {
@@ -110,7 +110,7 @@ procfs_accept(struct vfs_request *req)
}
pos += snprintf(buf + pos, 512 - pos, "intr")+1;
pos += snprintf(buf + pos, 512 - pos, "mem")+1;
- for (struct process *iter = p->child; iter; iter = iter->sibling) {
+ for (Proc *iter = p->child; iter; iter = iter->sibling) {
assert(pos < 512);
// processes could possibly be identified by unique identifiers instead
// e.g. an encrypted gid, or just a randomly generated one
@@ -135,7 +135,7 @@ procfs_accept(struct vfs_request *req)
);
vfsreq_finish_short(req, res);
} else if (req->type == VFSOP_WRITE && h->type == PhIntr) {
- process_intr(p);
+ proc_intr(p);
vfsreq_finish_short(req, req->input.len);
} else if (req->type == VFSOP_CLOSE) {
kfree(h);
@@ -146,9 +146,9 @@ procfs_accept(struct vfs_request *req)
}
static void
-procfs_cleanup(struct vfs_backend *be)
+procfs_cleanup(VfsBackend *be)
{
- struct process *p = be->kern.data;
+ Proc *p = be->kern.data;
assert(p);
p->refcount--;
}
@@ -158,11 +158,11 @@ isdigit(int c) {
return '0' <= c && c <= '9';
}
-struct vfs_backend *
-procfs_backend(struct process *proc)
+VfsBackend *
+procfs_backend(Proc *proc)
{
- struct vfs_backend *be = kzalloc(sizeof(struct vfs_backend));
- *be = (struct vfs_backend) {
+ VfsBackend *be = kzalloc(sizeof(VfsBackend));
+ *be = (VfsBackend) {
.is_user = false,
.provhcnt = 1,
.usehcnt = 1,
diff --git a/src/kernel/vfs/procfs.h b/src/kernel/vfs/procfs.h
index 5ee4e96..4fb8c84 100644
--- a/src/kernel/vfs/procfs.h
+++ b/src/kernel/vfs/procfs.h
@@ -1,4 +1,4 @@
#pragma once
#include <kernel/vfs/request.h>
-struct vfs_backend *procfs_backend(struct process *proc);
+VfsBackend *procfs_backend(Proc *proc);
diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c
index c98913a..7e5877d 100644
--- a/src/kernel/vfs/request.c
+++ b/src/kernel/vfs/request.c
@@ -7,12 +7,12 @@
#include <kernel/vfs/request.h>
#include <shared/mem.h>
-static void vfs_backend_user_accept(struct vfs_request *req);
+static void vfs_backend_user_accept(VfsReq *req);
-void vfsreq_create(struct vfs_request req_) {
- struct vfs_request *req;
+void vfsreq_create(VfsReq req_) {
+ VfsReq *req;
if (req_.caller) {
- process_transition(req_.caller, PS_WAITS4FS);
+ proc_setstate(req_.caller, PS_WAITS4FS);
if (!req_.caller->reqslot)
req_.caller->reqslot = kmalloc(sizeof *req);
req = req_.caller->reqslot;
@@ -34,7 +34,7 @@ void vfsreq_create(struct vfs_request req_) {
// TODO if i add a handle field to vfs_request, check ->readable ->writeable here
if (req->backend && req->backend->provhcnt) {
- struct vfs_request **iter = &req->backend->queue;
+ VfsReq **iter = &req->backend->queue;
while (*iter != NULL) // find free spot in queue
iter = &(*iter)->queue_next;
*iter = req;
@@ -44,11 +44,11 @@ void vfsreq_create(struct vfs_request req_) {
}
}
-void vfsreq_finish(struct vfs_request *req, char __user *stored, long ret,
- int flags, struct process *handler)
+void vfsreq_finish(VfsReq *req, char __user *stored, long ret,
+ int flags, Proc *handler)
{
if (req->type == VFSOP_OPEN && ret >= 0) {
- struct handle *h;
+ Handle *h;
if (!(flags & FSR_DELEGATE)) {
/* default behavior - create a new handle for the file, wrap the id */
h = handle_init(HANDLE_FILE);
@@ -60,14 +60,14 @@ void vfsreq_finish(struct vfs_request *req, char __user *stored, long ret,
} else {
/* delegating - moving a handle to the caller */
assert(handler);
- h = process_handle_take(handler, ret);
+ h = proc_hid_take(handler, ret);
// TODO don't ignore OPEN_RO
}
if (h) {
// TODO write tests for caller getting killed while opening a file
if (!req->caller) panic_unimplemented();
- ret = process_handle_put(req->caller, h);
+ ret = proc_handle_put(req->caller, h);
if (ret < 0) ret = -EMFILE;
} else {
ret = -1;
@@ -83,14 +83,14 @@ void vfsreq_finish(struct vfs_request *req, char __user *stored, long ret,
if (req->caller) {
assert(req->caller->state == PS_WAITS4FS);
regs_savereturn(&req->caller->regs, ret);
- process_transition(req->caller, PS_RUNNING);
+ proc_setstate(req->caller, PS_RUNNING);
} else {
kfree(req);
}
}
-void vfs_backend_tryaccept(struct vfs_backend *backend) {
- struct vfs_request *req = backend->queue;
+void vfs_backend_tryaccept(VfsBackend *backend) {
+ VfsReq *req = backend->queue;
if (!req) return;
if (backend->is_user && !backend->user.handler) return;
@@ -103,8 +103,8 @@ void vfs_backend_tryaccept(struct vfs_backend *backend) {
}
}
-static void vfs_backend_user_accept(struct vfs_request *req) {
- struct process *handler;
+static void vfs_backend_user_accept(VfsReq *req) {
+ Proc *handler;
struct ufs_request res = {0};
int len;
@@ -143,26 +143,26 @@ static void vfs_backend_user_accept(struct vfs_request *req) {
panic_unimplemented();
}
- struct handle *h;
- handle_t hid = process_handle_init(handler, HANDLE_FS_REQ, &h);
+ Handle *h;
+ hid_t hid = proc_handle_init(handler, HANDLE_FS_REQ, &h);
if (hid < 0) panic_unimplemented();
h->req = req;
- process_transition(handler, PS_RUNNING);
+ proc_setstate(handler, PS_RUNNING);
regs_savereturn(&handler->regs, hid);
req->backend->user.handler = NULL;
return;
}
-void vfs_backend_refdown(struct vfs_backend *b, bool use) {
+void vfs_backend_refdown(VfsBackend *b, bool use) {
size_t *field = use ? &b->usehcnt : &b->provhcnt;
assert(b);
assert(0 < *field);
*field -= 1;
if (b->provhcnt == 0 && use == false) {
- struct vfs_request *q = b->queue;
+ VfsReq *q = b->queue;
while (q) {
- struct vfs_request *q2 = q->queue_next;
+ VfsReq *q2 = q->queue_next;
vfsreq_finish_short(q, -1);
q = q2;
}
@@ -173,11 +173,11 @@ void vfs_backend_refdown(struct vfs_backend *b, bool use) {
b->kern.cleanup(b);
}
if (b->is_user && b->user.handler) {
- struct process *p = b->user.handler;
+ Proc *p = b->user.handler;
b->user.handler = NULL;
assert(p->state == PS_WAITS4REQUEST);
regs_savereturn(&p->regs, -EPIPE);
- process_transition(p, PS_RUNNING);
+ proc_setstate(p, PS_RUNNING);
}
}
if (b->usehcnt == 0 && b->provhcnt == 0) {
diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h
index 4d7fa01..182202c 100644
--- a/src/kernel/vfs/request.h
+++ b/src/kernel/vfs/request.h
@@ -1,38 +1,38 @@
#pragma once
-#include <camellia/types.h>
+#include <kernel/types.h>
#include <stdbool.h>
#include <stddef.h>
-// describes something which can act as an access function
-struct vfs_backend {
+/* describes something which can act as an access function */
+struct VfsBackend {
/* amount of using references
- * struct vfs_mount
- * struct vfs_request
- * struct handle
+ * VfsMount
+ * VfsReq
+ * Handle
* once it reaches 0, it'll never increase */
- size_t usehcnt; /* struct vfs_mount */
+ size_t usehcnt; /* VfsMount */
/* amount of providing references
- * struct process
+ * Proc
* 0 - orphaned, will never increase */
size_t provhcnt;
- struct vfs_request *queue;
+ VfsReq *queue;
bool is_user;
union {
struct {
- struct process *handler;
+ Proc *handler;
} user;
struct {
- void (*accept)(struct vfs_request *);
- void (*cleanup)(struct vfs_backend *);
+ void (*accept)(VfsReq *);
+ void (*cleanup)(VfsBackend *);
void *data;
} kern;
};
};
-// describes an in-process vfs call
-struct vfs_request {
- enum vfs_operation type;
+/* describes an in-progress vfs call */
+struct VfsReq {
+ enum vfs_op type;
struct {
bool kern; // if false: use .buf ; if true: use .buf_kern
union {
@@ -54,26 +54,26 @@ struct vfs_request {
/* if caller != NULL, owned by it - don't free, the allocation will be reused
* if caller == NULL, free on finish */
- struct process *caller;
- struct vfs_backend *backend;
+ Proc *caller;
+ VfsBackend *backend;
- struct vfs_request *queue_next;
- struct vfs_request *postqueue_next; /* used by kernel backends */
+ VfsReq *queue_next;
+ VfsReq *postqueue_next; /* used by kernel backends */
/* only one of these queues is in use at a given moment, they could
* be merged into a single field */
};
/** Assigns the vfs_request to the caller, and dispatches the call */
-void vfsreq_create(struct vfs_request);
-void vfsreq_finish(struct vfs_request*, char __user *stored, long ret, int flags, struct process *handler);
+void vfsreq_create(VfsReq);
+void vfsreq_finish(VfsReq*, char __user *stored, long ret, int flags, Proc *handler);
-static inline void vfsreq_finish_short(struct vfs_request *req, long ret) {
+static inline void vfsreq_finish_short(VfsReq *req, long ret) {
vfsreq_finish(req, (void __user *)ret, ret, 0, NULL);
}
/** Try to accept an enqueued request */
-void vfs_backend_tryaccept(struct vfs_backend *);
+void vfs_backend_tryaccept(VfsBackend *);
// TODO the bool arg is confusing. maybe this should just be a function
// that verified the refcount and potentially frees the backend
-void vfs_backend_refdown(struct vfs_backend *, bool use);
+void vfs_backend_refdown(VfsBackend *, bool use);
diff --git a/src/shared/include/camellia/syscalls.h b/src/shared/include/camellia/syscalls.h
index 1de5368..5d63223 100644
--- a/src/shared/include/camellia/syscalls.h
+++ b/src/shared/include/camellia/syscalls.h
@@ -1,27 +1,27 @@
#pragma once
-#define _SYSCALL_EXIT 0
-#define _SYSCALL_AWAIT 1
-#define _SYSCALL_FORK 2
-#define _SYSCALL_OPEN 3
-#define _SYSCALL_MOUNT 4
-#define _SYSCALL_DUP 5
-#define _SYSCALL_READ 6
-#define _SYSCALL_WRITE 7
-#define _SYSCALL_GETSIZE 8
-#define _SYSCALL_REMOVE 9
-#define _SYSCALL_CLOSE 10
-#define _SYSCALL_FS_WAIT 11
-#define _SYSCALL_FS_RESPOND 12
-#define _SYSCALL_MEMFLAG 13
-#define _SYSCALL_PIPE 14
-#define _SYSCALL_SLEEP 15
-#define _SYSCALL_FILICIDE 16
-#define _SYSCALL_INTR 17
-#define _SYSCALL_INTR_SET 18
-
-#define _SYSCALL_EXECBUF 100
-#define _SYSCALL_DEBUG_KLOG 101
+#define _SYS_EXIT 0
+#define _SYS_AWAIT 1
+#define _SYS_FORK 2
+#define _SYS_OPEN 3
+#define _SYS_MOUNT 4
+#define _SYS_DUP 5
+#define _SYS_READ 6
+#define _SYS_WRITE 7
+#define _SYS_GETSIZE 8
+#define _SYS_REMOVE 9
+#define _SYS_CLOSE 10
+#define _SYS_FS_WAIT 11
+#define _SYS_FS_RESPOND 12
+#define _SYS_MEMFLAG 13
+#define _SYS_PIPE 14
+#define _SYS_SLEEP 15
+#define _SYS_FILICIDE 16
+#define _SYS_INTR 17
+#define _SYS_INTR_SET 18
+
+#define _SYS_EXECBUF 100
+#define _SYS_DEBUG_KLOG 101
#ifndef ASM_FILE
#include <camellia/types.h>
@@ -31,12 +31,12 @@ long _syscall(long, long, long, long, long, long);
/** Kills the current process.
*/
-_Noreturn void _syscall_exit(long ret);
+_Noreturn void _sys_exit(long ret);
/** Waits for a child to exit.
* @return the value the child passed to exit()
*/
-long _syscall_await(void);
+long _sys_await(void);
/** Creates a copy of the current process, and executes it.
* All user memory pages get copied too.
@@ -46,20 +46,20 @@ long _syscall_await(void);
*
* @return 0 in the child, the CID in the parent.
*/
-long _syscall_fork(int flags, handle_t __user *fs_front);
+long _sys_fork(int flags, hid_t __user *fs_front);
-handle_t _syscall_open(const char __user *path, long len, int flags);
-long _syscall_mount(handle_t h, const char __user *path, long len);
-handle_t _syscall_dup(handle_t from, handle_t to, int flags);
+hid_t _sys_open(const char __user *path, long len, int flags);
+long _sys_mount(hid_t h, const char __user *path, long len);
+hid_t _sys_dup(hid_t from, hid_t to, int flags);
-long _syscall_read(handle_t h, void __user *buf, size_t len, long offset);
-long _syscall_write(handle_t h, const void __user *buf, size_t len, long offset, int flags);
-long _syscall_getsize(handle_t h);
-long _syscall_remove(handle_t h);
-long _syscall_close(handle_t h);
+long _sys_read(hid_t h, void __user *buf, size_t len, long offset);
+long _sys_write(hid_t h, const void __user *buf, size_t len, long offset, int flags);
+long _sys_getsize(hid_t h);
+long _sys_remove(hid_t h);
+long _sys_close(hid_t h);
-handle_t _syscall_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res);
-long _syscall_fs_respond(handle_t hid, const void __user *buf, long ret, int flags);
+hid_t _sys_fs_wait(char __user *buf, long max_len, struct ufs_request __user *res);
+long _sys_fs_respond(hid_t hid, const void __user *buf, long ret, int flags);
/** Modifies the virtual address space.
*
@@ -70,18 +70,18 @@ long _syscall_fs_respond(handle_t hid, const void __user *buf, long ret, int fla
*
* @return address of the first affected page (usually == addr)
*/
-void __user *_syscall_memflag(void __user *addr, size_t len, int flags);
-long _syscall_pipe(handle_t __user user_ends[2], int flags);
+void __user *_sys_memflag(void __user *addr, size_t len, int flags);
+long _sys_pipe(hid_t __user user_ends[2], int flags);
-void _syscall_sleep(long ms);
+void _sys_sleep(long ms);
-void _syscall_filicide(void);
-void _syscall_intr(void);
-void _syscall_intr_set(void __user *ip);
+void _sys_filicide(void);
+void _sys_intr(void);
+void _sys_intr_set(void __user *ip);
/* see shared/execbuf.h */
-long _syscall_execbuf(void __user *buf, size_t len);
+long _sys_execbuf(void __user *buf, size_t len);
-void _syscall_debug_klog(const void __user *buf, size_t len);
+void _sys_debug_klog(const void __user *buf, size_t len);
#endif
diff --git a/src/shared/include/camellia/types.h b/src/shared/include/camellia/types.h
index bd17e51..3b9cfb4 100644
--- a/src/shared/include/camellia/types.h
+++ b/src/shared/include/camellia/types.h
@@ -11,9 +11,9 @@
#endif
typedef void __user * userptr_t;
-typedef int handle_t;
+typedef int hid_t;
-enum vfs_operation {
+enum vfs_op {
VFSOP_OPEN,
VFSOP_READ,
VFSOP_WRITE,
@@ -23,7 +23,7 @@ enum vfs_operation {
};
struct ufs_request {
- enum vfs_operation op;
+ enum vfs_op op;
size_t len; // how much was put in *buf
size_t capacity; // how much output can be accepted by the caller
void __user *id; // file id (returned by the open handler, passed to other calls)
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) {