This commit is contained in:
2026-08-14 21:31:01 +02:00
parent 40cea4dedd
commit ac9d47fa16
58 changed files with 148 additions and 37 deletions
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#pragma once #pragma once
// Attributes that affect data layout. // Attributes that affect data layout.
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#pragma once #pragma once
#define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0]))
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_ARCHCTL_H #ifndef ZINNIA_ARCHCTL_H
#define ZINNIA_ARCHCTL_H #define ZINNIA_ARCHCTL_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_CHANNEL_H #ifndef ZINNIA_CHANNEL_H
#define ZINNIA_CHANNEL_H #define ZINNIA_CHANNEL_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_FUTEX_H #ifndef ZINNIA_FUTEX_H
#define ZINNIA_FUTEX_H #define ZINNIA_FUTEX_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_HANDLE_H #ifndef ZINNIA_HANDLE_H
#define ZINNIA_HANDLE_H #define ZINNIA_HANDLE_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_MEM_H #ifndef ZINNIA_MEM_H
#define ZINNIA_MEM_H #define ZINNIA_MEM_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_NAMESPACE_H #ifndef ZINNIA_NAMESPACE_H
#define ZINNIA_NAMESPACE_H #define ZINNIA_NAMESPACE_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_RANDOM_H #ifndef ZINNIA_RANDOM_H
#define ZINNIA_RANDOM_H #define ZINNIA_RANDOM_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_RIGHTS_H #ifndef ZINNIA_RIGHTS_H
#define ZINNIA_RIGHTS_H #define ZINNIA_RIGHTS_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_STATUS_H #ifndef ZINNIA_STATUS_H
#define ZINNIA_STATUS_H #define ZINNIA_STATUS_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_SYSTEM_H #ifndef ZINNIA_SYSTEM_H
#define ZINNIA_SYSTEM_H #define ZINNIA_SYSTEM_H
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#ifndef ZINNIA_THREAD_H #ifndef ZINNIA_THREAD_H
#define ZINNIA_THREAD_H #define ZINNIA_THREAD_H
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <kernel/usercopy.h>
bool arch_usercopy_read(void* dst, const __user void* src, size_t len, struct usercopy_region** region);
bool arch_usercopy_write(__user void* dst, const void* src, size_t len, struct usercopy_region** region);
bool arch_usercopy_strlen(const __user char* str, size_t max, size_t* len, struct usercopy_region** region);
+2 -2
View File
@@ -51,8 +51,8 @@ zn_status_t namespace_get(struct namespace* namespace, zn_handle_t handle, struc
zn_status_t namespace_del_desc(struct namespace* namespace, zn_handle_t handle); zn_status_t namespace_del_desc(struct namespace* namespace, zn_handle_t handle);
// Clones a descriptor with optionally restricted rights. // Clones a descriptor with optionally restricted rights.
// If cloned_rights has ZN_RIGHTS_IDENTICAL set, the clone keeps the original rights. // If `cloned_rights` contains ZN_RIGHTS_IDENTICAL, the clone keeps the original rights.
// Otherwise, cloned_rights must be a subset of the original descriptor's rights. // Otherwise, `cloned_rights` must be a subset of the original descriptor's rights.
zn_status_t namespace_clone_desc( zn_status_t namespace_clone_desc(
struct namespace* ns, struct namespace* ns,
struct namespace_desc* desc, struct namespace_desc* desc,
+3 -1
View File
@@ -1,6 +1,8 @@
#pragma once #pragma once
typedef enum { #include <stdint.h>
typedef enum : uint32_t {
ZN_SYSCALL_LOG, ZN_SYSCALL_LOG,
ZN_SYSCALL_ARCHCTL, ZN_SYSCALL_ARCHCTL,
ZN_SYSCALL_PAGE_SIZE, ZN_SYSCALL_PAGE_SIZE,
-4
View File
@@ -18,7 +18,3 @@ bool usercopy_write(__user void* dst, const void* src, size_t len);
// Performs a strlen() on a user string. // Performs a strlen() on a user string.
bool usercopy_strlen(const __user char* str, size_t max, size_t* len); bool usercopy_strlen(const __user char* str, size_t max, size_t* len);
bool arch_usercopy_read(void* dst, const __user void* src, size_t len, struct usercopy_region** region);
bool arch_usercopy_write(__user void* dst, const void* src, size_t len, struct usercopy_region** region);
bool arch_usercopy_strlen(const __user char* str, size_t max, size_t* len, struct usercopy_region** region);
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <common/utils.h> #include <common/utils.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
#include <kernel/init.h> #include <kernel/init.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <kernel/mmio.h> #include <kernel/mmio.h>
#include <kernel/pmap.h> #include <kernel/pmap.h>
#include <kernel/vas.h> #include <kernel/vas.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
#include <kernel/pmap.h> #include <kernel/pmap.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <common/compiler.h> #include <common/compiler.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
#include <kernel/panic.h> #include <kernel/panic.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <common/compiler.h> #include <common/compiler.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
+3
View File
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: MIT
#include <kernel/bits/usercopy.h>
#include <kernel/percpu.h> #include <kernel/percpu.h>
#include <kernel/usercopy.h> #include <kernel/usercopy.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <common/utils.h> #include <common/utils.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <common/utils.h> #include <common/utils.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
#include <kernel/virt.h> #include <kernel/virt.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <common/utils.h> #include <common/utils.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
+1 -1
View File
@@ -47,10 +47,10 @@ executable(
link_args: kernel_link_args, link_args: kernel_link_args,
link_depends: [ link_depends: [
kernel_lds, kernel_lds,
vdso,
], ],
sources: [ sources: [
kernel_sources, kernel_sources,
uacpi_sources, uacpi_sources,
vdso,
], ],
) )
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/archctl.h> #include <zinnia/archctl.h>
#include <kernel/syscalls.h> #include <kernel/syscalls.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/channel.h> #include <zinnia/channel.h>
#include <zinnia/handle.h> #include <zinnia/handle.h>
#include <zinnia/status.h> #include <zinnia/status.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <common/compiler.h> #include <common/compiler.h>
#include <common/utils.h> #include <common/utils.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/futex.h> #include <kernel/futex.h>
#include <kernel/syscalls.h> #include <kernel/syscalls.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/handle.h> #include <zinnia/handle.h>
#include <zinnia/rights.h> #include <zinnia/rights.h>
#include <zinnia/status.h> #include <zinnia/status.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/syscalls.h> #include <kernel/syscalls.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/alloc.h> #include <kernel/alloc.h>
#include <kernel/clock.h> #include <kernel/clock.h>
+11 -10
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/handle.h> #include <zinnia/handle.h>
#include <zinnia/rights.h> #include <zinnia/rights.h>
#include <zinnia/status.h> #include <zinnia/status.h>
@@ -14,11 +16,11 @@
#include <string.h> #include <string.h>
zn_status_t syscall_thread_create(struct arch_context* ctx) { zn_status_t syscall_thread_create(struct arch_context* ctx) {
zn_handle_t ns_handle = ctx->ARCH_CTX_A0; zn_handle_t ns_handle = ctx->a0;
__user const char* name = (__user const char*)ctx->ARCH_CTX_A1; __user const char* name = (__user const char*)ctx->a1;
size_t name_len = ctx->ARCH_CTX_A2; size_t name_len = ctx->a2;
enum zn_thread_flags flags = ctx->ARCH_CTX_A3; enum zn_thread_flags flags = ctx->a3;
__user zn_handle_t* out = (__user zn_handle_t*)ctx->ARCH_CTX_A4; __user zn_handle_t* out = (__user zn_handle_t*)ctx->a4;
struct task* current = percpu_get()->sched.current; struct task* current = percpu_get()->sched.current;
// Resolve namespace. // Resolve namespace.
@@ -44,7 +46,6 @@ zn_status_t syscall_thread_create(struct arch_context* ctx) {
return ZN_ERR_BAD_BUFFER; return ZN_ERR_BAD_BUFFER;
// Create the task sharing the caller's address space. // Create the task sharing the caller's address space.
// Uses sched_to_user as a placeholder entry — the real IP/SP come from thread_start.
struct task* new_task; struct task* new_task;
zn_status_t status = task_create(task_name, current->space, ns, sched_to_user, 0, &new_task); zn_status_t status = task_create(task_name, current->space, ns, sched_to_user, 0, &new_task);
if (status != ZN_OK) if (status != ZN_OK)
@@ -71,10 +72,10 @@ zn_status_t syscall_thread_create(struct arch_context* ctx) {
} }
zn_status_t syscall_thread_start(struct arch_context* ctx) { zn_status_t syscall_thread_start(struct arch_context* ctx) {
zn_handle_t thread_handle = ctx->ARCH_CTX_A0; zn_handle_t thread_handle = ctx->a0;
uintptr_t ip = ctx->ARCH_CTX_A1; uintptr_t ip = ctx->a1;
uintptr_t sp = ctx->ARCH_CTX_A2; uintptr_t sp = ctx->a2;
uintptr_t arg = ctx->ARCH_CTX_A3; uintptr_t arg = ctx->a3;
struct task* current = percpu_get()->sched.current; struct task* current = percpu_get()->sched.current;
struct sched_percpu* sched = &percpu_get()->sched; struct sched_percpu* sched = &percpu_get()->sched;
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/syscalls.h> #include <kernel/syscalls.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/handle.h> #include <zinnia/handle.h>
#include <zinnia/status.h> #include <zinnia/status.h>
#include <common/utils.h> #include <common/utils.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/archctl.h> #include <zinnia/archctl.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/channel.h> #include <zinnia/channel.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2 -2
View File
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
#include <common/compiler.h> #include <common/compiler.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
[[__used, __section(".vdso_data")]] [[__used, __section(".vdso_data")]]
const volatile struct vdso_kernel_data vdso_data = {0}; const volatile struct vdso_kernel_data vdso_data = {0};
static_assert(sizeof(vdso_data) <= 0x1000);
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/futex.h> #include <zinnia/futex.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/handle.h> #include <zinnia/handle.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/mem.h> #include <zinnia/mem.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+7 -1
View File
@@ -19,7 +19,7 @@ vdso_link_args = [
# Build a shared library, which we are going to embed next. # Build a shared library, which we are going to embed next.
# TODO: We need to ensure there are no relocations inside the vDSO. # TODO: We need to ensure there are no relocations inside the vDSO.
vdso = shared_library( real_vdso = shared_library(
'zinnia-vdso', 'zinnia-vdso',
name_prefix: '', name_prefix: '',
c_args: vdso_c_args, c_args: vdso_c_args,
@@ -44,5 +44,11 @@ vdso = shared_library(
], ],
) )
vdso = custom_target(
command: [find_program('cp'), '@INPUT@', '@OUTPUT@'],
input: real_vdso,
output: 'vdso.bin',
)
# Tell the kernel where the built binary lives so we can #embed it. # Tell the kernel where the built binary lives so we can #embed it.
kernel_c_args += ['-DVDSO_PATH="' + vdso.full_path() + '"'] kernel_c_args += ['-DVDSO_PATH="' + vdso.full_path() + '"']
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/namespace.h> #include <zinnia/namespace.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/random.h> #include <zinnia/random.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/status.h> #include <zinnia/status.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/system.h> #include <zinnia/system.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+2
View File
@@ -1,3 +1,5 @@
// SPDX-License-Identifier: MIT
#include <zinnia/thread.h> #include <zinnia/thread.h>
#include <kernel/vdso.h> #include <kernel/vdso.h>
+9 -7
View File
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: GPL-2.0-only */ /* SPDX-License-Identifier: MIT */
VERSION { VERSION {
ZINNIA_0 { ZINNIA_0 {
@@ -11,7 +11,7 @@ VERSION {
PHDRS { PHDRS {
text PT_LOAD FILEHDR PHDRS FLAGS(5); text PT_LOAD FILEHDR PHDRS FLAGS(5);
dynamic PT_DYNAMIC FLAGS(4); dynamic PT_DYNAMIC FLAGS(4);
note PT_NOTE FLAGS(4); data PT_LOAD FLAGS(4);
} }
SECTIONS SECTIONS
@@ -28,10 +28,6 @@ SECTIONS
*(.got .got.*) *(.got .got.*)
} :text } :text
.data ALIGN(CONSTANT(MAXPAGESIZE)) : {
*(.vdso_data)
} :text
.dynsym : { .dynsym : {
*(.dynsym) *(.dynsym)
} :text } :text
@@ -44,9 +40,15 @@ SECTIONS
*(.dynamic) *(.dynamic)
} :text :dynamic } :text :dynamic
.vdso_data ALIGN(CONSTANT(MAXPAGESIZE)) : {
*(.vdso_data)
. = ALIGN(CONSTANT(MAXPAGESIZE));
} :data
/DISCARD/ : /DISCARD/ :
{ {
*(.data*) *(.data*) /* No data allowed besides the vDSO data */
*(.bss*) *(.bss*)
*(.comment*) *(.comment*)
*(.eh_frame*) *(.eh_frame*)
+7
View File
@@ -0,0 +1,7 @@
libdevice = library(
'device',
sources: [
'vdso.c',
],
include_directories: common_includes,
)
+1
View File
@@ -0,0 +1 @@
+8
View File
@@ -0,0 +1,8 @@
libfreestanding = static_library(
'freestanding',
sources: [
'entry.c',
'vdso.c',
],
include_directories: common_includes,
)
+3 -7
View File
@@ -1,7 +1,3 @@
libzinnia = static_library( subdir('freestanding')
'zinnia',
sources: [ subdir('device')
'vdso.c',
],
include_directories: common_includes,
)
+1 -1
View File
@@ -11,6 +11,6 @@ executable(
common_includes, common_includes,
uacpi_includes, uacpi_includes,
], ],
link_with: libzinnia, link_with: libfreestanding,
install: true, install: true,
) )
+1 -1
View File
@@ -3,7 +3,7 @@ executable(
'main.c', 'main.c',
# The init process is linked statically because the dynamic loader can't be read before posixd is up. # The init process is linked statically because the dynamic loader can't be read before posixd is up.
link_args: '-static', link_args: '-static',
link_with: libzinnia, link_with: libfreestanding,
include_directories: common_includes, include_directories: common_includes,
install: true, install: true,
) )