From 37d6229ac5533504ad17924b5ddd9ccfeb527b52 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 5 Mar 2025 12:43:10 +0100 Subject: [PATCH] dix: replace CLIENT_ID() macro by dixClientIdForXID() inline function Make it type-safe and a bit more obvious what it really does, also adding some inline documentation. Since it's just some bit shifting magic, it's qualified for inlining. The CLIENT_ID() macro isn't used by any external modules, so the new function doesn't need to be in a public header. Signed-off-by: Enrico Weigelt, metux IT consult --- Xext/panoramiX.c | 3 ++- Xext/security.c | 2 +- Xext/xres.c | 14 +++++++------- Xext/xselinux_hooks.c | 2 +- Xi/exevents.c | 2 +- Xi/xibarriers.c | 6 +++--- Xi/xiselectev.c | 3 ++- composite/compalloc.c | 12 +++++++----- composite/compwindow.c | 2 +- dix/colormap.c | 11 ++++++----- dix/dix_priv.h | 1 + dix/dixutils.c | 3 ++- dix/events.c | 14 +++++++------- dix/grabs.c | 13 +++++++------ dix/lookup.c | 8 ++++---- dix/resource.c | 15 ++++++++------- dix/resource_priv.h | 15 +++++++++++++++ dix/touch.c | 3 ++- glx/glxcmds.c | 3 ++- hw/xwayland/xwayland-pixmap.h | 4 +++- hw/xwayland/xwayland-window.c | 4 ++-- include/resource.h | 1 - record/record.c | 7 ++++--- 23 files changed, 88 insertions(+), 60 deletions(-) diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c index 75f9e37b2..519133951 100644 --- a/Xext/panoramiX.c +++ b/Xext/panoramiX.c @@ -32,6 +32,7 @@ Equipment Corporation. #include #include "dix/dix_priv.h" +#include "dix/resource_priv.h" #include "misc.h" #include "cursor.h" @@ -352,7 +353,7 @@ PanoramiXFindIDByScrnum(RESTYPE type, XID id, int screen) data.screen = screen; data.id = id; - return LookupClientResourceComplex(clients[CLIENT_ID(id)], type, + return LookupClientResourceComplex(clients[dixClientIdForXID(id)], type, XineramaFindIDByScrnum, &data); } diff --git a/Xext/security.c b/Xext/security.c index 68648e8ae..0ac266f3c 100644 --- a/Xext/security.c +++ b/Xext/security.c @@ -745,7 +745,7 @@ SecurityResource(CallbackListPtr *pcbl, void *unused, void *calldata) { XaceResourceAccessRec *rec = calldata; SecurityStateRec *subj, *obj; - int cid = CLIENT_ID(rec->id); + int cid = dixClientIdForXID(rec->id); Mask requested = rec->access_mode; Mask allowed = SecurityResourceMask; diff --git a/Xext/xres.c b/Xext/xres.c index 90f8bc285..0b7b84155 100644 --- a/Xext/xres.c +++ b/Xext/xres.c @@ -12,6 +12,7 @@ #include #include "dix/registry_priv.h" +#include "dix/resource_priv.h" #include "os/client_priv.h" #include "misc.h" @@ -299,12 +300,12 @@ ProcXResQueryClientResources(ClientPtr client) { REQUEST(xXResQueryClientResourcesReq); xXResQueryClientResourcesReply rep; - int i, clientID, num_types; + int i, num_types; int *counts; REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); - clientID = CLIENT_ID(stuff->xid); + int clientID = dixClientIdForXID(stuff->xid); if ((clientID >= currentMaxClients) || !clients[clientID]) { client->errorValue = stuff->xid; @@ -375,12 +376,11 @@ ProcXResQueryClientPixmapBytes(ClientPtr client) { REQUEST(xXResQueryClientPixmapBytesReq); xXResQueryClientPixmapBytesReply rep; - int clientID; unsigned long bytes; REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); - clientID = CLIENT_ID(stuff->xid); + int clientID = dixClientIdForXID(stuff->xid); if ((clientID >= currentMaxClients) || !clients[clientID]) { client->errorValue = stuff->xid; @@ -547,7 +547,7 @@ ConstructClientIds(ClientPtr client, } } } else { - int clientID = CLIENT_ID(specs[specIdx].client); + int clientID = dixClientIdForXID(specs[specIdx].client); if ((clientID < currentMaxClients) && clients[clientID]) { if (!ConstructClientIdValue(client, clients[clientID], @@ -887,7 +887,7 @@ ConstructResourceBytesByResource(XID aboutClient, ConstructResourceBytesCtx *ctx for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) { xXResResourceIdSpec *spec = ctx->specs + specIdx; if (spec->resource) { - int cid = CLIENT_ID(spec->resource); + int cid = dixClientIdForXID(spec->resource); if (cid < currentMaxClients && (aboutClient == None || cid == aboutClient)) { ClientPtr client = clients[cid]; @@ -915,7 +915,7 @@ ConstructResourceBytes(XID aboutClient, ConstructResourceBytesCtx *ctx) { if (aboutClient) { - int clientIdx = CLIENT_ID(aboutClient); + int clientIdx = dixClientIdForXID(aboutClient); ClientPtr client = NullClient; if ((clientIdx >= currentMaxClients) || !clients[clientIdx]) { diff --git a/Xext/xselinux_hooks.c b/Xext/xselinux_hooks.c index 8f8eeabe4..da0f61289 100644 --- a/Xext/xselinux_hooks.c +++ b/Xext/xselinux_hooks.c @@ -631,7 +631,7 @@ SELinuxResource(CallbackListPtr *pcbl, void *unused, void *calldata) if (offset < 0) { /* No: use the SID of the owning client */ class = SECCLASS_X_RESOURCE; - privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates; + privatePtr = &clients[dixClientIdForXID(rec->id)]->devPrivates; obj = dixLookupPrivate(privatePtr, objectKey); } else { diff --git a/Xi/exevents.c b/Xi/exevents.c index 3b3b49f51..fa8854487 100644 --- a/Xi/exevents.c +++ b/Xi/exevents.c @@ -1739,7 +1739,7 @@ ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev) Otherwise, deliver normally to the client. */ if (grab && - CLIENT_ID(be->barrierid) == CLIENT_ID(grab->resource) && + dixClientIdForXID(be->barrierid) == dixClientIdForXID(grab->resource) && grab->window->drawable.id == be->window) { DeliverGrabbedEvent(e, dev, FALSE); } else { diff --git a/Xi/xibarriers.c b/Xi/xibarriers.c index 6761bcb49..9c260405a 100644 --- a/Xi/xibarriers.c +++ b/Xi/xibarriers.c @@ -46,6 +46,7 @@ #include "dix/cursor_priv.h" #include "dix/dix_priv.h" #include "dix/input_priv.h" +#include "dix/resource_priv.h" #include "mi/mi_priv.h" #include "os/bug_priv.h" @@ -844,7 +845,7 @@ XIDestroyPointerBarrier(ClientPtr client, return err; } - if (CLIENT_ID(stuff->barrier) != client->index) + if (dixClientIdForXID(stuff->barrier) != client->index) return BadAccess; FreeResource(stuff->barrier, X11_RESTYPE_NONE); @@ -913,10 +914,9 @@ ProcXIBarrierReleasePointer(ClientPtr client) return err; } - if (CLIENT_ID(barrier_id) != client->index) + if (dixClientIdForXID(barrier_id) != client->index) return BadAccess; - barrier = container_of(b, struct PointerBarrierClient, barrier); pbd = GetBarrierDevice(barrier, dev->id); diff --git a/Xi/xiselectev.c b/Xi/xiselectev.c index d341a12d5..80dbf6857 100644 --- a/Xi/xiselectev.c +++ b/Xi/xiselectev.c @@ -29,6 +29,7 @@ #include "dix/dix_priv.h" #include "dix/exevents_priv.h" +#include "dix/resource_priv.h" #include "dixstruct.h" #include "windowstr.h" @@ -56,7 +57,7 @@ check_for_touch_selection_conflicts(ClientPtr B, WindowPtr win, int deviceid, for (; A; A = A->next) { DeviceIntPtr tmp; - if (CLIENT_ID(A->resource) == B->index) + if (dixClientIdForXID(A->resource) == B->index) continue; if (deviceid == XIAllDevices) diff --git a/composite/compalloc.c b/composite/compalloc.c index 4a1243170..7da3f08c2 100644 --- a/composite/compalloc.c +++ b/composite/compalloc.c @@ -43,6 +43,8 @@ #include +#include "dix/resource_priv.h" + #include "compint.h" static Bool @@ -327,7 +329,7 @@ compUnredirectWindow(ClientPtr pClient, WindowPtr pWin, int update) return BadValue; for (ccw = cw->clients; ccw; ccw = ccw->next) - if (ccw->update == update && CLIENT_ID(ccw->id) == pClient->index) { + if (ccw->update == update && dixClientIdForXID(ccw->id) == pClient->index) { FreeResource(ccw->id, X11_RESTYPE_NONE); return Success; } @@ -426,7 +428,7 @@ compFreeClientSubwindows(WindowPtr pWin, XID id) return; for (prev = &csw->clients; (ccw = *prev); prev = &ccw->next) { if (ccw->id == id) { - ClientPtr pClient = clients[CLIENT_ID(id)]; + ClientPtr pClient = clients[dixClientIdForXID(id)]; *prev = ccw->next; if (ccw->update == CompositeRedirectManual) { @@ -475,7 +477,7 @@ compUnredirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update) if (!csw) return BadValue; for (ccw = csw->clients; ccw; ccw = ccw->next) - if (ccw->update == update && CLIENT_ID(ccw->id) == pClient->index) { + if (ccw->update == update && dixClientIdForXID(ccw->id) == pClient->index) { FreeResource(ccw->id, X11_RESTYPE_NONE); return Success; } @@ -495,7 +497,7 @@ compRedirectOneSubwindow(WindowPtr pParent, WindowPtr pWin) if (!csw) return Success; for (ccw = csw->clients; ccw; ccw = ccw->next) { - int ret = compRedirectWindow(clients[CLIENT_ID(ccw->id)], + int ret = compRedirectWindow(clients[dixClientIdForXID(ccw->id)], pWin, ccw->update); if (ret != Success) @@ -517,7 +519,7 @@ compUnredirectOneSubwindow(WindowPtr pParent, WindowPtr pWin) if (!csw) return Success; for (ccw = csw->clients; ccw; ccw = ccw->next) { - int ret = compUnredirectWindow(clients[CLIENT_ID(ccw->id)], + int ret = compUnredirectWindow(clients[dixClientIdForXID(ccw->id)], pWin, ccw->update); if (ret != Success) diff --git a/composite/compwindow.c b/composite/compwindow.c index c2a96168a..db769a5be 100644 --- a/composite/compwindow.c +++ b/composite/compwindow.c @@ -586,7 +586,7 @@ compCreateWindow(WindowPtr pWin) (*pScreen->SetWindowPixmap) (pWin, parent_pixmap); if (csw) for (ccw = csw->clients; ccw; ccw = ccw->next) - compRedirectWindow(clients[CLIENT_ID(ccw->id)], + compRedirectWindow(clients[dixClientIdForXID(ccw->id)], pWin, ccw->update); if (compImplicitRedirect(pWin, pWin->parent)) compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic); diff --git a/dix/colormap.c b/dix/colormap.c index 9a8be28e2..28392d525 100644 --- a/dix/colormap.c +++ b/dix/colormap.c @@ -53,6 +53,7 @@ SOFTWARE. #include #include "dix/colormap_priv.h" +#include "dix/resource_priv.h" #include "os/osdep.h" #include "misc.h" @@ -415,7 +416,7 @@ FreeColormap(void *value, XID mid) EntryPtr pent; ColormapPtr pmap = (ColormapPtr) value; - if (CLIENT_ID(mid) != SERVER_ID) { + if (dixClientIdForXID(mid) != SERVER_ID) { (*pmap->pScreen->UninstallColormap) (pmap); WalkTree(pmap->pScreen, (VisitWindowProcPtr) TellNoMap, (void *) &mid); } @@ -546,7 +547,7 @@ CopyColormapAndFree(Colormap mid, ColormapPtr pSrc, int client) pScreen = pSrc->pScreen; pVisual = pSrc->pVisual; midSrc = pSrc->mid; - alloc = ((pSrc->flags & CM_AllAllocated) && CLIENT_ID(midSrc) == client) ? + alloc = ((pSrc->flags & CM_AllAllocated) && dixClientIdForXID(midSrc) == client) ? AllocAll : AllocNone; size = pVisual->ColormapEntries; @@ -1086,7 +1087,7 @@ AllocColor(ColormapPtr pmap, * resource manager that the client has pixels in this colormap which * should be freed when the client dies */ if ((pmap->numPixelsRed[client] == 1) && - (CLIENT_ID(pmap->mid) != client) && !(pmap->flags & CM_BeingCreated)) { + (dixClientIdForXID(pmap->mid) != client) && !(pmap->flags & CM_BeingCreated)) { colorResource *pcr; pcr = malloc(sizeof(colorResource)); @@ -1506,7 +1507,7 @@ AllocColorCells(int client, ColormapPtr pmap, int colors, int planes, oldcount = pmap->numPixelsRed[client]; if (pmap->class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; - if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { + if (!oldcount && (dixClientIdForXID(pmap->mid) != client)) { pcr = malloc(sizeof(colorResource)); if (!pcr) return BadAlloc; @@ -1573,7 +1574,7 @@ AllocColorPlanes(int client, ColormapPtr pmap, int colors, oldcount = pmap->numPixelsRed[client]; if (class == DirectColor) oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; - if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { + if (!oldcount && (dixClientIdForXID(pmap->mid) != client)) { pcr = malloc(sizeof(colorResource)); if (!pcr) return BadAlloc; diff --git a/dix/dix_priv.h b/dix/dix_priv.h index 47c18817f..bc90e46df 100644 --- a/dix/dix_priv.h +++ b/dix/dix_priv.h @@ -23,6 +23,7 @@ #include "include/events.h" #include "include/gc.h" #include "include/input.h" +#include "include/resource.h" #include "include/window.h" /* server setting: maximum size for big requests */ diff --git a/dix/dixutils.c b/dix/dixutils.c index 3b98ced0e..006b5dce4 100644 --- a/dix/dixutils.c +++ b/dix/dixutils.c @@ -87,6 +87,7 @@ Author: Adobe Systems Incorporated #include "dix/callback_priv.h" #include "dix/dix_priv.h" +#include "dix/resource_priv.h" #include "misc.h" #include "windowstr.h" @@ -221,7 +222,7 @@ int dixLookupClient(ClientPtr *pClient, XID rid, ClientPtr client, Mask access) { void *pRes; - int rc = BadValue, clientIndex = CLIENT_ID(rid); + int rc = BadValue, clientIndex = dixClientIdForXID(rid); if (!clientIndex || !clients[clientIndex] || (rid & SERVER_BIT)) goto bad; diff --git a/dix/events.c b/dix/events.c index fb306da49..55861dcba 100644 --- a/dix/events.c +++ b/dix/events.c @@ -1425,8 +1425,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) else { /* free both if same client owns both */ thisDev->deviceGrab.sync.state = GRAB_STATE_THAWED; if (thisDev->deviceGrab.sync.other && - (CLIENT_BITS(thisDev->deviceGrab.sync.other->resource) == - CLIENT_BITS(grab->resource))) + (dixClientIdForXID(thisDev->deviceGrab.sync.other->resource) == + dixClientIdForXID(grab->resource))) thisDev->deviceGrab.sync.other = NullGrab; } @@ -1436,8 +1436,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode) dev->deviceGrab.sync.other = grab; else { /* free both if same client owns both */ if (dev->deviceGrab.sync.other && - (CLIENT_BITS(dev->deviceGrab.sync.other->resource) == - CLIENT_BITS(grab->resource))) + (dixClientIdForXID(dev->deviceGrab.sync.other->resource) == + dixClientIdForXID(grab->resource))) dev->deviceGrab.sync.other = NullGrab; } } @@ -4424,8 +4424,8 @@ FreezeThisEventIfNeededForSyncGrab(DeviceIntPtr thisDev, InternalEvent *event) if (dev) { FreezeThaw(dev, TRUE); if ((dev->deviceGrab.sync.state == GRAB_STATE_FREEZE_BOTH_NEXT_EVENT) && - (CLIENT_BITS(grab->resource) == - CLIENT_BITS(dev->deviceGrab.grab->resource))) + (dixClientIdForXID(grab->resource) == + dixClientIdForXID(dev->deviceGrab.grab->resource))) dev->deviceGrab.sync.state = GRAB_STATE_FROZEN_NO_EVENT; else dev->deviceGrab.sync.other = grab; @@ -6285,5 +6285,5 @@ IsWrongPointerBarrierClient(ClientPtr client, DeviceIntPtr dev, xEvent *event) if (ev->evtype != XI_BarrierHit && ev->evtype != XI_BarrierLeave) return FALSE; - return client->index != CLIENT_ID(ev->barrier); + return client->index != dixClientIdForXID(ev->barrier); } diff --git a/dix/grabs.c b/dix/grabs.c index 8409a0bf8..e8f0d32e9 100644 --- a/dix/grabs.c +++ b/dix/grabs.c @@ -55,6 +55,7 @@ SOFTWARE. #include "dix/dix_priv.h" #include "dix/dixgrabs_priv.h" #include "dix/exevents_priv.h" +#include "dix/resource_priv.h" #include "os/auth.h" #include "os/client_priv.h" @@ -88,7 +89,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) (grab->grabtype == XI2) ? "xi2" : ((grab->grabtype == CORE) ? "core" : "xi1"), dev->name, dev->id); - client = clients[CLIENT_ID(grab->resource)]; + client = clients[dixClientIdForXID(grab->resource)]; if (client) { pid_t clientpid = GetClientPid(client); const char *cmdname = GetClientCmdName(client); @@ -110,7 +111,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev) } if (!clientIdPrinted) { ErrorF(" (no client information available for client %d)\n", - CLIENT_ID(grab->resource)); + dixClientIdForXID(grab->resource)); } /* XXX is this even correct? */ @@ -181,7 +182,7 @@ UngrabAllDevices(Bool kill_client) if (!dev->deviceGrab.grab) continue; PrintDeviceGrabInfo(dev); - client = clients[CLIENT_ID(dev->deviceGrab.grab->resource)]; + client = clients[dixClientIdForXID(dev->deviceGrab.grab->resource)]; if (!kill_client || !client || client->clientGone) dev->deviceGrab.DeactivateGrab(dev); if (kill_client) @@ -539,7 +540,7 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab) for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == CORE))) { - if (CLIENT_BITS(pGrab->resource) != CLIENT_BITS(grab->resource)) { + if (dixClientIdForXID(pGrab->resource) != dixClientIdForXID(grab->resource)) { FreeGrab(pGrab); return BadAccess; } @@ -619,7 +620,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) ok = TRUE; for (grab = wPassiveGrabs(pMinuendGrab->window); grab && ok; grab = grab->next) { - if ((CLIENT_BITS(grab->resource) != CLIENT_BITS(pMinuendGrab->resource)) + if ((dixClientIdForXID(grab->resource) != dixClientIdForXID(pMinuendGrab->resource)) || !GrabMatchesSecond(grab, pMinuendGrab, (grab->grabtype == CORE))) continue; if (GrabSupersedesSecond(pMinuendGrab, grab)) { @@ -647,7 +648,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab) param.other_devices_mode = grab->pointerMode; param.modifiers = any_modifier; - pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device, + pNewGrab = CreateGrab(dixClientIdForXID(grab->resource), grab->device, grab->modifierDevice, grab->window, grab->grabtype, (GrabMask *) &grab->eventMask, diff --git a/dix/lookup.c b/dix/lookup.c index c039efd39..02d04e228 100644 --- a/dix/lookup.c +++ b/dix/lookup.c @@ -16,26 +16,26 @@ ClientPtr dixClientForWindow(WindowPtr pWin) { if (!pWin) return NullClient; - return clients[CLIENT_ID(pWin->drawable.id)]; + return clients[dixClientIdForXID(pWin->drawable.id)]; } ClientPtr dixClientForGrab(GrabPtr pGrab) { if (!pGrab) return NullClient; - return clients[CLIENT_ID(pGrab->resource)]; + return clients[dixClientIdForXID(pGrab->resource)]; } ClientPtr dixClientForInputClients(InputClientsPtr pInputClients) { if (!pInputClients) return NullClient; - return clients[CLIENT_ID(pInputClients->resource)]; + return clients[dixClientIdForXID(pInputClients->resource)]; } ClientPtr dixClientForOtherClients(OtherClientsPtr pOtherClients) { if (!pOtherClients) return NullClient; - return clients[CLIENT_ID(pOtherClients->resource)]; + return clients[dixClientIdForXID(pOtherClients->resource)]; } diff --git a/dix/resource.c b/dix/resource.c index 7542f0c42..60682b8df 100644 --- a/dix/resource.c +++ b/dix/resource.c @@ -112,7 +112,7 @@ Equipment Corporation. * like it belongs to a client. This ID, however, must not be one * the client actually can create, or we have the potential for conflict. * The 31st bit of the ID is reserved for the server's use for this - * purpose. By setting CLIENT_ID(id) to the client, the SERVER_BIT to + * purpose. By setting dixClientIdForXID(id) to the client, the SERVER_BIT to * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a * resource "owned" by the client. */ @@ -125,6 +125,7 @@ Equipment Corporation. #include "dix/dixgrabs_priv.h" #include "dix/gc_priv.h" #include "dix/registry_priv.h" +#include "dix/resource_priv.h" #include "os/osdep.h" #include "misc.h" @@ -813,7 +814,7 @@ AddResource(XID id, RESTYPE type, void *value) #ifdef XSERVER_DTRACE XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); #endif - client = CLIENT_ID(id); + client = dixClientIdForXID(id); rrec = &clientTable[client]; if (!rrec->buckets) { ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n", @@ -901,7 +902,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType) int *eltptr; int elements; - if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { + if (((cid = dixClientIdForXID(id)) < LimitClients) && clientTable[cid].buckets) { head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; eltptr = &clientTable[cid].elements; @@ -935,7 +936,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree) ResourcePtr res; ResourcePtr *prev, *head; - if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { + if (((cid = dixClientIdForXID(id)) < LimitClients) && clientTable[cid].buckets) { head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; prev = head; @@ -970,7 +971,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, void *value) int cid; ResourcePtr res; - if (((cid = CLIENT_ID(id)) < LimitClients) && clientTable[cid].buckets) { + if (((cid = dixClientIdForXID(id)) < LimitClients) && clientTable[cid].buckets) { res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)]; for (; res; res = res->next) @@ -1201,7 +1202,7 @@ int dixLookupResourceByType(void **result, XID id, RESTYPE rtype, ClientPtr client, Mask mode) { - int cid = CLIENT_ID(id); + int cid = dixClientIdForXID(id); ResourcePtr res = NULL; *result = NULL; @@ -1238,7 +1239,7 @@ int dixLookupResourceByClass(void **result, XID id, RESTYPE rclass, ClientPtr client, Mask mode) { - int cid = CLIENT_ID(id); + int cid = dixClientIdForXID(id); ResourcePtr res = NULL; *result = NULL; diff --git a/dix/resource_priv.h b/dix/resource_priv.h index ee12b0ede..35b6b3ec8 100644 --- a/dix/resource_priv.h +++ b/dix/resource_priv.h @@ -51,4 +51,19 @@ ClientPtr dixClientForInputClients(InputClientsPtr pInputClients); */ ClientPtr dixClientForOtherClients(OtherClientsPtr pOtherClients); +/* + * @brief extract client ID from XID + * + * XIDs carry the ID of the client who created/owns the resource in upper bits. + * (every client so is assigned a range of XIDs it may use for resource creation) + * + * This ID is frequently used as table index, eg. for client or resource lookup. + * + * @param XID the ID of the resource whose client is retrieved + * @return index of the client (within client or resource table) + */ +static inline int dixClientIdForXID(XID xid) { + return ((int)(CLIENT_BITS(xid) >> CLIENTOFFSET)); +} + #endif /* _XSERVER_DIX_RESOURCE_PRIV_H */ diff --git a/dix/touch.c b/dix/touch.c index 9365fc70e..5173d2767 100644 --- a/dix/touch.c +++ b/dix/touch.c @@ -31,6 +31,7 @@ #include "dix/eventconvert.h" #include "dix/exevents_priv.h" #include "dix/input_priv.h" +#include "dix/resource_priv.h" #include "mi/mi_priv.h" #include "os/bug_priv.h" @@ -994,7 +995,7 @@ TouchAcceptReject(ClientPtr client, DeviceIntPtr dev, int mode, } for (i = 0; i < ti->num_listeners; i++) { - if (CLIENT_ID(ti->listeners[i].listener) == client->index && + if (dixClientIdForXID(ti->listeners[i].listener) == client->index && ti->listeners[i].window->drawable.id == grab_window) break; } diff --git a/glx/glxcmds.c b/glx/glxcmds.c index f8c3a965c..314768d52 100644 --- a/glx/glxcmds.c +++ b/glx/glxcmds.c @@ -36,6 +36,7 @@ #include #include "dix/dix_priv.h" +#include "dix/resource_priv.h" #include "glxserver.h" #include @@ -2501,7 +2502,7 @@ void __glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust, CARD64 msc, CARD32 sbc) { - ClientPtr client = clients[CLIENT_ID(drawable->drawId)]; + ClientPtr client = clients[dixClientIdForXID(drawable->drawId)]; xGLXBufferSwapComplete2 wire = { .type = __glXEventBase + GLX_BufferSwapComplete diff --git a/hw/xwayland/xwayland-pixmap.h b/hw/xwayland/xwayland-pixmap.h index 036b532ef..b4b26c886 100644 --- a/hw/xwayland/xwayland-pixmap.h +++ b/hw/xwayland/xwayland-pixmap.h @@ -29,6 +29,8 @@ #include #include +#include "dix/resource_priv.h" + #include "pixmapstr.h" /* This is an opaque structure implemented in the different backends */ @@ -48,7 +50,7 @@ Bool xwl_pixmap_init(void); static inline Bool xwl_is_client_pixmap(PixmapPtr pixmap) { - return clients[CLIENT_ID(pixmap->drawable.id)] != serverClient; + return clients[dixClientIdForXID(pixmap->drawable.id)] != serverClient; } #endif /* XWAYLAND_PIXMAP_H */ diff --git a/hw/xwayland/xwayland-window.c b/hw/xwayland/xwayland-window.c index 77c66a25f..4d166ebc0 100644 --- a/hw/xwayland/xwayland-window.c +++ b/hw/xwayland/xwayland-window.c @@ -473,7 +473,7 @@ window_is_wm_window(WindowPtr window) { struct xwl_screen *xwl_screen = xwl_screen_get(window->drawable.pScreen); - return CLIENT_ID(window->drawable.id) == xwl_screen->wm_client_id; + return dixClientIdForXID(window->drawable.id) == xwl_screen->wm_client_id; } static WindowPtr @@ -1789,7 +1789,7 @@ xwl_change_window_attributes(WindowPtr window, unsigned long mask) for (others = wOtherClients(window); others; others = others->next) { if (others->mask & (SubstructureRedirectMask | ResizeRedirectMask)) - xwl_screen->wm_client_id = CLIENT_ID(others->resource); + xwl_screen->wm_client_id = dixClientIdForXID(others->resource); } return ret; diff --git a/include/resource.h b/include/resource.h index a384b59a0..5993c7ef5 100644 --- a/include/resource.h +++ b/include/resource.h @@ -111,7 +111,6 @@ extern _X_EXPORT unsigned int ResourceClientBits(void); /* extract the client mask from an XID */ #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK) /* extract the client id from an XID */ -#define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET)) #define SERVER_BIT (Mask)0x40000000 /* use illegal bit */ #ifdef INVALID diff --git a/record/record.c b/record/record.c index d8e730972..41046b0d0 100644 --- a/record/record.c +++ b/record/record.c @@ -36,6 +36,7 @@ and Jim Haggerty of Metheus. #include "dix/cursor_priv.h" #include "dix/eventconvert.h" +#include "dix/resource_priv.h" #include "os/client_priv.h" #include "dixstruct.h" @@ -864,7 +865,7 @@ RecordInstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient) if (pRCAP->pRequestMajorOpSet) { RecordSetIteratePtr pIter = NULL; RecordSetInterval interval; - ClientPtr pClient = clients[CLIENT_ID(client)]; + ClientPtr pClient = clients[dixClientIdForXID(client)]; if (pClient && !RecordClientPrivate(pClient)) { RecordClientPrivatePtr pClientPriv; @@ -947,7 +948,7 @@ RecordUninstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient) while (client) { if (client != XRecordFutureClients) { if (pRCAP->pRequestMajorOpSet) { - ClientPtr pClient = clients[CLIENT_ID(client)]; + ClientPtr pClient = clients[dixClientIdForXID(client)]; int c; Bool otherRCAPwantsProcVector = FALSE; RecordClientPrivatePtr pClientPriv = NULL; @@ -1152,7 +1153,7 @@ RecordSanityCheckClientSpecifiers(ClientPtr client, XID *clientspecs, continue; if (errorspec && (CLIENT_BITS(clientspecs[i]) == errorspec)) return BadMatch; - clientIndex = CLIENT_ID(clientspecs[i]); + clientIndex = dixClientIdForXID(clientspecs[i]); if (clientIndex && clients[clientIndex] && clients[clientIndex]->clientState == ClientStateRunning) { if (clientspecs[i] == clients[clientIndex]->clientAsMask)