This commit is contained in:
2026-08-11 17:48:20 +02:00
committed by Marvin Friedrich
parent cf33867e68
commit 0e2d4ed8c6
55 changed files with 279 additions and 346 deletions
+7 -28
View File
@@ -1,7 +1,12 @@
#pragma once
// These hints may improve code generation, but are optional and can be stubbed.
#if defined(__GNUC__) || defined(__clang__)
// Attributes that affect data layout.
#define __section(x) gnu::section(x)
#define __aligned(x) gnu::aligned(x)
#define __packed gnu::packed
#define __naked gnu::naked
// These hints may improve code generation.
#define __cold gnu::cold
#define __hot gnu::hot
#define __used gnu::used
@@ -9,17 +14,6 @@
#define __format(like, ...) gnu::format(like, __VA_ARGS__)
#define __likely(x) __builtin_expect(!!(x), 1)
#define __unlikely(x) __builtin_expect(!!(x), 0)
#define __always_inline gnu::always_inline
#else
#define __cold
#define __hot
#define __used
#define __unused
#define __format(like, ...)
#define __likely(x) x
#define __unlikely(x) x
#define __always_inline
#endif
// Only clang has these hints, GCC will throw a warning here.
// They also don't support the C23 attribute format.
@@ -30,18 +24,3 @@
#define __user
#define __phys
#endif
// Attributes that affect data layout. Not optional.
#if defined(__GNUC__) || defined(__clang__)
#define __weak gnu::weak
#define __section(x) gnu::section(x)
#define __aligned(x) gnu::aligned(x)
#define __packed gnu::packed
#define __naked gnu::naked
#define __alias(x) gnu::alias(x)
#else
#error "Unsupported compiler!"
#endif
// Intrinsics
#define __unreachable() __builtin_unreachable()
+33 -31
View File
@@ -2,37 +2,6 @@
#include <stdint.h>
#ifdef __x86_64__
#define ELF_ARCH_CLASS ELFCLASS64
#define ELF_ARCH_DATA ELFDATA2LSB
#define ELF_ARCH_MACHINE EM_X86_64
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#define elf_ehdr elf64_ehdr
#define elf_phdr elf64_phdr
#define elf_dyn elf64_dyn
#define elf_addr elf64_addr
#define elf_off elf64_off
#define elf_nhdr elf64_nhdr
#define elf_auxv elf64_auxv
#define elf_sym elf64_sym
#define elf_rela elf64_rela
#define elf_rel elf64_rel
enum {
R_NONE = 0,
R_COPY = 5,
R_GLOB_DAT = 6,
R_JUMP_SLOT = 7,
R_RELATIVE = 8,
R_IRELATIVE = 37,
};
#endif
constexpr char ELF_MAG[4] = {0x7F, 'E', 'L', 'F'};
typedef uint64_t elf64_addr_t;
@@ -369,3 +338,36 @@ static inline uint32_t ELF64_R_SYM(uint64_t info) {
static inline uint32_t ELF64_R_TYPE(uint64_t info) {
return info & 0xFFFFFFFF;
}
// Architecture specific bits.
#ifdef __x86_64__
#define ELF_ARCH_CLASS ELFCLASS64
#define ELF_ARCH_DATA ELFDATA2LSB
#define ELF_ARCH_MACHINE EM_X86_64
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#define elf_ehdr elf64_ehdr
#define elf_phdr elf64_phdr
#define elf_dyn elf64_dyn
#define elf_addr elf64_addr
#define elf_off elf64_off
#define elf_nhdr elf64_nhdr
#define elf_auxv elf64_auxv
#define elf_sym elf64_sym
#define elf_rela elf64_rela
#define elf_rel elf64_rel
enum {
R_NONE = 0,
R_COPY = 5,
R_GLOB_DAT = 6,
R_JUMP_SLOT = 7,
R_RELATIVE = 8,
R_IRELATIVE = 37,
};
#endif
+3 -2
View File
@@ -3,6 +3,7 @@
#include <zinnia/status.h>
#include <zinnia/syscall_stubs.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@@ -10,12 +11,12 @@ extern "C" {
// Blocks the calling thread if *addr == expected.
// Returns immediately if the value at addr has changed.
static inline zn_status_t zn_futex_wait(int* addr, int expected) {
static inline zn_status_t zn_futex_wait(int32_t* addr, int32_t expected) {
return zn_syscall2(addr, expected, ZN_SYSCALL_FUTEX_WAIT);
}
// Wakes up to `count` threads waiting on the given futex address.
static inline zn_status_t zn_futex_wake(int* addr, int count) {
static inline zn_status_t zn_futex_wake(int32_t* addr, int32_t count) {
return zn_syscall2(addr, count, ZN_SYSCALL_FUTEX_WAKE);
}
+2 -3
View File
@@ -24,9 +24,8 @@ static inline zn_status_t zn_handle_validate(zn_handle_t handle) {
return zn_syscall1(handle, ZN_SYSCALL_HANDLE_VALIDATE);
}
// Drops an object handle.
// All further references using this handle are invalid. The numerical value
// may become valid again, but it is an error to keep using it.
// Drops an object handle. All further references using this handle are invalid.
// The numerical value may become valid again, but it is an error to keep using it.
// The underlying object gets freed only once no other handle references it.
static inline zn_status_t zn_handle_drop(zn_handle_t handle) {
return zn_syscall1(handle, ZN_SYSCALL_HANDLE_DROP);
+26
View File
@@ -0,0 +1,26 @@
#ifndef ZINNIA_IPC_H
#define ZINNIA_IPC_H
#include <zinnia/handle.h>
#include <zinnia/rights.h>
#include <zinnia/status.h>
#include <zinnia/syscall_stubs.h>
#ifdef __cplusplus
extern "C" {
#endif
// Defines an IPC window.
struct zn_ipcw {
zn_handle_t handles[16];
};
static inline zn_status_t zn_ipcw_init(struct zn_ipcw** ipcw) {
return ZN_ERR_UNSUPPORTED;
}
#ifdef __cplusplus
}
#endif
#endif
-46
View File
@@ -1,46 +0,0 @@
#pragma once
#include <zinnia/handle.h>
#include <stddef.h>
#include <stdint.h>
#define IPC_GET_STRING(data, str, buf) \
do { \
memcpy(buf, (data) + (str)->offset, (str)->len); \
} while (0)
#define IPC_SET_STRING(cursor, data, field, string) \
do { \
const size_t _len = strlen(string); \
(field)->offset = cursor; \
(field)->len = _len; \
memcpy(data + cursor, string, _len); \
cursor += _len; \
} while (0)
enum ipc_msg_id {
IPC_MSG_FOO,
IPC_MSG_BAR,
IPC_MSG_BAZ,
};
struct ipc_array {
uint16_t offset;
uint16_t len;
};
struct ipc_option {
uint16_t offset;
};
struct ipc_init_register_rq {
enum ipc_msg_id id;
struct ipc_array name;
char data[];
};
struct ipc_kernel_msg {
enum ipc_msg_id id;
struct ipc_array name;
char data[];
};
+1 -1
View File
@@ -25,7 +25,7 @@ enum zn_vm_flags {
// Map at a fixed address, replacing whatever is in the way.
ZN_VM_MAP_FIXED = 1 << 8,
// Map at a fixed address, failing if anything is in the way.
ZB_VM_MAP_FIXED_NOREPLACE = 1 << 9,
ZN_VM_MAP_FIXED_NOREPLACE = 1 << 9,
// Map the entire range immediately.
ZN_VM_MAP_POPULATE = 1 << 10,
};
+3 -1
View File
@@ -13,7 +13,9 @@ static inline zn_status_t zn_ns_create(zn_handle_t* out) {
return ZN_ERR_UNSUPPORTED;
}
static inline zn_status_t zn_ns_move(zn_handle_t handle, zn_handle_t target_namespace) {
// Moves a handle to another namespace.
// The handle must have the `ZN_RIGHT_MOVE` right.
static inline zn_status_t zn_ns_move(zn_handle_t handle, zn_handle_t target_ns) {
return ZN_ERR_UNSUPPORTED;
}