diff --git a/Source/hoc-clk/sysmodule/src/ipc/ipc_service.cpp b/Source/hoc-clk/sysmodule/src/ipc/ipc_service.cpp index f1e01d9b..c51f8195 100644 --- a/Source/hoc-clk/sysmodule/src/ipc/ipc_service.cpp +++ b/Source/hoc-clk/sysmodule/src/ipc/ipc_service.cpp @@ -24,6 +24,7 @@ * -------------------------------------------------------------------------- */ +#include #include #include #include @@ -48,6 +49,8 @@ namespace ipcService { LockableMutex gThreadMutex; IpcServer gServer; + constexpr size_t gMinContextBufSize = offsetof(HocClkContext, stable) + sizeof(HocClkContext::stable); + Result GetApiVersion(u32 *out_version) { *out_version = HOCCLK_IPC_API_VERSION; return 0; @@ -60,8 +63,9 @@ namespace ipcService { return 0; } - Result GetCurrentContext(HocClkContext *out_ctx) { - *out_ctx = clockManager::GetCurrentContext(); + Result GetCurrentContext(void *out_buf, size_t bufSize) { + HocClkContext ctx = clockManager::GetCurrentContext(); + memcpy(out_buf, &ctx, bufSize < sizeof(ctx) ? bufSize : sizeof(ctx)); return 0; } @@ -162,8 +166,8 @@ namespace ipcService { case HocClkIpcCmd_GetCurrentContext: if (r->data.size >= sizeof(std::uint64_t) && r->hipc.meta.num_recv_buffers >= 1) { size_t bufSize = hipcGetBufferSize(r->hipc.data.recv_buffers); - if (bufSize >= sizeof(HocClkContext)) { - return GetCurrentContext((HocClkContext *)hipcGetBufferAddress(r->hipc.data.recv_buffers)); + if (bufSize >= gMinContextBufSize) { + return GetCurrentContext(hipcGetBufferAddress(r->hipc.data.recv_buffers), bufSize); } } break;