summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordzwdz2022-07-26 22:21:52 +0200
committerdzwdz2022-07-26 22:34:22 +0200
commitd54dcb2efc4be344900a7721ac4b65b47840c5d2 (patch)
tree8d0b2a5158809fe64a40e3b362c01f1b2f22772e /src
parent059ef013683e780a6603b228cd1fd8391d11494e (diff)
user/libc: exit()
What an interesting commit.
Diffstat (limited to 'src')
-rw-r--r--src/user/app/init/driver/ansiterm.c3
-rw-r--r--src/user/app/init/driver/ps2.c5
-rw-r--r--src/user/app/init/driver/termcook.c2
-rw-r--r--src/user/app/init/driver/tmpfs.c3
-rw-r--r--src/user/app/init/main.c16
-rw-r--r--src/user/app/init/shell.c8
-rw-r--r--src/user/app/init/tests/main.c20
-rw-r--r--src/user/app/init/tests/pipe.c10
-rw-r--r--src/user/app/init/tests/semaphore.c6
-rw-r--r--src/user/app/init/tests/stress.c4
-rw-r--r--src/user/app/init/tests/tests.h2
-rw-r--r--src/user/app/testelf/main.c3
-rw-r--r--src/user/bootstrap/tar.c6
-rw-r--r--src/user/bootstrap/tar.h1
-rw-r--r--src/user/lib/esemaphore.c4
-rw-r--r--src/user/lib/fs/misc.c12
-rw-r--r--src/user/lib/include/unistd.h1
-rw-r--r--src/user/lib/stdlib.c4
18 files changed, 60 insertions, 50 deletions
diff --git a/src/user/app/init/driver/ansiterm.c b/src/user/app/init/driver/ansiterm.c
index 4b66d6f..b5d3772 100644
--- a/src/user/app/init/driver/ansiterm.c
+++ b/src/user/app/init/driver/ansiterm.c
@@ -1,6 +1,7 @@
#include "driver.h"
#include <camellia/syscalls.h>
#include <stdbool.h>
+#include <unistd.h>
struct vga_cell {
unsigned char c;
@@ -95,5 +96,5 @@ void ansiterm_drv(void) {
}
}
- _syscall_exit(1);
+ exit(1);
}
diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c
index 6aed2fb..532695f 100644
--- a/src/user/app/init/driver/ps2.c
+++ b/src/user/app/init/driver/ps2.c
@@ -2,6 +2,7 @@
#include <camellia/syscalls.h>
#include <shared/container/ring.h>
#include <stdbool.h>
+#include <unistd.h>
static const char keymap_lower[] = {
@@ -79,8 +80,8 @@ static void main_loop(void) {
void ps2_drv(void) {
fd = _syscall_open("/kdev/ps2", 9, 0);
- if (fd < 0) _syscall_exit(1);
+ if (fd < 0) exit(1);
main_loop();
- _syscall_exit(0);
+ exit(0);
}
diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c
index 59cef77..3dc6f32 100644
--- a/src/user/app/init/driver/termcook.c
+++ b/src/user/app/init/driver/termcook.c
@@ -63,7 +63,7 @@ void termcook(void) {
if (!fork()) {
close(stdin_pipe[0]);
line_editor(0, stdin_pipe[1]);
- _syscall_exit(0);
+ exit(0);
}
/* 0 is stdin, like in unix */
_syscall_dup(stdin_pipe[0], 0, 0);
diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c
index 83c42c7..d9f73ab 100644
--- a/src/user/app/init/driver/tmpfs.c
+++ b/src/user/app/init/driver/tmpfs.c
@@ -2,6 +2,7 @@
#include <shared/mem.h>
#include <stddef.h>
#include <stdlib.h>
+#include <unistd.h>
struct node {
const char *name;
@@ -128,5 +129,5 @@ void tmpfs_drv(void) {
}
}
- _syscall_exit(1);
+ exit(1);
}
diff --git a/src/user/app/init/main.c b/src/user/app/init/main.c
index 71220af..426933f 100644
--- a/src/user/app/init/main.c
+++ b/src/user/app/init/main.c
@@ -38,40 +38,40 @@ int main(void) {
* of a dead process, which is invalid state
*/
_syscall_await();
- _syscall_exit(1);
+ exit(1);
}
if (!fork()) {
if (!freopen("/kdev/com1", "a+", stdout)) {
printf("couldn't open /kdev/com1\n"); // TODO borked
- _syscall_exit(1);
+ exit(1);
}
if (!freopen("/kdev/com1", "r", stdin)) {
printf("couldn't open /kdev/com1\n");
- _syscall_exit(1);
+ exit(1);
}
termcook();
shell_loop();
- _syscall_exit(1);
+ exit(1);
}
if (!fork()) {
if (!freopen("/vga_tty", "a+", stdout)) {
printf("couldn't open /vga_tty\n"); // TODO borked
- _syscall_exit(1);
+ exit(1);
}
if (!freopen("/keyboard", "r", stdin)) {
printf("couldn't open /keyboard\n");
- _syscall_exit(1);
+ exit(1);
}
termcook();
shell_loop();
- _syscall_exit(1);
+ exit(1);
}
_syscall_await();
printf("init: quitting\n");
- _syscall_exit(0);
+ exit(0);
}
diff --git a/src/user/app/init/shell.c b/src/user/app/init/shell.c
index e53d7d9..85e56e1 100644
--- a/src/user/app/init/shell.c
+++ b/src/user/app/init/shell.c
@@ -136,7 +136,7 @@ void shell_loop(void) {
readline(buf, 256);
if (feof(stdin))
- _syscall_exit(0);
+ exit(0);
redir = strtrim(strsplit(buf, '>'));
cmd = strtrim(buf);
args = strtrim(strsplit(cmd, 0));
@@ -146,7 +146,7 @@ void shell_loop(void) {
_syscall_mount(-1, args, strlen(args));
continue;
} else if (!strcmp(cmd, "exit")) {
- _syscall_exit(0);
+ exit(0);
continue;
} else if (!strcmp(cmd, "fork")) {
if (!fork()) level++;
@@ -157,7 +157,7 @@ void shell_loop(void) {
if (!fork()) {
if (redir && !freopen(redir, "w", stdout)) {
// TODO stderr
- _syscall_exit(0);
+ exit(0);
}
if (!strcmp(cmd, "echo")) {
@@ -196,7 +196,7 @@ void shell_loop(void) {
} else {
printf("unknown command :(\n");
}
- _syscall_exit(0);
+ exit(0);
} else {
_syscall_await();
}
diff --git a/src/user/app/init/tests/main.c b/src/user/app/init/tests/main.c
index cf59925..7036965 100644
--- a/src/user/app/init/tests/main.c
+++ b/src/user/app/init/tests/main.c
@@ -11,7 +11,7 @@
static void run_forked(void (*fn)()) {
if (!fork()) {
fn();
- _syscall_exit(0);
+ exit(0);
} else {
/* successful tests must return 0
* TODO add a better fail msg */
@@ -30,7 +30,7 @@ static void test_await(void) {
for (int i = 0; i < 16; i++)
if (!fork())
- _syscall_exit(i);
+ exit(i);
while ((ret = _syscall_await()) != ~0) {
assert(0 <= ret && ret < 16);
@@ -50,12 +50,12 @@ static void test_faults(void) {
if (!fork()) { // invalid memory access
asm volatile("movb $69, 0" ::: "memory");
printf("this shouldn't happen");
- _syscall_exit(-1);
+ exit(-1);
}
if (!fork()) { // #GP
asm volatile("hlt" ::: "memory");
printf("this shouldn't happen");
- _syscall_exit(-1);
+ exit(-1);
}
while (_syscall_await() != ~0) await_cnt++;
@@ -68,24 +68,24 @@ static void test_interrupted_fs(void) {
// TODO make a similar test with all 0s passed to fs_wait
struct fs_wait_response res;
_syscall_fs_wait(NULL, 0, &res);
- _syscall_exit(0);
+ exit(0);
} else { /* parent */
_syscall_mount(h, "/", 1);
int ret = _syscall_open("/", 1, 0);
// the handler quits while handling that call - but this syscall should return anyways
- _syscall_exit(ret < 0 ? 0 : -1);
+ exit(ret < 0 ? 0 : -1);
}
}
static void test_orphaned_fs(void) {
handle_t h;
if (_syscall_fork(FORK_NEWFS, &h)) { /* child */
- _syscall_exit(0);
+ exit(0);
} else { /* parent */
_syscall_mount(h, "/", 1);
int ret = _syscall_open("/", 1, 0);
// no handler will ever be available to handle this call - the syscall should instantly return
- _syscall_exit(ret < 0 ? 0 : -1);
+ exit(ret < 0 ? 0 : -1);
}
}
@@ -97,7 +97,7 @@ static void test_memflag(void) {
if (!fork()) {
memset(page, 11, 4096); // should segfault
- _syscall_exit(0);
+ exit(0);
} else {
assert(_syscall_await() != 0); // test if the process crashed
}
@@ -156,7 +156,7 @@ static void test_dup(void) {
_syscall_write(h1, "h1", 2, 0);
close(h1);
- _syscall_exit(0);
+ exit(0);
} else {
char buf[16];
size_t count = 0;
diff --git a/src/user/app/init/tests/pipe.c b/src/user/app/init/tests/pipe.c
index f7005f8..d6e954a 100644
--- a/src/user/app/init/tests/pipe.c
+++ b/src/user/app/init/tests/pipe.c
@@ -28,7 +28,7 @@ void test_pipe(void) {
ret = _syscall_write(ends[1], pipe_msgs[1], 5, -1);
assert(ret == 5);
- _syscall_exit(0);
+ exit(0);
} else {
assert(_syscall_read(ends[1], buf, 16, 0) < 0);
assert(_syscall_write(ends[0], buf, 16, 0) < 0);
@@ -56,7 +56,7 @@ void test_pipe(void) {
if (!fork()) {
close(ends[1]);
assert(_syscall_read(ends[0], buf, 16, 0) < 0);
- _syscall_exit(0);
+ exit(0);
}
}
close(ends[1]);
@@ -69,7 +69,7 @@ void test_pipe(void) {
if (!fork()) {
close(ends[0]);
assert(_syscall_write(ends[1], buf, 16, 0) < 0);
- _syscall_exit(0);
+ exit(0);
}
}
close(ends[0]);
@@ -83,7 +83,7 @@ void test_pipe(void) {
for (int i = 0; i < 16; i++) {
if (!fork()) {
assert(_syscall_write(ends[1], pipe_msgs[0], 5, -1) == 5);
- _syscall_exit(0);
+ exit(0);
}
}
close(ends[1]);
@@ -100,7 +100,7 @@ void test_pipe(void) {
memset(buf, 0, sizeof buf);
assert(_syscall_read(ends[0], buf, 5, -1) == 5);
assert(!memcmp(buf, pipe_msgs[1], 5));
- _syscall_exit(0);
+ exit(0);
}
}
close(ends[0]);
diff --git a/src/user/app/init/tests/semaphore.c b/src/user/app/init/tests/semaphore.c
index fc0cc10..e05f2f9 100644
--- a/src/user/app/init/tests/semaphore.c
+++ b/src/user/app/init/tests/semaphore.c
@@ -45,7 +45,7 @@ void test_semaphore(void) {
assert(sem1 && sem2);
if (!fork()) {
odd(pipe[1], sem1, sem2);
- _syscall_exit(69);
+ exit(69);
} else {
even(pipe[1], sem1, sem2);
assert(_syscall_await() == 69);
@@ -60,7 +60,7 @@ void test_semaphore(void) {
assert(sem1 && sem2);
if (!fork()) {
even(pipe[1], sem1, sem2);
- _syscall_exit(69);
+ exit(69);
} else {
odd(pipe[1], sem1, sem2);
assert(_syscall_await() == 69);
@@ -69,7 +69,7 @@ void test_semaphore(void) {
esem_free(sem1);
esem_free(sem2);
- _syscall_exit(0);
+ exit(0);
} else {
close(pipe[1]);
diff --git a/src/user/app/init/tests/stress.c b/src/user/app/init/tests/stress.c
index e620f0a..9be88d7 100644
--- a/src/user/app/init/tests/stress.c
+++ b/src/user/app/init/tests/stress.c
@@ -7,7 +7,7 @@
static void run_forked(void (*fn)()) {
if (!fork()) {
fn();
- _syscall_exit(0);
+ exit(0);
} else {
/* successful tests must return 0
* TODO add a better fail msg */
@@ -18,7 +18,7 @@ static void run_forked(void (*fn)()) {
static void stress_fork(void) {
for (size_t i = 0; i < 2048; i++) {
- if (!fork()) _syscall_exit(0);
+ if (!fork()) exit(0);
_syscall_await();
}
}
diff --git a/src/user/app/init/tests/tests.h b/src/user/app/init/tests/tests.h
index 23ed1e3..39294eb 100644
--- a/src/user/app/init/tests/tests.h
+++ b/src/user/app/init/tests/tests.h
@@ -13,7 +13,7 @@ void test_semaphore(void);
#define argify(str) str, sizeof(str) - 1
#define test_fail() do { \
printf("\033[31m" "TEST FAILED: %s:%xh\n" "\033[0m", __func__, __LINE__); \
- _syscall_exit(0); \
+ exit(0); \
} while (0)
#define assert(cond) if (!(cond)) test_fail();
diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c
index de7b965..93a5e11 100644
--- a/src/user/app/testelf/main.c
+++ b/src/user/app/testelf/main.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <user/lib/elf.h>
#include <user/lib/elfload.h>
+#include <unistd.h>
const char *str = "Hello!\n", *str2 = "World.\n";
@@ -13,5 +14,5 @@ int main(void) {
printf("loaded at %x\n", &_image_base);
printf(str);
printf(str2);
- _syscall_exit(0);
+ exit(0);
}
diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c
index a392f4c..75883e6 100644
--- a/src/user/bootstrap/tar.c
+++ b/src/user/bootstrap/tar.c
@@ -1,9 +1,9 @@
+#include "tar.h"
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <shared/mem.h>
#include <stdint.h>
-
-#include "tar.h"
+#include <unistd.h>
#define BUF_SIZE 64
@@ -36,7 +36,7 @@ void tar_driver(void *base) {
break;
}
}
- _syscall_exit(0);
+ exit(0);
}
static void *tar_open(const char *path, int len, void *base, size_t base_len) {
diff --git a/src/user/bootstrap/tar.h b/src/user/bootstrap/tar.h
index fe4d6c5..e7ab130 100644
--- a/src/user/bootstrap/tar.h
+++ b/src/user/bootstrap/tar.h
@@ -1,5 +1,6 @@
#pragma once
#include <camellia/types.h>
+#include <stddef.h>
_Noreturn void tar_driver(void *base);
void *tar_find(const char *path, size_t path_len, void *base, size_t base_len);
diff --git a/src/user/lib/esemaphore.c b/src/user/lib/esemaphore.c
index 3a4a836..70cedae 100644
--- a/src/user/lib/esemaphore.c
+++ b/src/user/lib/esemaphore.c
@@ -26,10 +26,10 @@ struct evil_sem *esem_new(int value) {
while (_syscall_read(ends_signal[0], NULL, 0, 0) >= 0) {
if (!_syscall_fork(FORK_NOREAP, NULL)) {
_syscall_write(ends_wait[1], NULL, 0, 0);
- _syscall_exit(0);
+ exit(0);
}
}
- _syscall_exit(0);
+ exit(0);
}
close(ends_signal[0]);
close(ends_wait[1]);
diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c
index 3a248ec..3a732af 100644
--- a/src/user/lib/fs/misc.c
+++ b/src/user/lib/fs/misc.c
@@ -23,7 +23,7 @@ void fs_passthru(const char *prefix) {
const size_t buf_len = 1024;
char *buf = malloc(buf_len);
int prefix_len = prefix ? strlen(prefix) : 0;
- if (!buf) _syscall_exit(1);
+ if (!buf) exit(1);
while (!_syscall_fs_wait(buf, buf_len, &res)) {
switch (res.op) {
@@ -49,7 +49,7 @@ void fs_passthru(const char *prefix) {
break;
}
}
- _syscall_exit(0);
+ exit(0);
}
void fs_whitelist(const char **list) {
@@ -57,7 +57,7 @@ void fs_whitelist(const char **list) {
const size_t buf_len = 1024;
char *buf = malloc(buf_len);
bool allow;
- if (!buf) _syscall_exit(1);
+ if (!buf) exit(1);
while (!_syscall_fs_wait(buf, buf_len, &res)) {
switch (res.op) {
@@ -79,7 +79,7 @@ void fs_whitelist(const char **list) {
break;
}
}
- _syscall_exit(0);
+ exit(0);
}
@@ -96,7 +96,7 @@ void fs_dir_inject(const char *path) {
char *buf = malloc(buf_len);
int ret, inject_len;
- if (!buf) _syscall_exit(1);
+ if (!buf) exit(1);
while (!_syscall_fs_wait(buf, buf_len, &res)) {
data = res.id;
@@ -162,5 +162,5 @@ void fs_dir_inject(const char *path) {
break;
}
}
- _syscall_exit(0);
+ exit(0);
}
diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h
index 4a30298..b825e45 100644
--- a/src/user/lib/include/unistd.h
+++ b/src/user/lib/include/unistd.h
@@ -3,3 +3,4 @@
int fork(void);
int close(handle_t h);
+_Noreturn void exit(int);
diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c
index 6f276bd..068635b 100644
--- a/src/user/lib/stdlib.c
+++ b/src/user/lib/stdlib.c
@@ -10,3 +10,7 @@ int fork(void) {
int close(handle_t h) {
return _syscall_close(h);
}
+
+_Noreturn void exit(int c) {
+ _syscall_exit(c);
+}