From 5ccaceb43c095fb0a5acab2b42bb64a072b7faa7 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Thu, 25 Sep 2025 14:46:52 +0200 Subject: [PATCH] dix: inline SProcResourceReq() Simplifying byte-swapping code flow by inlining SProcResourceReq() instead of having complicated call chains. Signed-off-by: Enrico Weigelt, metux IT consult Signed-off-by: Enrico Weigelt, metux IT consult --- dix/dispatch.c | 104 +++++++++++++++++++++++++++++++++++++++------- dix/events.c | 18 ++++++-- dix/property.c | 5 ++- dix/selection.c | 3 ++ dix/swapreq.c | 12 ------ dix/tables.c | 58 +++++++++++++------------- dix/window.c | 3 ++ include/swapreq.h | 1 - 8 files changed, 143 insertions(+), 61 deletions(-) diff --git a/dix/dispatch.c b/dix/dispatch.c index f0e19e864..2ab7723b1 100644 --- a/dix/dispatch.c +++ b/dix/dispatch.c @@ -797,9 +797,13 @@ ProcDestroyWindow(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc; - REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixDestroyAccess); if (rc != Success) return rc; @@ -819,9 +823,13 @@ ProcDestroySubwindows(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc; - REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixRemoveAccess); if (rc != Success) return rc; @@ -835,9 +843,13 @@ ProcChangeSaveSet(ClientPtr client) WindowPtr pWin; REQUEST(xChangeSaveSetReq); + REQUEST_SIZE_MATCH(xChangeSaveSetReq); + + if (client->swapped) + swapl(&stuff->window); + int rc; - REQUEST_SIZE_MATCH(xChangeSaveSetReq); rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess); if (rc != Success) return rc; @@ -882,9 +894,12 @@ ProcMapWindow(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); - int rc; - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + + int rc; rc = dixLookupWindow(&pWin, stuff->id, client, DixShowAccess); if (rc != Success) return rc; @@ -899,9 +914,13 @@ ProcMapSubwindows(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc; - REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess); if (rc != Success) return rc; @@ -916,9 +935,13 @@ ProcUnmapWindow(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc; - REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixHideAccess); if (rc != Success) return rc; @@ -933,9 +956,13 @@ ProcUnmapSubwindows(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc; - REQUEST_SIZE_MATCH(xResourceReq); rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess); if (rc != Success) return rc; @@ -968,9 +995,13 @@ ProcCirculateWindow(ClientPtr client) WindowPtr pWin; REQUEST(xCirculateWindowReq); + REQUEST_SIZE_MATCH(xCirculateWindowReq); + + if (client->swapped) + swapl(&stuff->window); + int rc; - REQUEST_SIZE_MATCH(xCirculateWindowReq); if ((stuff->direction != RaiseLowest) && (stuff->direction != LowerHighest)) { client->errorValue = stuff->direction; return BadValue; @@ -991,6 +1022,9 @@ ProcGetGeometry(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY, DixGetAttrAccess); if (rc != Success) return rc; @@ -1029,8 +1063,11 @@ ProcQueryTree(ClientPtr client) WindowPtr pWin, pHead; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess); if (rc != Success) return rc; @@ -1095,8 +1132,11 @@ ProcGetAtomName(ClientPtr client) const char *str; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + if (!(str = NameForAtom(stuff->id))) { client->errorValue = stuff->id; return BadAtom; @@ -1282,8 +1322,11 @@ ProcCloseFont(ClientPtr client) int rc; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pFont, stuff->id, X11_RESTYPE_FONT, client, DixDestroyAccess); if (rc == Success) { @@ -1306,6 +1349,9 @@ ProcQueryFont(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -1357,6 +1403,9 @@ ProcQueryTextExtents(ClientPtr client) REQUEST(xQueryTextExtentsReq); REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq); + if (client->swapped) + swapl(&stuff->fid); + rc = dixLookupFontable(&pFont, stuff->fid, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -1507,6 +1556,9 @@ ProcFreePixmap(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pMap, stuff->id, X11_RESTYPE_PIXMAP, client, DixDestroyAccess); if (rc == Success) { @@ -1655,6 +1707,9 @@ ProcFreeGC(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupGC(&pGC, stuff->id, client, DixDestroyAccess); if (rc != Success) return rc; @@ -2443,8 +2498,11 @@ ProcFreeColormap(ClientPtr client) int rc; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pmap, stuff->id, X11_RESTYPE_COLORMAP, client, DixDestroyAccess); if (rc == Success) { @@ -2489,6 +2547,9 @@ ProcInstallColormap(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pcmp, stuff->id, X11_RESTYPE_COLORMAP, client, DixInstallAccess); if (rc != Success) @@ -2518,6 +2579,9 @@ ProcUninstallColormap(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pcmp, stuff->id, X11_RESTYPE_COLORMAP, client, DixUninstallAccess); if (rc != Success) @@ -2548,6 +2612,9 @@ ProcListInstalledColormaps(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; @@ -3109,8 +3176,11 @@ ProcFreeCursor(ClientPtr client) int rc; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupResourceByType((void **) &pCursor, stuff->id, X11_RESTYPE_CURSOR, client, DixDestroyAccess); if (rc == Success) { @@ -3357,10 +3427,14 @@ int ProcKillClient(ClientPtr client) { REQUEST(xResourceReq); + REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + ClientPtr killclient; int rc; - REQUEST_SIZE_MATCH(xResourceReq); if (stuff->id == AllTemporary) { CloseDownRetainedResources(); return Success; diff --git a/dix/events.c b/dix/events.c index 94077140e..5649a2724 100644 --- a/dix/events.c +++ b/dix/events.c @@ -1942,8 +1942,11 @@ ProcAllowEvents(ClientPtr client) DeviceIntPtr keybd = NULL; REQUEST(xAllowEventsReq); - REQUEST_SIZE_MATCH(xAllowEventsReq); + + if (client->swapped) + swapl(&stuff->time); + UpdateCurrentTime(); time = ClientTimeToServerTime(stuff->time); @@ -5115,8 +5118,11 @@ ProcUngrabPointer(ClientPtr client) TimeStamp time; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + UpdateCurrentTime(); grab = device->deviceGrab.grab; @@ -5300,8 +5306,11 @@ ProcUngrabKeyboard(ClientPtr client) TimeStamp time; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + UpdateCurrentTime(); grab = device->deviceGrab.grab; @@ -5332,6 +5341,9 @@ ProcQueryPointer(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) return rc; diff --git a/dix/property.c b/dix/property.c index f24473d7f..34b5e23ba 100644 --- a/dix/property.c +++ b/dix/property.c @@ -651,8 +651,11 @@ ProcListProperties(ClientPtr client) WindowPtr pWin; REQUEST(xResourceReq); - REQUEST_SIZE_MATCH(xResourceReq); + + if (client->swapped) + swapl(&stuff->id); + int rc = dixLookupWindow(&pWin, stuff->id, client, DixListPropAccess); if (rc != Success) return rc; diff --git a/dix/selection.c b/dix/selection.c index 0b8b84095..1c9f3b4dd 100644 --- a/dix/selection.c +++ b/dix/selection.c @@ -246,6 +246,9 @@ ProcGetSelectionOwner(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + /* allow extensions to intercept */ SelectionFilterParamRec param = { .client = client, diff --git a/dix/swapreq.c b/dix/swapreq.c index 2cd59cb94..49eb3d35f 100644 --- a/dix/swapreq.c +++ b/dix/swapreq.c @@ -115,18 +115,6 @@ SwapShorts(short *list, unsigned long count) } } -/* The following is used for all requests that have - only a single 32-bit field to be swapped, coming - right after the "length" field */ -int _X_COLD -SProcResourceReq(ClientPtr client) -{ - REQUEST(xResourceReq); - REQUEST_AT_LEAST_SIZE(xResourceReq); /* not EXACT */ - swapl(&stuff->id); - return (*ProcVector[stuff->reqType]) (client); -} - int _X_COLD SProcCreateWindow(ClientPtr client) { diff --git a/dix/tables.c b/dix/tables.c index 64a055f6e..bb522e439 100644 --- a/dix/tables.c +++ b/dix/tables.c @@ -334,42 +334,42 @@ int (*SwappedProcVector[256]) (ClientPtr /* client */) = { ProcBadRequest, SProcCreateWindow, SProcChangeWindowAttributes, - SProcResourceReq, /* GetWindowAttributes */ - SProcResourceReq, /* DestroyWindow */ - SProcResourceReq, /* 5 DestroySubwindows */ - SProcResourceReq, /* SProcChangeSaveSet, */ + ProcGetWindowAttributes, + ProcDestroyWindow, + ProcDestroySubwindows, /* 5 */ + ProcChangeSaveSet, SProcReparentWindow, - SProcResourceReq, /* MapWindow */ - SProcResourceReq, /* MapSubwindows */ - SProcResourceReq, /* 10 UnmapWindow */ - SProcResourceReq, /* UnmapSubwindows */ + ProcMapWindow, + ProcMapSubwindows, + ProcUnmapWindow, /* 10 */ + ProcUnmapSubwindows, SProcConfigureWindow, - SProcResourceReq, /* SProcCirculateWindow, */ - SProcResourceReq, /* GetGeometry */ - SProcResourceReq, /* 15 QueryTree */ + ProcCirculateWindow, + ProcGetGeometry, + ProcQueryTree, /* 15 */ SProcInternAtom, - SProcResourceReq, /* SProcGetAtomName, */ + ProcGetAtomName, SProcChangeProperty, SProcDeleteProperty, SProcGetProperty, /* 20 */ - SProcResourceReq, /* SProcListProperties, */ + ProcListProperties, SProcSetSelectionOwner, - SProcResourceReq, /* SProcGetSelectionOwner, */ + ProcGetSelectionOwner, SProcConvertSelection, SProcSendEvent, /* 25 */ SProcGrabPointer, - SProcResourceReq, /* SProcUngrabPointer, */ + ProcUngrabPointer, SProcGrabButton, SProcUngrabButton, SProcChangeActivePointerGrab, /* 30 */ SProcGrabKeyboard, - SProcResourceReq, /* SProcUngrabKeyboard, */ + ProcUngrabKeyboard, SProcGrabKey, SProcUngrabKey, - SProcResourceReq, /* 35 SProcAllowEvents, */ + ProcAllowEvents, ProcGrabServer, ProcUngrabServer, - SProcResourceReq, /* SProcQueryPointer, */ + ProcQueryPointer, SProcGetMotionEvents, SProcTranslateCoords, /*40 */ SProcWarpPointer, @@ -377,21 +377,21 @@ int (*SwappedProcVector[256]) (ClientPtr /* client */) = { ProcGetInputFocus, ProcQueryKeymap, SProcOpenFont, /* 45 */ - SProcResourceReq, /* SProcCloseFont, */ - SProcResourceReq, /* SProcQueryFont, */ - SProcResourceReq, /* SProcQueryTextExtents, */ + ProcCloseFont, + ProcQueryFont, + ProcQueryTextExtents, SProcListFonts, SProcListFontsWithInfo, /* 50 */ SProcSetFontPath, ProcGetFontPath, SProcCreatePixmap, - SProcResourceReq, /* SProcFreePixmap, */ + ProcFreePixmap, SProcCreateGC, /* 55 */ SProcChangeGC, SProcCopyGC, SProcSetDashes, SProcSetClipRectangles, - SProcResourceReq, /* 60 SProcFreeGC, */ + ProcFreeGC, /* 60 */ SProcClearToBackground, SProcCopyArea, SProcCopyPlane, @@ -410,11 +410,11 @@ int (*SwappedProcVector[256]) (ClientPtr /* client */) = { SProcImageText, SProcImageText, SProcCreateColormap, - SProcResourceReq, /* SProcFreeColormap, */ + ProcFreeColormap, SProcCopyColormapAndFree, /* 80 */ - SProcResourceReq, /* SProcInstallColormap, */ - SProcResourceReq, /* SProcUninstallColormap, */ - SProcResourceReq, /* SProcListInstalledColormaps, */ + ProcInstallColormap, + ProcUninstallColormap, + ProcListInstalledColormaps, SProcAllocColor, SProcAllocNamedColor, /* 85 */ SProcAllocColorCells, @@ -426,7 +426,7 @@ int (*SwappedProcVector[256]) (ClientPtr /* client */) = { SProcLookupColor, SProcCreateCursor, SProcCreateGlyphCursor, - SProcResourceReq, /* 95 SProcFreeCursor, */ + ProcFreeCursor, /* 95 */ SProcRecolorCursor, SProcQueryBestSize, SProcQueryExtension, @@ -444,7 +444,7 @@ int (*SwappedProcVector[256]) (ClientPtr /* client */) = { ProcListHosts, /* 110 */ ProcChangeAccessControl, ProcChangeCloseDownMode, - SProcResourceReq, /* SProcKillClient, */ + ProcKillClient, SProcRotateProperties, ProcForceScreenSaver, /* 115 */ ProcSetPointerMapping, diff --git a/dix/window.c b/dix/window.c index 3eb17d380..859657923 100644 --- a/dix/window.c +++ b/dix/window.c @@ -1567,6 +1567,9 @@ ProcGetWindowAttributes(ClientPtr client) REQUEST(xResourceReq); REQUEST_SIZE_MATCH(xResourceReq); + if (client->swapped) + swapl(&stuff->id); + WindowPtr pWin; int rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess); if (rc != Success) diff --git a/include/swapreq.h b/include/swapreq.h index d9ee145b6..65731f2d1 100644 --- a/include/swapreq.h +++ b/include/swapreq.h @@ -73,7 +73,6 @@ int SProcQueryBestSize(ClientPtr client); int SProcQueryColors(ClientPtr client); int SProcQueryExtension(ClientPtr client); int SProcReparentWindow(ClientPtr client); -int SProcResourceReq(ClientPtr client); int SProcRotateProperties(ClientPtr client); int SProcSetClipRectangles(ClientPtr client); int SProcSetDashes(ClientPtr client);