summaryrefslogtreecommitdiff
path: root/src/init/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/init/main.c')
-rw-r--r--src/init/main.c50
1 files changed, 28 insertions, 22 deletions
diff --git a/src/init/main.c b/src/init/main.c
index 5c798d2..401e4a0 100644
--- a/src/init/main.c
+++ b/src/init/main.c
@@ -1,10 +1,10 @@
+#include <init/stdlib.h>
#include <init/tar.h>
#include <shared/flags.h>
#include <shared/syscalls.h>
#include <stdint.h>
#define argify(str) str, sizeof(str) - 1
-#define log(str) _syscall_write(tty_fd, argify(str), 0)
extern char _bss_start; // provided by the linker
extern char _bss_end;
@@ -23,7 +23,7 @@ int main(void) {
tty_fd = _syscall_open("/tty", sizeof("/tty") - 1);
if (tty_fd < 0)
- _syscall_exit(argify("couldn't open tty"));
+ _syscall_exit(1);
fs_test();
test_await();
@@ -32,7 +32,7 @@ int main(void) {
while (_syscall_read(tty_fd, &c, 1, 0))
_syscall_write(tty_fd, &c, 1, 0);
- _syscall_exit(argify("my job here is done."));
+ _syscall_exit(0);
}
void read_file(const char *path, size_t len) {
@@ -41,9 +41,9 @@ void read_file(const char *path, size_t len) {
int buf_len = 64;
_syscall_write(tty_fd, path, len, 0);
- log(": ");
+ printf(": ");
if (fd < 0) {
- log("couldn't open.\n");
+ printf("couldn't open.\n");
return;
}
@@ -64,7 +64,7 @@ void fs_test(void) {
}
// parent: accesses the fs
- log("\n\n");
+ printf("\n\n");
// the trailing slash should be ignored by mount()
_syscall_mount(front, argify("/init/"));
read_file(argify("/init/fake.txt"));
@@ -72,30 +72,36 @@ void fs_test(void) {
read_file(argify("/init/2.txt"));
read_file(argify("/init/dir/3.txt"));
- log("\nshadowing /init/dir...\n");
+ printf("\nshadowing /init/dir...\n");
_syscall_mount(-1, argify("/init/dir"));
read_file(argify("/init/fake.txt"));
read_file(argify("/init/1.txt"));
read_file(argify("/init/2.txt"));
read_file(argify("/init/dir/3.txt"));
- log("\n");
+ printf("\n");
}
void test_await(void) {
- char buf[16];
- int len;
-
- // the child immediately dies
- if (!_syscall_fork())
- _syscall_exit(argify("i'm dead"));
- if (!_syscall_fork())
- _syscall_exit(argify("i'm also dead"));
-
- while ((len = _syscall_await(buf, 16)) >= 0) {
- log("await returned: ");
- _syscall_write(tty_fd, buf, len, 0);
- log("\n");
+ int ret;
+
+ // regular exit()s
+ if (!_syscall_fork()) _syscall_exit(69);
+ if (!_syscall_fork()) _syscall_exit(420);
+
+ // faults
+ if (!_syscall_fork()) { // invalid memory access
+ asm volatile("movb $69, 0" ::: "memory");
+ printf("this shouldn't happen");
+ _syscall_exit(-1);
}
- log("await: negative len\n");
+ if (!_syscall_fork()) { // #GP
+ asm volatile("hlt" ::: "memory");
+ printf("this shouldn't happen");
+ _syscall_exit(-1);
+ }
+
+ while ((ret = _syscall_await()) != ~0)
+ printf("await returned: %x\n", ret);
+ printf("await: no more children\n");
}