This commit is contained in:
2026-08-18 01:28:35 +02:00
parent ac9d47fa16
commit cf3f1f9e99
11 changed files with 110 additions and 59 deletions
+25 -19
View File
@@ -12,8 +12,14 @@
#include <kernel/usercopy.h>
zn_status_t syscall_channel_create(struct arch_context* ctx) {
__user zn_handle_t* end0 = (__user zn_handle_t*)ctx->ARCH_CTX_A1;
__user zn_handle_t* end1 = (__user zn_handle_t*)ctx->ARCH_CTX_A2;
auto flags = (enum zn_channel_flags)ctx->a0;
auto end0 = (__user zn_handle_t*)ctx->a1;
auto end1 = (__user zn_handle_t*)ctx->a2;
// Validate flags before doing anything.
if (flags & !(ZN_CHANNEL_NONE | ZN_CHANNEL_NONBLOCK)) {
return ZN_ERR_INVALID;
}
struct channel* ep0;
struct channel* ep1;
@@ -61,11 +67,11 @@ zn_status_t syscall_channel_create(struct arch_context* ctx) {
}
zn_status_t syscall_channel_write(struct arch_context* ctx) {
zn_handle_t ch_handle = ctx->ARCH_CTX_A0;
__user zn_handle_t* handles = (__user zn_handle_t*)ctx->ARCH_CTX_A1;
__user void* bytes = (__user void*)ctx->ARCH_CTX_A2;
size_t num_handles = ctx->ARCH_CTX_A3;
size_t num_bytes = ctx->ARCH_CTX_A4;
auto ch_handle = (zn_handle_t)ctx->a0;
auto handles = (__user zn_handle_t*)ctx->a0;
auto bytes = (__user void*)ctx->a2;
size_t num_handles = ctx->a3;
size_t num_bytes = ctx->a4;
struct task* current = percpu_get()->sched.current;
@@ -95,7 +101,7 @@ zn_status_t syscall_channel_write(struct arch_context* ctx) {
}
}
// Copy and transfer handles (move semantics).
// Copy and transfer handles.
struct namespace_desc* descs = nullptr;
if (num_handles > 0) {
if (!handles) {
@@ -155,13 +161,13 @@ zn_status_t syscall_channel_write(struct arch_context* ctx) {
}
zn_status_t syscall_channel_read(struct arch_context* ctx) {
zn_handle_t ch_handle = ctx->ARCH_CTX_A0;
__user zn_handle_t* handles = (__user zn_handle_t*)ctx->ARCH_CTX_A1;
__user void* bytes = (__user void*)ctx->ARCH_CTX_A2;
size_t num_handles = ctx->ARCH_CTX_A3;
size_t num_bytes = ctx->ARCH_CTX_A4;
__user size_t* read_handles = (__user size_t*)ctx->ARCH_CTX_A5;
__user size_t* read_bytes = (__user size_t*)ctx->ARCH_CTX_A6;
zn_handle_t ch_handle = ctx->a0;
__user zn_handle_t* handles = (__user zn_handle_t*)ctx->a1;
__user void* bytes = (__user void*)ctx->a2;
size_t num_handles = ctx->a3;
size_t num_bytes = ctx->a4;
__user size_t* read_handles = (__user size_t*)ctx->a5;
__user size_t* read_bytes = (__user size_t*)ctx->a6;
struct task* current = percpu_get()->sched.current;
struct sched_percpu* sched = &percpu_get()->sched;
@@ -183,7 +189,7 @@ zn_status_t syscall_channel_read(struct arch_context* ctx) {
if (status == ZN_OK) {
// Copy byte data to userspace.
size_t bytes_to_copy = msg->num_bytes < num_bytes ? msg->num_bytes : num_bytes;
size_t bytes_to_copy = MIN(msg->num_bytes, num_bytes);
if (bytes_to_copy > 0 && bytes) {
if (!usercopy_write(bytes, msg->data, bytes_to_copy)) {
channel_msg_free(msg);
@@ -192,7 +198,7 @@ zn_status_t syscall_channel_read(struct arch_context* ctx) {
}
// Transfer handle descriptors into the reader's namespace.
size_t handles_to_copy = msg->num_handles < num_handles ? msg->num_handles : num_handles;
size_t handles_to_copy = MIN(msg->num_handles, num_handles);
if (handles_to_copy > 0 && handles) {
for (size_t i = 0; i < handles_to_copy; i++) {
zn_handle_t new_handle;
@@ -231,13 +237,13 @@ zn_status_t syscall_channel_read(struct arch_context* ctx) {
if (status == ZN_ERR_BAD_HANDLE)
return status;
// Empty but peer alive — block until a message arrives or peer closes.
// Block until a message arrives or peer closes.
sched_block(sched, &ch->waiters);
}
}
zn_status_t syscall_channel_wait(struct arch_context* ctx) {
zn_handle_t ch_handle = ctx->ARCH_CTX_A0;
zn_handle_t ch_handle = ctx->a0;
struct task* current = percpu_get()->sched.current;
struct sched_percpu* sched = &percpu_get()->sched;
+13 -13
View File
@@ -15,8 +15,8 @@
#include <stdatomic.h>
zn_status_t syscall_vmo_create(struct arch_context* ctx) {
size_t length = ctx->ARCH_CTX_A0;
__user zn_handle_t* out = (__user zn_handle_t*)ctx->ARCH_CTX_A1;
size_t length = ctx->a0;
__user zn_handle_t* out = (__user zn_handle_t*)ctx->a1;
// Allocate new VMO.
struct paged_vmo* vmo;
@@ -43,9 +43,9 @@ zn_status_t syscall_vmo_create(struct arch_context* ctx) {
}
zn_status_t syscall_vmo_create_phys(struct arch_context* ctx) {
uintptr_t addr = ctx->ARCH_CTX_A0;
size_t length = ctx->ARCH_CTX_A1;
__user zn_handle_t* out = (__user zn_handle_t*)ctx->ARCH_CTX_A2;
uintptr_t addr = ctx->a0;
size_t length = ctx->a1;
__user zn_handle_t* out = (__user zn_handle_t*)ctx->a2;
struct vmo* vmo;
zn_status_t status = vmo_new_phys_range(addr, length, &vmo);
@@ -71,12 +71,12 @@ zn_status_t syscall_vmo_create_phys(struct arch_context* ctx) {
}
zn_status_t syscall_vmo_map(struct arch_context* ctx) {
zn_handle_t vmo_handle = ctx->ARCH_CTX_A0;
zn_handle_t vas_handle = ctx->ARCH_CTX_A1;
uintptr_t vmo_offset = ctx->ARCH_CTX_A2;
__user uintptr_t* addr = (__user uintptr_t*)ctx->ARCH_CTX_A3;
size_t bytes = ctx->ARCH_CTX_A4;
enum zn_vm_flags flags = ctx->ARCH_CTX_A5;
zn_handle_t vmo_handle = ctx->a0;
zn_handle_t vas_handle = ctx->a1;
uintptr_t vmo_offset = ctx->a2;
auto addr = (__user uintptr_t*)ctx->a3;
size_t bytes = ctx->a4;
enum zn_vm_flags flags = ctx->a5;
struct task* current = percpu_get()->sched.current;
@@ -112,8 +112,8 @@ zn_status_t syscall_vmo_map(struct arch_context* ctx) {
// TODO: Use actual allocator for user task.
if (target_addr == 0) {
static uintptr_t map_offset = 0xA000'0000;
target_addr = atomic_fetch_add(&map_offset, ALIGN_UP(bytes, arch_mem_page_size()));
static _Atomic uintptr_t map_offset = 0xA000'0000;
target_addr = atomic_fetch_add((volatile uintptr_t*)&map_offset, ALIGN_UP(bytes, arch_mem_page_size()));
}
if (addr != nullptr) {