From d58de12e73f21d38a74bf93881d56bf8b39b434e Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Mon, 15 Sep 2025 14:57:48 +0200 Subject: [PATCH] Xext: xres: inline SProc*()'s No need to have a hole bunch of extra functions, if we can just easily inline the few relevant lines. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/xres.c | 120 ++++++++++++---------------------------------------- 1 file changed, 28 insertions(+), 92 deletions(-) diff --git a/Xext/xres.c b/Xext/xres.c index ad287a87d7..da2249baad 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -259,6 +259,9 @@ ProcXResQueryClientResources(ClientPtr client) REQUEST(xXResQueryClientResourcesReq); REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); + if (client->swapped) + swapl(&stuff->xid); + ClientPtr resClient = dixClientForXID(stuff->xid); if ((!resClient) || @@ -319,6 +322,9 @@ ProcXResQueryClientPixmapBytes(ClientPtr client) REQUEST(xXResQueryClientPixmapBytesReq); REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); + if (client->swapped) + swapl(&stuff->xid); + ClientPtr owner = dixClientForXID(stuff->xid); if ((!owner) || (dixCallClientAccessCallback(client, owner, DixReadAccess) @@ -502,16 +508,19 @@ static int ProcXResQueryClientIds (ClientPtr client) { REQUEST(xXResQueryClientIdsReq); + REQUEST_AT_LEAST_SIZE(xXResQueryClientIdsReq); - xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff)); + if (client->swapped) + swapl(&stuff->numSpecs); + + REQUEST_FIXED_SIZE(xXResQueryClientIdsReq, + (uint64_t)stuff->numSpecs * sizeof(xXResClientIdSpec)); + + xXResClientIdSpec *specs = (void*) ((char*) stuff + sizeof(xXResQueryClientIdsReq)); ConstructClientIdCtx ctx; InitConstructClientIdCtx(&ctx); - REQUEST_AT_LEAST_SIZE(xXResQueryClientIdsReq); - REQUEST_FIXED_SIZE(xXResQueryClientIdsReq, - stuff->numSpecs * sizeof(specs[0])); - x_rpcbuf_t rpcbuf = { .swapped = client->swapped, .err_clear = TRUE }; int rc = ConstructClientIds(client, stuff->numSpecs, specs, &ctx); @@ -872,12 +881,20 @@ ProcXResQueryResourceBytes (ClientPtr client) REQUEST(xXResQueryResourceBytesReq); REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); - ConstructResourceBytesCtx ctx; - if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0])) - return BadLength; - REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq, - stuff->numSpecs * sizeof(ctx.specs[0])); + if (client->swapped) { + swapl(&stuff->numSpecs); + } + REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq, + ((uint64_t)stuff->numSpecs) * sizeof(xXResResourceIdSpec)); + + if (client->swapped) { + xXResResourceIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff)); + for (int c = 0; c < stuff->numSpecs; ++c) + SwapXResResourceIdSpec(specs + c); + } + + ConstructResourceBytesCtx ctx; if (!InitConstructResourceBytesCtx(&ctx, client, stuff->numSpecs, (void*) ((char*) stuff + @@ -938,91 +955,10 @@ ProcResDispatch(ClientPtr client) return BadRequest; } -static int _X_COLD -SProcXResQueryVersion(ClientPtr client) -{ - REQUEST_SIZE_MATCH(xXResQueryVersionReq); - return ProcXResQueryVersion(client); -} - -static int _X_COLD -SProcXResQueryClientResources(ClientPtr client) -{ - REQUEST(xXResQueryClientResourcesReq); - REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); - swapl(&stuff->xid); - return ProcXResQueryClientResources(client); -} - -static int _X_COLD -SProcXResQueryClientPixmapBytes(ClientPtr client) -{ - REQUEST(xXResQueryClientPixmapBytesReq); - REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); - swapl(&stuff->xid); - return ProcXResQueryClientPixmapBytes(client); -} - -static int _X_COLD -SProcXResQueryClientIds (ClientPtr client) -{ - REQUEST(xXResQueryClientIdsReq); - - REQUEST_AT_LEAST_SIZE (xXResQueryClientIdsReq); - swapl(&stuff->numSpecs); - return ProcXResQueryClientIds(client); -} - -/** @brief Implements the XResQueryResourceBytes of XResProto v1.2. - This variant byteswaps request contents before issuing the - rest of the work to ProcXResQueryResourceBytes */ -static int _X_COLD -SProcXResQueryResourceBytes (ClientPtr client) -{ - REQUEST(xXResQueryResourceBytesReq); - int c; - xXResResourceIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff)); - - REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq); - swapl(&stuff->numSpecs); - REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq, - stuff->numSpecs * sizeof(specs[0])); - - for (c = 0; c < stuff->numSpecs; ++c) { - SwapXResResourceIdSpec(specs + c); - } - - return ProcXResQueryResourceBytes(client); -} - -static int _X_COLD -SProcResDispatch (ClientPtr client) -{ - REQUEST(xReq); - - switch (stuff->data) { - case X_XResQueryVersion: - return SProcXResQueryVersion(client); - case X_XResQueryClients: /* nothing to swap */ - return ProcXResQueryClients(client); - case X_XResQueryClientResources: - return SProcXResQueryClientResources(client); - case X_XResQueryClientPixmapBytes: - return SProcXResQueryClientPixmapBytes(client); - case X_XResQueryClientIds: - return SProcXResQueryClientIds(client); - case X_XResQueryResourceBytes: - return SProcXResQueryResourceBytes(client); - default: break; - } - - return BadRequest; -} - void ResExtensionInit(void) { (void) AddExtension(XRES_NAME, 0, 0, - ProcResDispatch, SProcResDispatch, + ProcResDispatch, ProcResDispatch, NULL, StandardMinorOpcode); }