procgroup capabilities
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 1m55s
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
20
kernel/libk/ringbuffer.c
Normal 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
36
kernel/libk/ringbuffer.h
Normal 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
|
||||
@@ -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
6
kernel/proc/capability.h
Normal 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
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user