wip: shared library support

This commit is contained in:
2026-04-05 15:14:07 +02:00
parent d6c0470c62
commit 01c242d4de
20 changed files with 1026 additions and 4 deletions
+5
View File
@@ -144,6 +144,11 @@ namespace Montauk {
static constexpr uint64_t SYS_SURFACE_MAP = 112;
static constexpr uint64_t SYS_SURFACE_RESIZE = 113;
// Shared library syscalls
static constexpr uint64_t SYS_LOAD_LIB = 114;
static constexpr uint64_t SYS_UNLOAD_LIB = 115;
static constexpr uint64_t SYS_DLSYM = 116;
static constexpr uint32_t IPC_SIGNAL_READABLE = 1u << 0;
static constexpr uint32_t IPC_SIGNAL_WRITABLE = 1u << 1;
static constexpr uint32_t IPC_SIGNAL_PEER_CLOSED = 1u << 2;
+39
View File
@@ -0,0 +1,39 @@
/*
* libloader.h
* Dynamic library loading interface for MontaukOS
* Copyright (c) 2026 Daniel Hammer
*/
#pragma once
#include <montauk/syscall.h>
// Library handle - opaque to users
struct LibHandle {
int handle; // syscall handle (slot + 1)
uint64_t base; // base virtual address
char path[256];
int symbolCount;
struct SymbolEntry {
char name[64];
uint64_t offset;
}* symbols;
};
namespace libloader {
// Maximum libraries that can be loaded per process
static constexpr int MaxLoadedLibs = 8;
// Load a shared library.
// Returns a LibHandle* on success, or nullptr on failure.
LibHandle* dlopen(const char* path);
// Look up a symbol in a loaded library.
// Returns the function/data pointer, or nullptr if not found.
void* dlsym(LibHandle* lib, const char* symbolName);
// Unload a library.
// Returns 0 on success, -1 on failure.
int dlclose(LibHandle* lib);
} // namespace libloader
+11
View File
@@ -282,6 +282,17 @@ namespace montauk {
return (int)syscall2(Montauk::SYS_SURFACE_RESIZE, (uint64_t)handle, newSize);
}
// Shared library support
inline int load_lib(const char* path) {
return (int)syscall1(Montauk::SYS_LOAD_LIB, (uint64_t)path);
}
inline int unload_lib(int handle) {
return (int)syscall1(Montauk::SYS_UNLOAD_LIB, (uint64_t)handle);
}
inline void* dlsym(int handle, uint64_t symbolOffset) {
return (void*)syscall2(Montauk::SYS_DLSYM, (uint64_t)handle, symbolOffset);
}
// Process management
inline void waitpid(int pid) { syscall1(Montauk::SYS_WAITPID, (uint64_t)pid); }