summaryrefslogtreecommitdiff
path: root/src/shared/include
diff options
context:
space:
mode:
authordzwdz2022-07-26 18:16:10 +0200
committerdzwdz2022-07-26 18:16:10 +0200
commit18667c48b0cf6497b50c00f00f474d79a68f59ce (patch)
tree83029f59242d6b5f5d486284e6542a31f0cda415 /src/shared/include
parent13519597d98c9271b7856242d5625896d18803c5 (diff)
shared: move some headers from shared/ to camellia/
Diffstat (limited to 'src/shared/include')
-rw-r--r--src/shared/include/camellia/errno.h3
-rw-r--r--src/shared/include/camellia/execbuf.h7
-rw-r--r--src/shared/include/camellia/flags.h6
-rw-r--r--src/shared/include/camellia/syscalls.h93
-rw-r--r--src/shared/include/camellia/types.h20
5 files changed, 129 insertions, 0 deletions
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 <camellia/types.h>
+#include <stddef.h>
+
+#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 <stdint.h>
+
+#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,
+};