From 18667c48b0cf6497b50c00f00f474d79a68f59ce Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 26 Jul 2022 18:16:10 +0200 Subject: shared: move some headers from shared/ to camellia/ --- src/kernel/arch/amd64/driver/fsroot.c | 2 +- src/kernel/arch/amd64/paging.h | 2 +- src/kernel/arch/amd64/registers.h | 2 +- src/kernel/arch/amd64/sysenter.c | 2 +- src/kernel/arch/generic.h | 2 +- src/kernel/execbuf.c | 2 +- src/kernel/handle.h | 2 +- src/kernel/mem/virt.h | 2 +- src/kernel/proc.c | 2 +- src/kernel/proc.h | 2 +- src/kernel/syscalls.c | 4 +- src/kernel/vfs/request.c | 2 +- src/kernel/vfs/request.h | 4 +- src/shared/errno.h | 3 -- src/shared/execbuf.h | 7 --- src/shared/flags.h | 6 --- src/shared/include/camellia/errno.h | 3 ++ src/shared/include/camellia/execbuf.h | 7 +++ src/shared/include/camellia/flags.h | 6 +++ src/shared/include/camellia/syscalls.h | 93 ++++++++++++++++++++++++++++++++++ src/shared/include/camellia/types.h | 20 ++++++++ src/shared/syscalls.h | 93 ---------------------------------- src/shared/types.h | 20 -------- src/user/app/init/driver/ansiterm.c | 2 +- src/user/app/init/driver/ps2.c | 2 +- src/user/app/init/driver/termcook.c | 2 +- src/user/app/init/driver/tmpfs.c | 2 +- src/user/app/init/main.c | 4 +- src/user/app/init/shell.c | 2 +- src/user/app/init/tests/main.c | 8 +-- src/user/app/init/tests/pipe.c | 4 +- src/user/app/init/tests/semaphore.c | 4 +- src/user/app/init/tests/stress.c | 4 +- src/user/app/testelf/main.c | 2 +- src/user/bootstrap/main.c | 4 +- src/user/bootstrap/tar.c | 4 +- src/user/bootstrap/tar.h | 2 +- src/user/lib/elfload.c | 6 +-- src/user/lib/esemaphore.c | 4 +- src/user/lib/esemaphore.h | 2 +- src/user/lib/fs/misc.c | 4 +- src/user/lib/malloc.c | 4 +- src/user/lib/stdlib.c | 2 +- src/user/lib/stdlib.h | 2 +- src/user/lib/syscall.c | 2 +- src/user/lib/syscall.c.awk | 2 +- 46 files changed, 181 insertions(+), 181 deletions(-) delete mode 100644 src/shared/errno.h delete mode 100644 src/shared/execbuf.h delete mode 100644 src/shared/flags.h create mode 100644 src/shared/include/camellia/errno.h create mode 100644 src/shared/include/camellia/execbuf.h create mode 100644 src/shared/include/camellia/flags.h create mode 100644 src/shared/include/camellia/syscalls.h create mode 100644 src/shared/include/camellia/types.h delete mode 100644 src/shared/syscalls.h delete mode 100644 src/shared/types.h (limited to 'src') diff --git a/src/kernel/arch/amd64/driver/fsroot.c b/src/kernel/arch/amd64/driver/fsroot.c index d6e943f..1e3dc1f 100644 --- a/src/kernel/arch/amd64/driver/fsroot.c +++ b/src/kernel/arch/amd64/driver/fsroot.c @@ -1,10 +1,10 @@ +#include #include #include #include #include #include #include -#include #include #include diff --git a/src/kernel/arch/amd64/paging.h b/src/kernel/arch/amd64/paging.h index a676bb8..f8de339 100644 --- a/src/kernel/arch/amd64/paging.h +++ b/src/kernel/arch/amd64/paging.h @@ -1,5 +1,5 @@ #pragma once -#include +#include /* nitpick: I highly recommend you dont use bitfields for paging * structures diff --git a/src/kernel/arch/amd64/registers.h b/src/kernel/arch/amd64/registers.h index c98c647..5d88595 100644 --- a/src/kernel/arch/amd64/registers.h +++ b/src/kernel/arch/amd64/registers.h @@ -1,5 +1,5 @@ #pragma once -#include +#include #include struct registers { diff --git a/src/kernel/arch/amd64/sysenter.c b/src/kernel/arch/amd64/sysenter.c index 536ada9..b5cec73 100644 --- a/src/kernel/arch/amd64/sysenter.c +++ b/src/kernel/arch/amd64/sysenter.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include struct registers _sysexit_regs; diff --git a/src/kernel/arch/generic.h b/src/kernel/arch/generic.h index 941bfa4..4a4f632 100644 --- a/src/kernel/arch/generic.h +++ b/src/kernel/arch/generic.h @@ -1,7 +1,7 @@ #pragma once +#include #include -#include #include #include #include diff --git a/src/kernel/execbuf.c b/src/kernel/execbuf.c index 1e4d8ed..682566e 100644 --- a/src/kernel/execbuf.c +++ b/src/kernel/execbuf.c @@ -1,7 +1,7 @@ +#include #include #include #include -#include #include _Noreturn static void halt(struct process *proc) { diff --git a/src/kernel/handle.h b/src/kernel/handle.h index be8250b..233c2fa 100644 --- a/src/kernel/handle.h +++ b/src/kernel/handle.h @@ -2,8 +2,8 @@ enum handle_type; // forward declaration for proc.h +#include #include -#include #include enum handle_type { diff --git a/src/kernel/mem/virt.h b/src/kernel/mem/virt.h index cf22a75..1f9ef14 100644 --- a/src/kernel/mem/virt.h +++ b/src/kernel/mem/virt.h @@ -1,7 +1,7 @@ /* contains utilities for interacting with virtual memory */ #pragma once +#include #include -#include #include #include diff --git a/src/kernel/proc.c b/src/kernel/proc.c index 9f6f6b7..a8cf303 100644 --- a/src/kernel/proc.c +++ b/src/kernel/proc.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,7 +8,6 @@ #include #include #include -#include #include struct process *process_first; diff --git a/src/kernel/proc.h b/src/kernel/proc.h index c642a42..c7e885a 100644 --- a/src/kernel/proc.h +++ b/src/kernel/proc.h @@ -1,9 +1,9 @@ #pragma once +#include #include #include #include #include -#include #include #define HANDLE_MAX 16 diff --git a/src/kernel/syscalls.c b/src/kernel/syscalls.c index f884fd3..9c4e2fa 100644 --- a/src/kernel/syscalls.c +++ b/src/kernel/syscalls.c @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -5,9 +7,7 @@ #include #include #include -#include #include -#include #include #define SYSCALL_RETURN(val) do { \ diff --git a/src/kernel/vfs/request.c b/src/kernel/vfs/request.c index 102a7e8..377cb2c 100644 --- a/src/kernel/vfs/request.c +++ b/src/kernel/vfs/request.c @@ -1,10 +1,10 @@ +#include #include #include #include #include #include #include -#include #include void vfsreq_create(struct vfs_request req_) { diff --git a/src/kernel/vfs/request.h b/src/kernel/vfs/request.h index 4201d44..cb560c9 100644 --- a/src/kernel/vfs/request.h +++ b/src/kernel/vfs/request.h @@ -1,7 +1,7 @@ #pragma once +#include +#include #include -#include -#include #include #include diff --git a/src/shared/errno.h b/src/shared/errno.h deleted file mode 100644 index a0b5731..0000000 --- a/src/shared/errno.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define EFAULT 2 diff --git a/src/shared/execbuf.h b/src/shared/execbuf.h deleted file mode 100644 index c9d444d..0000000 --- a/src/shared/execbuf.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once -/* the instruction format is bound to change, atm it's extremely inefficient */ - -/* takes 5 arguments */ -#define EXECBUF_SYSCALL 0xF0000001 -/* takes 1 argument, changes %rip */ -#define EXECBUF_JMP 0xF0000002 diff --git a/src/shared/flags.h b/src/shared/flags.h deleted file mode 100644 index dd20a3f..0000000 --- a/src/shared/flags.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -enum { - MEMFLAG_PRESENT = 1 << 0, - MEMFLAG_FINDFREE = 1 << 1, -}; diff --git a/src/shared/include/camellia/errno.h b/src/shared/include/camellia/errno.h new file mode 100644 index 0000000..a0b5731 --- /dev/null +++ b/src/shared/include/camellia/errno.h @@ -0,0 +1,3 @@ +#pragma once + +#define EFAULT 2 diff --git a/src/shared/include/camellia/execbuf.h b/src/shared/include/camellia/execbuf.h new file mode 100644 index 0000000..c9d444d --- /dev/null +++ b/src/shared/include/camellia/execbuf.h @@ -0,0 +1,7 @@ +#pragma once +/* the instruction format is bound to change, atm it's extremely inefficient */ + +/* takes 5 arguments */ +#define EXECBUF_SYSCALL 0xF0000001 +/* takes 1 argument, changes %rip */ +#define EXECBUF_JMP 0xF0000002 diff --git a/src/shared/include/camellia/flags.h b/src/shared/include/camellia/flags.h new file mode 100644 index 0000000..dd20a3f --- /dev/null +++ b/src/shared/include/camellia/flags.h @@ -0,0 +1,6 @@ +#pragma once + +enum { + MEMFLAG_PRESENT = 1 << 0, + MEMFLAG_FINDFREE = 1 << 1, +}; diff --git a/src/shared/include/camellia/syscalls.h b/src/shared/include/camellia/syscalls.h new file mode 100644 index 0000000..e835c91 --- /dev/null +++ b/src/shared/include/camellia/syscalls.h @@ -0,0 +1,93 @@ +#pragma once +#include +#include + +#define FORK_NOREAP 1 +#define FORK_NEWFS 2 +#define OPEN_CREATE 1 +#define FSR_DELEGATE 1 + +enum { + // idc about stable syscall numbers just yet + _SYSCALL_EXIT, + _SYSCALL_AWAIT, + _SYSCALL_FORK, + + _SYSCALL_OPEN, + _SYSCALL_MOUNT, + _SYSCALL_DUP, + + _SYSCALL_READ, + _SYSCALL_WRITE, + _SYSCALL_CLOSE, + + _SYSCALL_FS_FORK2, + _SYSCALL_FS_WAIT, + _SYSCALL_FS_RESPOND, + + _SYSCALL_MEMFLAG, + _SYSCALL_PIPE, + + _SYSCALL_EXECBUF, + + _SYSCALL_DEBUG_KLOG, +}; + +long _syscall(long, long, long, long, long); + +/** Kills the current process. + */ +_Noreturn void _syscall_exit(long ret); + +/** Waits for a child to exit. + * @return the value the child passed to exit() + */ +long _syscall_await(void); + +/** Creates a copy of the current process, and executes it. + * All user memory pages get copied too. + * + * @param flags FORK_NOREAP, FORK_NEWFS + * @param fs_front requires FORK_NEWFS. the front handle to the new fs is put there + * + * @return 0 in the child, a meaningless positive value in the parent. + */ +long _syscall_fork(int flags, handle_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); + +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); +long _syscall_close(handle_t h); + +struct fs_wait_response { + enum vfs_operation 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) + long offset; + int flags; +}; +/** Blocks until an fs request is made. + * @return 0 if everything was successful */ +long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res); +long _syscall_fs_respond(void __user *buf, long ret, int flags); + +/** Modifies the virtual address space. + * + * If the MEMFLAG_PRESENT flag is present - mark the memory region as allocated. + * Otherwise, free it. + * + * MEMFLAG_FINDFREE tries to find the first free region of length `len`. + * + * @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); + +/* see shared/execbuf.h */ +long _syscall_execbuf(void __user *buf, size_t len); + +void _syscall_debug_klog(const void __user *buf, size_t len); diff --git a/src/shared/include/camellia/types.h b/src/shared/include/camellia/types.h new file mode 100644 index 0000000..f47e1bb --- /dev/null +++ b/src/shared/include/camellia/types.h @@ -0,0 +1,20 @@ +#pragma once +#include + +#ifdef __CHECKER__ +# define __user __attribute__((noderef, address_space(__user))) +# define __force __attribute__((force)) +#else +# define __user +# define __force +#endif + +typedef void __user * userptr_t; +typedef int handle_t; + +enum vfs_operation { + VFSOP_OPEN, + VFSOP_READ, + VFSOP_WRITE, + VFSOP_CLOSE, +}; diff --git a/src/shared/syscalls.h b/src/shared/syscalls.h deleted file mode 100644 index e3b879e..0000000 --- a/src/shared/syscalls.h +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once -#include -#include - -#define FORK_NOREAP 1 -#define FORK_NEWFS 2 -#define OPEN_CREATE 1 -#define FSR_DELEGATE 1 - -enum { - // idc about stable syscall numbers just yet - _SYSCALL_EXIT, - _SYSCALL_AWAIT, - _SYSCALL_FORK, - - _SYSCALL_OPEN, - _SYSCALL_MOUNT, - _SYSCALL_DUP, - - _SYSCALL_READ, - _SYSCALL_WRITE, - _SYSCALL_CLOSE, - - _SYSCALL_FS_FORK2, - _SYSCALL_FS_WAIT, - _SYSCALL_FS_RESPOND, - - _SYSCALL_MEMFLAG, - _SYSCALL_PIPE, - - _SYSCALL_EXECBUF, - - _SYSCALL_DEBUG_KLOG, -}; - -long _syscall(long, long, long, long, long); - -/** Kills the current process. - */ -_Noreturn void _syscall_exit(long ret); - -/** Waits for a child to exit. - * @return the value the child passed to exit() - */ -long _syscall_await(void); - -/** Creates a copy of the current process, and executes it. - * All user memory pages get copied too. - * - * @param flags FORK_NOREAP, FORK_NEWFS - * @param fs_front requires FORK_NEWFS. the front handle to the new fs is put there - * - * @return 0 in the child, a meaningless positive value in the parent. - */ -long _syscall_fork(int flags, handle_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); - -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); -long _syscall_close(handle_t h); - -struct fs_wait_response { - enum vfs_operation 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) - long offset; - int flags; -}; -/** Blocks until an fs request is made. - * @return 0 if everything was successful */ -long _syscall_fs_wait(char __user *buf, long max_len, struct fs_wait_response __user *res); -long _syscall_fs_respond(void __user *buf, long ret, int flags); - -/** Modifies the virtual address space. - * - * If the MEMFLAG_PRESENT flag is present - mark the memory region as allocated. - * Otherwise, free it. - * - * MEMFLAG_FINDFREE tries to find the first free region of length `len`. - * - * @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); - -/* see shared/execbuf.h */ -long _syscall_execbuf(void __user *buf, size_t len); - -void _syscall_debug_klog(const void __user *buf, size_t len); diff --git a/src/shared/types.h b/src/shared/types.h deleted file mode 100644 index f47e1bb..0000000 --- a/src/shared/types.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include - -#ifdef __CHECKER__ -# define __user __attribute__((noderef, address_space(__user))) -# define __force __attribute__((force)) -#else -# define __user -# define __force -#endif - -typedef void __user * userptr_t; -typedef int handle_t; - -enum vfs_operation { - VFSOP_OPEN, - VFSOP_READ, - VFSOP_WRITE, - VFSOP_CLOSE, -}; diff --git a/src/user/app/init/driver/ansiterm.c b/src/user/app/init/driver/ansiterm.c index 8206e85..dde2183 100644 --- a/src/user/app/init/driver/ansiterm.c +++ b/src/user/app/init/driver/ansiterm.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/user/app/init/driver/ps2.c b/src/user/app/init/driver/ps2.c index 9bbab8e..45458c8 100644 --- a/src/user/app/init/driver/ps2.c +++ b/src/user/app/init/driver/ps2.c @@ -1,5 +1,5 @@ +#include #include -#include #include #include diff --git a/src/user/app/init/driver/termcook.c b/src/user/app/init/driver/termcook.c index 2ddd3f9..868d5d3 100644 --- a/src/user/app/init/driver/termcook.c +++ b/src/user/app/init/driver/termcook.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/src/user/app/init/driver/tmpfs.c b/src/user/app/init/driver/tmpfs.c index c6cc0f3..200e62d 100644 --- a/src/user/app/init/driver/tmpfs.c +++ b/src/user/app/init/driver/tmpfs.c @@ -1,5 +1,5 @@ +#include #include -#include #include #include diff --git a/src/user/app/init/main.c b/src/user/app/init/main.c index 4c4bf4e..772a9e3 100644 --- a/src/user/app/init/main.c +++ b/src/user/app/init/main.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include #include diff --git a/src/user/app/init/shell.c b/src/user/app/init/shell.c index f420208..76a0dbc 100644 --- a/src/user/app/init/shell.c +++ b/src/user/app/init/shell.c @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/src/user/app/init/tests/main.c b/src/user/app/init/tests/main.c index 015a3be..4f8e858 100644 --- a/src/user/app/init/tests/main.c +++ b/src/user/app/init/tests/main.c @@ -1,8 +1,8 @@ #define TEST_MACROS -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/user/app/init/tests/pipe.c b/src/user/app/init/tests/pipe.c index 54025d0..227007a 100644 --- a/src/user/app/init/tests/pipe.c +++ b/src/user/app/init/tests/pipe.c @@ -1,6 +1,6 @@ #define TEST_MACROS -#include -#include +#include +#include #include #include diff --git a/src/user/app/init/tests/semaphore.c b/src/user/app/init/tests/semaphore.c index 66ea4ba..b55db9e 100644 --- a/src/user/app/init/tests/semaphore.c +++ b/src/user/app/init/tests/semaphore.c @@ -1,6 +1,6 @@ #define TEST_MACROS -#include -#include +#include +#include #include #include #include diff --git a/src/user/app/init/tests/stress.c b/src/user/app/init/tests/stress.c index 9af1706..f797611 100644 --- a/src/user/app/init/tests/stress.c +++ b/src/user/app/init/tests/stress.c @@ -1,6 +1,6 @@ #define TEST_MACROS -#include -#include +#include +#include #include #include diff --git a/src/user/app/testelf/main.c b/src/user/app/testelf/main.c index a80d233..8c5b6a4 100644 --- a/src/user/app/testelf/main.c +++ b/src/user/app/testelf/main.c @@ -1,5 +1,5 @@ +#include #include -#include #include #include #include diff --git a/src/user/bootstrap/main.c b/src/user/bootstrap/main.c index 5f36aa1..fecd38f 100644 --- a/src/user/bootstrap/main.c +++ b/src/user/bootstrap/main.c @@ -1,6 +1,6 @@ -#include +#include +#include #include -#include #include #include diff --git a/src/user/bootstrap/tar.c b/src/user/bootstrap/tar.c index 40da437..a392f4c 100644 --- a/src/user/bootstrap/tar.c +++ b/src/user/bootstrap/tar.c @@ -1,6 +1,6 @@ -#include +#include +#include #include -#include #include #include "tar.h" diff --git a/src/user/bootstrap/tar.h b/src/user/bootstrap/tar.h index 43aa9ed..fe4d6c5 100644 --- a/src/user/bootstrap/tar.h +++ b/src/user/bootstrap/tar.h @@ -1,5 +1,5 @@ #pragma once -#include +#include _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/elfload.c b/src/user/lib/elfload.c index ef14388..45ce2a0 100644 --- a/src/user/lib/elfload.c +++ b/src/user/lib/elfload.c @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/user/lib/esemaphore.c b/src/user/lib/esemaphore.c index 1230274..1da418e 100644 --- a/src/user/lib/esemaphore.c +++ b/src/user/lib/esemaphore.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include diff --git a/src/user/lib/esemaphore.h b/src/user/lib/esemaphore.h index e746bd7..4a16c2e 100644 --- a/src/user/lib/esemaphore.h +++ b/src/user/lib/esemaphore.h @@ -1,5 +1,5 @@ #pragma once -#include +#include struct evil_sem { handle_t wait, signal; diff --git a/src/user/lib/fs/misc.c b/src/user/lib/fs/misc.c index 3631e35..99993ed 100644 --- a/src/user/lib/fs/misc.c +++ b/src/user/lib/fs/misc.c @@ -1,6 +1,6 @@ -#include +#include +#include #include -#include #include #include #include diff --git a/src/user/lib/malloc.c b/src/user/lib/malloc.c index 40ae917..bb6b653 100644 --- a/src/user/lib/malloc.c +++ b/src/user/lib/malloc.c @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include #include diff --git a/src/user/lib/stdlib.c b/src/user/lib/stdlib.c index e947486..943af01 100644 --- a/src/user/lib/stdlib.c +++ b/src/user/lib/stdlib.c @@ -1,5 +1,5 @@ +#include #include -#include #include // TODO oh god this garbage - malloc, actually open, [...] diff --git a/src/user/lib/stdlib.h b/src/user/lib/stdlib.h index 1982e85..64fbbe6 100644 --- a/src/user/lib/stdlib.h +++ b/src/user/lib/stdlib.h @@ -1,6 +1,6 @@ #pragma once +#include #include -#include #include #include #include diff --git a/src/user/lib/syscall.c b/src/user/lib/syscall.c index e105638..7e0de88 100644 --- a/src/user/lib/syscall.c +++ b/src/user/lib/syscall.c @@ -2,7 +2,7 @@ * don't modify manually, instead run: * make src/user/lib/syscall.c */ -#include +#include _Noreturn void _syscall_exit(long ret) { diff --git a/src/user/lib/syscall.c.awk b/src/user/lib/syscall.c.awk index 91e4665..58f9a4c 100644 --- a/src/user/lib/syscall.c.awk +++ b/src/user/lib/syscall.c.awk @@ -4,7 +4,7 @@ BEGIN { * don't modify manually, instead run:\n\ * make src/user/lib/syscall.c\n\ */\n\ -#include \n\ +#include \n\ \n"; } -- cgit v1.2.3