diff options
Diffstat (limited to 'src/user')
25 files changed, 68 insertions, 48 deletions
diff --git a/src/user/app/init/driver/ansiterm.c b/src/user/app/init/driver/ansiterm.c index dde2183..4b66d6f 100644 --- a/src/user/app/init/driver/ansiterm.c +++ b/src/user/app/init/driver/ansiterm.c @@ -1,6 +1,6 @@ +#include "driver.h" #include <camellia/syscalls.h> #include <stdbool.h> -#include <user/app/init/driver/driver.h> struct vga_cell { unsigned char c; diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c index 45458c8..6aed2fb 100644 --- a/src/user/app/init/driver/ps2.c +++ b/src/user/app/init/driver/ps2.c @@ -1,7 +1,7 @@ +#include "driver.h" #include <camellia/syscalls.h> #include <shared/container/ring.h> #include <stdbool.h> -#include <user/app/init/driver/driver.h> static const char keymap_lower[] = { diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c index 868d5d3..59cef77 100644 --- a/src/user/app/init/driver/termcook.c +++ b/src/user/app/init/driver/termcook.c @@ -1,6 +1,7 @@ +#include "driver.h" #include <camellia/syscalls.h> -#include <user/app/init/driver/driver.h> -#include <user/lib/stdlib.h> +#include <stdio.h> +#include <unistd.h> static void w_output(handle_t output, const char *buf, size_t len) { size_t pos = 0; diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c index 200e62d..83c42c7 100644 --- a/src/user/app/init/driver/tmpfs.c +++ b/src/user/app/init/driver/tmpfs.c @@ -1,7 +1,7 @@ #include <camellia/syscalls.h> #include <shared/mem.h> #include <stddef.h> -#include <user/lib/malloc.h> +#include <stdlib.h> struct node { const char *name; diff --git a/src/user/app/init/main.c b/src/user/app/init/main.c index 772a9e3..9c664a0 100644 --- a/src/user/app/init/main.c +++ b/src/user/app/init/main.c @@ -1,18 +1,15 @@ +#include "driver/driver.h" #include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdint.h> -#include <user/app/init/driver/driver.h> -#include <user/app/init/shell.h> -#include <user/app/init/tests/main.h> +#include <stdio.h> +#include <unistd.h> #include <user/lib/elfload.h> #include <user/lib/fs/misc.h> -#include <user/lib/stdlib.h> __attribute__((visibility("hidden"))) extern char _image_base[]; -void read_file(const char *path, size_t len); - __attribute__((section(".text.startup"))) int main(void) { elf_selfreloc(); diff --git a/src/user/app/init/shell.c b/src/user/app/init/shell.c index 76a0dbc..0c8b9b4 100644 --- a/src/user/app/init/shell.c +++ b/src/user/app/init/shell.c @@ -1,9 +1,11 @@ +#include "shell.h" +#include "tests/tests.h" #include <camellia/syscalls.h> #include <stdbool.h> -#include <user/app/init/shell.h> -#include <user/app/init/tests/main.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> #include <user/lib/elfload.h> -#include <user/lib/stdlib.h> static bool isspace(char c) { return c == ' ' || c == '\t' || c == '\n'; diff --git a/src/user/app/init/tests/main.c b/src/user/app/init/tests/main.c index 4f8e858..cf59925 100644 --- a/src/user/app/init/tests/main.c +++ b/src/user/app/init/tests/main.c @@ -1,10 +1,12 @@ #define TEST_MACROS +#include "tests.h" #include <camellia/errno.h> #include <camellia/execbuf.h> #include <camellia/flags.h> #include <camellia/syscalls.h> -#include <user/app/init/tests/main.h> -#include <user/lib/stdlib.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> static void run_forked(void (*fn)()) { if (!fork()) { diff --git a/src/user/app/init/tests/pipe.c b/src/user/app/init/tests/pipe.c index 227007a..f7005f8 100644 --- a/src/user/app/init/tests/pipe.c +++ b/src/user/app/init/tests/pipe.c @@ -1,8 +1,9 @@ #define TEST_MACROS +#include "tests.h" #include <camellia/flags.h> #include <camellia/syscalls.h> -#include <user/app/init/tests/main.h> -#include <user/lib/stdlib.h> +#include <string.h> +#include <unistd.h> static const char *pipe_msgs[2] = {"hello", "world"}; diff --git a/src/user/app/init/tests/semaphore.c b/src/user/app/init/tests/semaphore.c index b55db9e..fc0cc10 100644 --- a/src/user/app/init/tests/semaphore.c +++ b/src/user/app/init/tests/semaphore.c @@ -1,9 +1,11 @@ #define TEST_MACROS +#include "tests.h" #include <camellia/flags.h> #include <camellia/syscalls.h> -#include <user/app/init/tests/main.h> +#include <stdio.h> +#include <string.h> +#include <unistd.h> #include <user/lib/esemaphore.h> -#include <user/lib/stdlib.h> static void odd(handle_t out, struct evil_sem *sem1, struct evil_sem *sem2) { _syscall_write(out, "1", 1, -1); diff --git a/src/user/app/init/tests/stress.c b/src/user/app/init/tests/stress.c index f797611..e620f0a 100644 --- a/src/user/app/init/tests/stress.c +++ b/src/user/app/init/tests/stress.c @@ -1,8 +1,8 @@ #define TEST_MACROS +#include "tests.h" #include <camellia/flags.h> #include <camellia/syscalls.h> -#include <user/app/init/tests/main.h> -#include <user/lib/stdlib.h> +#include <unistd.h> static void run_forked(void (*fn)()) { if (!fork()) { diff --git a/src/user/app/init/tests/main.h b/src/user/app/init/tests/tests.h index ed11c5e..23ed1e3 100644 --- a/src/user/app/init/tests/main.h +++ b/src/user/app/init/tests/tests.h @@ -1,4 +1,6 @@ #pragma once +#include <camellia/syscalls.h> +#include <stdio.h> void stress_all(void); void test_all(void); diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c index 8c5b6a4..de7b965 100644 --- a/src/user/app/testelf/main.c +++ b/src/user/app/testelf/main.c @@ -1,8 +1,7 @@ #include <camellia/syscalls.h> -#include <shared/printf.h> +#include <stdio.h> #include <user/lib/elf.h> #include <user/lib/elfload.h> -#include <user/lib/stdlib.h> const char *str = "Hello!\n", *str2 = "World.\n"; diff --git a/src/user/lib/elfload.c b/src/user/lib/elfload.c index 45ce2a0..a30fd7c 100644 --- a/src/user/lib/elfload.c +++ b/src/user/lib/elfload.c @@ -1,6 +1,9 @@ #include <camellia/execbuf.h> #include <camellia/flags.h> #include <camellia/syscalls.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <user/lib/elf.h> #include <user/lib/elfload.h> diff --git a/src/user/lib/elfload.h b/src/user/lib/elfload.h index 40c4874..8310b3f 100644 --- a/src/user/lib/elfload.h +++ b/src/user/lib/elfload.h @@ -1,5 +1,5 @@ #pragma once -#include <user/lib/stdlib.h> +#include <bits/file.h> void elf_execf(libc_file *f); void elf_exec(void *elf); diff --git a/src/user/lib/elfreloc.c b/src/user/lib/elfreloc.c index 550fe97..b6e3844 100644 --- a/src/user/lib/elfreloc.c +++ b/src/user/lib/elfreloc.c @@ -1,5 +1,5 @@ +#include <stdio.h> #include <user/lib/elf.h> -#include <user/lib/stdlib.h> __attribute__((visibility("hidden"))) extern struct Elf64_Dyn _DYNAMIC[]; diff --git a/src/user/lib/esemaphore.c b/src/user/lib/esemaphore.c index 1da418e..3a4a836 100644 --- a/src/user/lib/esemaphore.c +++ b/src/user/lib/esemaphore.c @@ -1,7 +1,8 @@ #include <camellia/flags.h> #include <camellia/syscalls.h> +#include <stdlib.h> +#include <unistd.h> #include <user/lib/esemaphore.h> -#include <user/lib/stdlib.h> void esem_signal(struct evil_sem *sem) { _syscall_write(sem->signal, NULL, 0, 0); diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c index 99993ed..3a248ec 100644 --- a/src/user/lib/fs/misc.c +++ b/src/user/lib/fs/misc.c @@ -2,8 +2,11 @@ #include <camellia/syscalls.h> #include <shared/mem.h> #include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> #include <user/lib/fs/misc.h> -#include <user/lib/stdlib.h> bool fork2_n_mount(const char *path) { handle_t h; diff --git a/src/user/lib/fs/misc.h b/src/user/lib/fs/misc.h index 1e41956..0d9eb20 100644 --- a/src/user/lib/fs/misc.h +++ b/src/user/lib/fs/misc.h @@ -1,6 +1,6 @@ #pragma once #include <stdbool.h> -#include <user/lib/stdlib.h> +#include <stdio.h> bool fork2_n_mount(const char *path); diff --git a/src/user/lib/include/bits/file.h b/src/user/lib/include/bits/file.h new file mode 100644 index 0000000..d37b7de --- /dev/null +++ b/src/user/lib/include/bits/file.h @@ -0,0 +1,9 @@ +#pragma once +#include <stdbool.h> +// TODO make opaque +struct libc_file { + int fd; + int pos; + bool eof; +}; +typedef struct libc_file libc_file; diff --git a/src/user/lib/stdlib.h b/src/user/lib/include/stdio.h index 64fbbe6..291a194 100644 --- a/src/user/lib/stdlib.h +++ b/src/user/lib/include/stdio.h @@ -1,28 +1,18 @@ #pragma once -#include <camellia/types.h> -#include <shared/mem.h> -#include <stdbool.h> +#include <bits/file.h> #include <stddef.h> -#include <user/lib/malloc.h> int printf(const char *fmt, ...); int snprintf(char *str, size_t len, const char *fmt, ...); int _klogf(const char *fmt, ...); // for kernel debugging only -typedef struct { - int fd; - int pos; - bool eof; -} libc_file; + +extern libc_file *const stdin, *const stdout; + libc_file *file_open(const char *path, int flags); libc_file *file_reopen(libc_file*, const char *path, int flags); libc_file *file_clone(const libc_file*); int file_read(libc_file*, char *buf, size_t len); int file_write(libc_file*, const char *buf, size_t len); void file_close(libc_file*); - -extern libc_file *stdin, *stdout; - -int fork(void); -int close(handle_t h); diff --git a/src/user/lib/malloc.h b/src/user/lib/include/stdlib.h index 5916ebc..5916ebc 100644 --- a/src/user/lib/malloc.h +++ b/src/user/lib/include/stdlib.h diff --git a/src/user/lib/include/string.h b/src/user/lib/include/string.h new file mode 100644 index 0000000..e5c0255 --- /dev/null +++ b/src/user/lib/include/string.h @@ -0,0 +1 @@ +#include <shared/mem.h> diff --git a/src/user/lib/include/unistd.h b/src/user/lib/include/unistd.h new file mode 100644 index 0000000..4a30298 --- /dev/null +++ b/src/user/lib/include/unistd.h @@ -0,0 +1,5 @@ +#pragma once +#include <camellia/types.h> // TODO only needed because of handle_t + +int fork(void); +int close(handle_t h); diff --git a/src/user/lib/malloc.c b/src/user/lib/malloc.c index bb6b653..ea65d74 100644 --- a/src/user/lib/malloc.c +++ b/src/user/lib/malloc.c @@ -1,9 +1,8 @@ #include <camellia/flags.h> #include <camellia/syscalls.h> #include <stdbool.h> -#include <user/lib/malloc.h> - -#include <user/lib/stdlib.h> +#include <stdio.h> +#include <stdlib.h> #define MBLOCK_MAGIC 0x1337BABE diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c index 943af01..c998de7 100644 --- a/src/user/lib/stdlib.c +++ b/src/user/lib/stdlib.c @@ -1,12 +1,15 @@ #include <camellia/syscalls.h> #include <shared/printf.h> -#include <user/lib/stdlib.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> // TODO oh god this garbage - malloc, actually open, [...] static libc_file _stdin_null = { .fd = 0 }; static libc_file _stdout_null = { .fd = 1 }; -libc_file *stdin = &_stdin_null, *stdout = &_stdout_null; +libc_file *const stdin = &_stdin_null, *const stdout = &_stdout_null; static void backend_file(void *arg, const char *buf, size_t len) { file_write((libc_file*)arg, buf, len); |