From ea2b0d398647307ddc564d44d079aeca5e217257 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Sun, 15 Mar 2026 09:43:00 +0000 Subject: [PATCH] lib: xpc: implement writing to local buffers --- lib/libxpc/buffer.c | 10 ++++++++-- lib/libxpc/include/xpc/buffer.h | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/libxpc/buffer.c b/lib/libxpc/buffer.c index 2999213..594b218 100644 --- a/lib/libxpc/buffer.c +++ b/lib/libxpc/buffer.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -36,8 +37,7 @@ kern_status_t xpc_buffer_write( size_t len, size_t *nr_written) { - if ((buf->buf_flags & (XPC_BUFFER_F_OUT | XPC_BUFFER_F_REMOTE)) - != (XPC_BUFFER_F_OUT | XPC_BUFFER_F_REMOTE)) { + if (!(buf->buf_flags & XPC_BUFFER_F_OUT)) { return KERN_BAD_STATE; } @@ -46,6 +46,12 @@ kern_status_t xpc_buffer_write( to_write = buf->buf_max; } + if (!(buf->buf_flags & XPC_BUFFER_F_REMOTE)) { + memcpy(buf->buf_ptr, in, to_write); + *nr_written = to_write; + return KERN_OK; + } + kern_status_t status = xpc_msg_write(buf->buf_origin, buf->buf_offset, in, to_write); if (status != KERN_OK) { diff --git a/lib/libxpc/include/xpc/buffer.h b/lib/libxpc/include/xpc/buffer.h index 5ace79e..519cf10 100644 --- a/lib/libxpc/include/xpc/buffer.h +++ b/lib/libxpc/include/xpc/buffer.h @@ -18,6 +18,13 @@ .buf_offset = (offset), \ .buf_len = (size), \ } +#define XPC_LOCAL_BUFFER_OUT(ptr, size) \ + { \ + .buf_flags = XPC_BUFFER_F_OUT, \ + .buf_ptr = (ptr), \ + .buf_max = (size), \ + .buf_len = (size), \ + } struct xpc_msg; @@ -49,7 +56,7 @@ typedef struct xpc_buffer { /* only valid if F_OUT is set. * if F_FREE_ON_DISCARD is set, must be either NULL or * allocated via xpc_context_alloc */ - const char *buf_ptr; + void *buf_ptr; }; /* fields that are only valid if F_IN is set */