aboutsummaryrefslogtreecommitdiff
path: root/include/apos
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-09-20 15:38:06 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-09-20 15:38:06 +0300
commitd2f2714398d415eb9a628aab82b332b92ad5c923 (patch)
treece6844c3f6f446b3acefffbd294dfecd3eb8dc98 /include/apos
parenta717296a2036cede5fccfff544513043a984d614 (diff)
downloadkmi-d2f2714398d415eb9a628aab82b332b92ad5c923.tar.gz
kmi-d2f2714398d415eb9a628aab82b332b92ad5c923.zip
add capability subsystem and syscalls
Diffstat (limited to 'include/apos')
-rw-r--r--include/apos/caps.h70
-rw-r--r--include/apos/syscalls.h9
-rw-r--r--include/apos/tcb.h5
-rw-r--r--include/apos/types.h2
-rw-r--r--include/apos/uapi.h42
5 files changed, 123 insertions, 5 deletions
diff --git a/include/apos/caps.h b/include/apos/caps.h
new file mode 100644
index 0000000..e8ef76b
--- /dev/null
+++ b/include/apos/caps.h
@@ -0,0 +1,70 @@
+#ifndef APOS_CAPS_H
+#define APOS_CAPS_H
+
+/**
+ * @file caps.h
+ * Capabilities of threads.
+ * \todo The list of capabilities should maybe be placed in some other file so
+ * as to easier extract it into userspace programs.
+ */
+
+#include <apos/bits.h>
+
+/** Helper typedef for capabilities. */
+typedef unsigned char capflags_t;
+
+enum {
+ /** Thread is allowed to set capabilities of other threads. */
+ CAP_CAPS = (1 << 0),
+
+ /** Thread is allowed to modify process statuses, exec/fork/etc. */
+ CAP_PROC = (1 << 1),
+
+ /** Thread is allowed to force interrupt to callback in other thread. */
+ CAP_CALL = (1 << 2),
+};
+
+/**
+ * Check that offset is OK.
+ *
+ * @param o Offset to check.
+ * @return \ref true is OK, \ref false otherwise.
+ */
+#define cap_off_ok(o) (o == 0)
+
+/**
+ * Set capabilities.
+ *
+ * @param x Capabilities to modify.
+ * @param o Offset.
+ * @param c Capabilities to set.
+ */
+#define set_caps(x, o, c) set_bits(x, c)
+
+/**
+ * Clear capabilities.
+ *
+ * @param x Capabilities to modify.
+ * @param o Offset.
+ * @param c Capabilities to set.
+ */
+#define clear_caps(x, o, c) clear_bits(x, c)
+
+/**
+ * Copy capabilities.
+ *
+ * @param x Capabilities to copy to.
+ * @param y Capabilities to copy from.
+ */
+#define copy_caps(x, y) (x = y)
+
+/**
+ * Get capabilities at offset \p o.
+ *
+ * @param x Capabilities to get from.
+ * @param o Offset to get capabilities from.
+ * @return Capabilities at offset \p o.
+ */
+#define get_caps(x, o) (x)
+
+#endif /* APOS_CAPS_H */
diff --git a/include/apos/syscalls.h b/include/apos/syscalls.h
index 229e17e..0a6f0c7 100644
--- a/include/apos/syscalls.h
+++ b/include/apos/syscalls.h
@@ -108,6 +108,15 @@ enum {
/** Get system parameters. */
SYS_CONF_GET,
+ /** Set capability of thread. */
+ SYS_SET_CAP,
+
+ /** Get capabilities of thread. */
+ SYS_GET_CAP,
+
+ /** Clear capability of thread. */
+ SYS_CLEAR_CAP,
+
/** Shutdown, reboot, etc. */
SYS_POWEROFF,
/** @} */
diff --git a/include/apos/tcb.h b/include/apos/tcb.h
index 9e63a9a..41b5237 100644
--- a/include/apos/tcb.h
+++ b/include/apos/tcb.h
@@ -10,6 +10,7 @@
*/
#include <apos/mem_regions.h>
+#include <apos/caps.h>
#include <apos/types.h>
#include <arch/tcb.h> /* arch-specific data */
@@ -108,8 +109,8 @@ struct tcb {
/** Address of callback function in servers. */
vm_t callback;
- /** Address of signal callback. */
- vm_t signal;
+ /** Capabilities of thread. */
+ capflags_t caps;
/** Address of this thread's stack base. */
vm_t thread_stack;
diff --git a/include/apos/types.h b/include/apos/types.h
index f249705..e06ccd0 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -455,6 +455,8 @@ typedef uint_fast16_t vmflags_t;
*/
/* should this enum be somewhere else? */
enum status_codes {
+ /** Permission error. */
+ ERR_PERM = -10,
/** Internal error, should probably halt */
ERR_INT = -9,
/** Something went wrong :/ */
diff --git a/include/apos/uapi.h b/include/apos/uapi.h
index 5d61966..d0ce350 100644
--- a/include/apos/uapi.h
+++ b/include/apos/uapi.h
@@ -525,14 +525,14 @@ SYSCALL_DECLARE2(exec, bin, interp);
/**
* Kill syscall.
*
- * @param a Unused.
+ * @param tid Thread ID to kill. 0 if self.
* @param b Unused.
* @param c Unused.
* @param d Unused.
* @param e Unused.
* @return No.
*/
-SYSCALL_DECLARE0(kill);
+SYSCALL_DECLARE1(kill, tid);
/**
* Signal process syscall.
@@ -587,11 +587,47 @@ SYSCALL_DECLARE2(conf_set, param, val);
* @param c Unused.
* @param d Unused.
* @param e Unused.
- * @return \ref OK and 0.
+ * @return \ref OK.
*/
SYSCALL_DECLARE1(conf_get, param);
/**
+ * Set capabilities.
+ *
+ * @param tid Thread ID whose capabilities to set.
+ * @param off Offset of capability, multiple of \c bits(cap).
+ * @param caps Mask of capabilities to set.
+ * @param d Unused.
+ * @param e Unused.
+ * @return \ref OK on success, \ref ERR_INVAL on invalid input.
+ */
+SYSCALL_DECLARE3(set_cap, tid, off, caps);
+
+/**
+ * Get capabilities.
+ *
+ * @param tid Thread ID whose capabilities to get.
+ * @param off Offset of capability, multiple of \c bits(cap).
+ * @param c Unused.
+ * @param d Unused.
+ * @param e Unused.
+ * @return \ref OK, capabilities.
+ */
+SYSCALL_DECLARE2(get_cap, tid, off);
+
+/**
+ * Clear capabilities.
+ *
+ * @param tid Thread ID whose capabilities to clear.
+ * @param off Offset of capability, multiple of \c bits(cap).
+ * @param cap Mask of capabilities to clear.
+ * @param d Unused.
+ * @param e Unused.
+ * @return \ref OK.
+ */
+SYSCALL_DECLARE3(clear_cap, tid, off, cap);
+
+/**
* Power off syscall.
*
* Either shut down or reboot system.