procgroup capabilities
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s

This commit is contained in:
2026-02-14 20:48:38 +01:00
parent ddfc93d9cd
commit 690e09339e
10 changed files with 81 additions and 6 deletions

View File

@@ -2,9 +2,10 @@
#define _KERNEL_DEVICE_DEVICE_H
#include <libk/rbtree.h>
#include <proc/proc.h>
#include <sync/spin_lock.h>
typedef int (*device_op_func_t) (void* a1, void* a2, void* a3, void* a4);
typedef int (*device_op_func_t) (struct proc* proc, void* a1, void* a2, void* a3, void* a4);
struct device {
int id;

View File

@@ -5,6 +5,8 @@
#include <limine/requests.h>
#include <m/status.h>
#include <mm/liballoc.h>
#include <proc/capability.h>
#include <proc/proc.h>
#include <sys/debug.h>
struct flanterm_context* ft_ctx;
@@ -32,9 +34,12 @@ bool terminal_init (void* arg) {
void terminal_fini (void) {}
int terminal_putstr (void* a1, void* a2, void* a3, void* a4) {
int terminal_putstr (struct proc* proc, void* a1, void* a2, void* a3, void* a4) {
(void)a2, (void)a3, (void)a4;
if (!(proc->procgroup->capabilities & PROC_CAP_TERMINAL))
return -ST_PERMISSION_ERROR;
char* string = (char*)a1;
size_t* len = (size_t*)a2;

View File

@@ -1,8 +1,10 @@
#ifndef _KERNEL_DEVICE_TERMINAL_H
#define _KERNEL_DEVICE_TERMINAL_H
#include <proc/proc.h>
bool terminal_init (void* arg);
void terminal_fini (void);
int terminal_putstr (void* a1, void* a2, void* a3, void* a4);
int terminal_putstr (struct proc* proc, void* a1, void* a2, void* a3, void* a4);
#endif // _KERNEL_DEVICE_TERMINAL_H

20
kernel/libk/ringbuffer.c Normal file
View File

@@ -0,0 +1,20 @@
#include <libk/ringbuffer.h>
#include <libk/std.h>
#include <libk/string.h>
#include <mm/liballoc.h>
bool ringbuffer_init (struct ringbuffer* rb, size_t capacity, size_t type_size) {
void* buf = malloc (capacity * type_size);
if (buf == NULL)
return false;
memset (rb, 0, sizeof (*rb));
rb->capacity = capacity;
rb->buffer = buf;
return true;
}
void ringbuffer_fini (struct ringbuffer* rb) { free (rb->buffer); }

36
kernel/libk/ringbuffer.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef _KERNEL_LIBK_RINGBUFFER_H
#define _KERNEL_LIBK_RINGBUFFER_H
#include <libk/std.h>
struct ringbuffer {
void* buffer;
size_t tail;
size_t head;
size_t capacity;
size_t count;
bool full;
};
bool ringbuffer_init (struct ringbuffer* rb, size_t capacity, size_t type_size);
void ringbuffer_fini (struct ringbuffer* rb);
#define ringbuffer_pop(type, rb, data) \
do { \
if ((rb)->count != 0) { \
*(data) = ((type*)(rb)->buffer)[(rb)->tail]; \
(rb)->tail = ((rb)->tail + 1) % (rb)->capacity; \
(rb)->count--; \
} \
} while (0)
#define ringbuffer_push(type, rb, data) \
do { \
if ((rb)->count != (rb)->capacity) { \
((type*)(rb)->buffer)[(rb)->head] = (data); \
(rb)->head = ((rb)->head + 1) % (rb)->capacity; \
(rb)->count++; \
} \
} while (0)
#endif // _KERNEL_LIBK_RINGBUFFER_H

View File

@@ -1,9 +1,11 @@
c += libk/string.c \
libk/printf.c \
libk/putchar_.c \
libk/bm.c
libk/bm.c \
libk/ringbuffer.c
o += libk/string.o \
libk/printf.o \
libk/putchar_.o \
libk/bm.o
libk/bm.o \
libk/ringbuffer.o

6
kernel/proc/capability.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef _KERNEL_PROC_CAPABILITY_H
#define _KERNEL_PROC_CAPABILITY_H
#define PROC_CAP_TERMINAL (1 << 0)
#endif // _KERNEL_PROC_CAPABILITY_H

View File

@@ -12,6 +12,7 @@
#include <m/status.h>
#include <mm/liballoc.h>
#include <mm/pmm.h>
#include <proc/capability.h>
#include <proc/proc.h>
#include <proc/procgroup.h>
#include <proc/resource.h>
@@ -303,6 +304,7 @@ void proc_init (void) {
proc_register (spin_proc, &spin_cpu);
struct proc* init = proc_from_file ("ramdisk", "/init.exe");
init->procgroup->capabilities |= PROC_CAP_TERMINAL;
struct cpu* init_cpu = thiscpu;
proc_register (init, &init_cpu);

View File

@@ -31,6 +31,7 @@ struct procgroup {
struct list_node_link* mappings;
uintptr_t map_base;
struct procgroup_tls tls;
uint64_t capabilities;
};
struct procgroup* procgroup_create (void);

View File

@@ -210,7 +210,7 @@ DEFINE_SYSCALL (sys_device_do) {
spin_lock (&device->lock);
int ret = device->ops[cmd]((void*)ka1, (void*)ka2, (void*)ka3, (void*)ka4);
int ret = device->ops[cmd](proc, (void*)ka1, (void*)ka2, (void*)ka3, (void*)ka4);
spin_unlock (&device->lock);