fixes
This commit is contained in:
+25
-19
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user