Compare commits

..

3 Commits

Author SHA1 Message Date
77796dd317 driver-install: implemented a simple installer 2026-05-20 17:52:19 +03:00
f1a72cc9da Kernel: Implemented banos - a WIP C driver API
Banos is a stable WIP C driver API that is supposed to provide a simple
interface to interact with the kernel and load the modules dynamically.
It is WIP and atm this just implements module loading with a custom
banos_install syscall. Banos will not try to substitute parts of the
kernel instead it will just expose kernel functionality via a stable
BINARY API. Meaning binaries (should) remain forward and backward
compatible on a binary level.

Banos modules work similarly to those in linux, you expose symbols via
BANOS_EXPORT which allows you to export a name + addr paired symbol.
It puts it in the .banos-export section. Drivers provide metadata about
themselves in the REQUIRED .banos-driver section. Symbols are resolved
at runtime. The kernel exposes the driver functionality via the same
.banos-export export mechanism.

Banos modules are elf RELOCATABLE files (object files) which have
partial linking (only banos symbols should remain). Modules will
eventually define dependencies, will export symbols and will allow you
to build a complex object hierarchy.

This patch adds the banos_install syscall which takes in the driver
image to install and may only be executed by super users. The API
doesn't validate already loaded modules, as thats something the
userspace MAY choose to keep track of. Multi-instance functionality
shall be implemented via driver specific behaviuor (exposed in the dev
filesystem or some other means).

Modules are supposed to allow you to alter kernel behavior and extend
it, allowing you to create filesystems, drivers, networking
modifications, schedulers, probers, and more (hopefully) whilst
remaining binary compatible with any version of the kernel (again,
hopefully).
2026-05-20 17:52:19 +03:00
718379ce3b Kernel: moved read/write_from_user out of Process 2026-05-20 17:52:19 +03:00
2 changed files with 17 additions and 4 deletions

View File

@@ -1,7 +1,12 @@
#pragma once
#include <BAN/Errors.h>
namespace Kernel {
namespace Kernel
{
BAN::ErrorOr<void> read_from_user(const void* user_addr, void* out, size_t size);
BAN::ErrorOr<void> read_string_from_user(const char* user_addr, char* out, size_t max_size);
BAN::ErrorOr<void> write_to_user(void* user_addr, const void* in, size_t size);
};

View File

@@ -1,7 +1,12 @@
#include <kernel/Memory/Types.h>
#include <kernel/UserCopy.h>
extern "C" bool safe_user_memcpy(void*, const void*, size_t);
extern "C" bool safe_user_strncpy(void*, const void*, size_t);
namespace Kernel
{
static inline bool is_valid_user_address(const void* user_addr, size_t size)
{
const vaddr_t user_vaddr = reinterpret_cast<vaddr_t>(user_addr);
@@ -11,7 +16,8 @@ static inline bool is_valid_user_address(const void* user_addr, size_t size)
return false;
return true;
}
BAN::ErrorOr<void> Kernel::read_from_user(const void* user_addr, void* out, size_t size)
BAN::ErrorOr<void> read_from_user(const void* user_addr, void* out, size_t size)
{
if (!is_valid_user_address(user_addr, size))
return BAN::Error::from_errno(EFAULT);
@@ -20,7 +26,7 @@ BAN::ErrorOr<void> Kernel::read_from_user(const void* user_addr, void* out, size
return {};
}
BAN::ErrorOr<void> Kernel::read_string_from_user(const char* user_addr, char* out, size_t max_size)
BAN::ErrorOr<void> read_string_from_user(const char* user_addr, char* out, size_t max_size)
{
max_size = BAN::Math::min<size_t>(max_size, USERSPACE_END - reinterpret_cast<vaddr_t>(user_addr));
if (!is_valid_user_address(user_addr, max_size))
@@ -30,7 +36,7 @@ BAN::ErrorOr<void> Kernel::read_string_from_user(const char* user_addr, char* ou
return {};
}
BAN::ErrorOr<void> Kernel::write_to_user(void* user_addr, const void* in, size_t size)
BAN::ErrorOr<void> write_to_user(void* user_addr, const void* in, size_t size)
{
if (!is_valid_user_address(user_addr, size))
return BAN::Error::from_errno(EFAULT);
@@ -38,3 +44,5 @@ BAN::ErrorOr<void> Kernel::write_to_user(void* user_addr, const void* in, size_t
return BAN::Error::from_errno(EFAULT);
return {};
}
}