ipc: allow mismatached provided buffer size as long as the stable region is covered

This commit is contained in:
Lightos1 committed 2026-08-27 20:33:02 +02:00
1 parent b6fcd6072c
commit 40ec8dee8c
1 file changed
+8 -4
@@ -24,6 +24,7 @@
* --------------------------------------------------------------------------
*/
#include <cstddef>
#include <cstring>
#include <i2c.h>
#include <max17050.h>
@@ -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;