(!1899) 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 <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-03-05 12:43:10 +01:00
parent a072c68aad
commit bf204fcacf
23 changed files with 88 additions and 61 deletions

View File

@ -32,6 +32,7 @@ Equipment Corporation.
#include <X11/extensions/panoramiXproto.h> #include <X11/extensions/panoramiXproto.h>
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "dix/screen_hooks_priv.h" #include "dix/screen_hooks_priv.h"
#include "misc.h" #include "misc.h"
@ -352,7 +353,7 @@ PanoramiXFindIDByScrnum(RESTYPE type, XID id, int screen)
data.screen = screen; data.screen = screen;
data.id = id; data.id = id;
return LookupClientResourceComplex(clients[CLIENT_ID(id)], type, return LookupClientResourceComplex(clients[dixClientIdForXID(id)], type,
XineramaFindIDByScrnum, &data); XineramaFindIDByScrnum, &data);
} }

View File

@ -743,7 +743,7 @@ SecurityResource(CallbackListPtr *pcbl, void *unused, void *calldata)
{ {
XaceResourceAccessRec *rec = calldata; XaceResourceAccessRec *rec = calldata;
SecurityStateRec *subj, *obj; SecurityStateRec *subj, *obj;
int cid = CLIENT_ID(rec->id); int cid = dixClientIdForXID(rec->id);
Mask requested = rec->access_mode; Mask requested = rec->access_mode;
Mask allowed = SecurityResourceMask; Mask allowed = SecurityResourceMask;

View File

@ -12,6 +12,7 @@
#include <X11/extensions/XResproto.h> #include <X11/extensions/XResproto.h>
#include "dix/registry_priv.h" #include "dix/registry_priv.h"
#include "dix/resource_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "Xext/xace.h" #include "Xext/xace.h"
@ -301,12 +302,12 @@ ProcXResQueryClientResources(ClientPtr client)
{ {
REQUEST(xXResQueryClientResourcesReq); REQUEST(xXResQueryClientResourcesReq);
xXResQueryClientResourcesReply rep; xXResQueryClientResourcesReply rep;
int i, clientID, num_types; int i, num_types;
int *counts; int *counts;
REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq); REQUEST_SIZE_MATCH(xXResQueryClientResourcesReq);
clientID = CLIENT_ID(stuff->xid); int clientID = dixClientIdForXID(stuff->xid);
if ((clientID >= currentMaxClients) || !clients[clientID] || if ((clientID >= currentMaxClients) || !clients[clientID] ||
(XaceHookClientAccess(client, clients[clientID], DixReadAccess) (XaceHookClientAccess(client, clients[clientID], DixReadAccess)
@ -379,12 +380,11 @@ ProcXResQueryClientPixmapBytes(ClientPtr client)
{ {
REQUEST(xXResQueryClientPixmapBytesReq); REQUEST(xXResQueryClientPixmapBytesReq);
xXResQueryClientPixmapBytesReply rep; xXResQueryClientPixmapBytesReply rep;
int clientID;
unsigned long bytes; unsigned long bytes;
REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq); REQUEST_SIZE_MATCH(xXResQueryClientPixmapBytesReq);
clientID = CLIENT_ID(stuff->xid); int clientID = dixClientIdForXID(stuff->xid);
if ((clientID >= currentMaxClients) || !clients[clientID] || if ((clientID >= currentMaxClients) || !clients[clientID] ||
(XaceHookClientAccess(client, clients[clientID], DixReadAccess) (XaceHookClientAccess(client, clients[clientID], DixReadAccess)
@ -555,7 +555,7 @@ ConstructClientIds(ClientPtr client,
} }
} }
} else { } else {
int clientID = CLIENT_ID(specs[specIdx].client); int clientID = dixClientIdForXID(specs[specIdx].client);
if ((clientID < currentMaxClients) && clients[clientID] && if ((clientID < currentMaxClients) && clients[clientID] &&
(XaceHookClientAccess(client, clients[clientID], DixReadAccess) (XaceHookClientAccess(client, clients[clientID], DixReadAccess)
@ -897,7 +897,7 @@ ConstructResourceBytesByResource(XID aboutClient, ConstructResourceBytesCtx *ctx
for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) { for (specIdx = 0; specIdx < ctx->numSpecs; ++specIdx) {
xXResResourceIdSpec *spec = ctx->specs + specIdx; xXResResourceIdSpec *spec = ctx->specs + specIdx;
if (spec->resource) { if (spec->resource) {
int cid = CLIENT_ID(spec->resource); int cid = dixClientIdForXID(spec->resource);
if (cid < currentMaxClients && if (cid < currentMaxClients &&
(aboutClient == None || cid == aboutClient)) { (aboutClient == None || cid == aboutClient)) {
ClientPtr client = clients[cid]; ClientPtr client = clients[cid];
@ -925,7 +925,7 @@ ConstructResourceBytes(XID aboutClient,
ConstructResourceBytesCtx *ctx) ConstructResourceBytesCtx *ctx)
{ {
if (aboutClient) { if (aboutClient) {
int clientIdx = CLIENT_ID(aboutClient); int clientIdx = dixClientIdForXID(aboutClient);
ClientPtr client = NullClient; ClientPtr client = NullClient;
if ((clientIdx >= currentMaxClients) || !clients[clientIdx]) { if ((clientIdx >= currentMaxClients) || !clients[clientIdx]) {

View File

@ -632,7 +632,7 @@ SELinuxResource(CallbackListPtr *pcbl, void *unused, void *calldata)
if (offset < 0) { if (offset < 0) {
/* No: use the SID of the owning client */ /* No: use the SID of the owning client */
class = SECCLASS_X_RESOURCE; class = SECCLASS_X_RESOURCE;
privatePtr = &clients[CLIENT_ID(rec->id)]->devPrivates; privatePtr = &clients[dixClientIdForXID(rec->id)]->devPrivates;
obj = dixLookupPrivate(privatePtr, objectKey); obj = dixLookupPrivate(privatePtr, objectKey);
} }
else { else {

View File

@ -1743,7 +1743,7 @@ ProcessBarrierEvent(InternalEvent *e, DeviceIntPtr dev)
Otherwise, deliver normally to the client. Otherwise, deliver normally to the client.
*/ */
if (grab && if (grab &&
CLIENT_ID(be->barrierid) == CLIENT_ID(grab->resource) && dixClientIdForXID(be->barrierid) == dixClientIdForXID(grab->resource) &&
grab->window->drawable.id == be->window) { grab->window->drawable.id == be->window) {
DeliverGrabbedEvent(e, dev, FALSE); DeliverGrabbedEvent(e, dev, FALSE);
} else { } else {

View File

@ -46,6 +46,7 @@
#include "dix/cursor_priv.h" #include "dix/cursor_priv.h"
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/resource_priv.h"
#include "mi/mi_priv.h" #include "mi/mi_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
@ -841,7 +842,7 @@ XIDestroyPointerBarrier(ClientPtr client,
return err; return err;
} }
if (CLIENT_ID(stuff->barrier) != client->index) if (dixClientIdForXID(stuff->barrier) != client->index)
return BadAccess; return BadAccess;
FreeResource(stuff->barrier, X11_RESTYPE_NONE); FreeResource(stuff->barrier, X11_RESTYPE_NONE);
@ -910,10 +911,9 @@ ProcXIBarrierReleasePointer(ClientPtr client)
return err; return err;
} }
if (CLIENT_ID(barrier_id) != client->index) if (dixClientIdForXID(barrier_id) != client->index)
return BadAccess; return BadAccess;
barrier = container_of(b, struct PointerBarrierClient, barrier); barrier = container_of(b, struct PointerBarrierClient, barrier);
pbd = GetBarrierDevice(barrier, dev->id); pbd = GetBarrierDevice(barrier, dev->id);

View File

@ -29,6 +29,7 @@
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/resource_priv.h"
#include "dixstruct.h" #include "dixstruct.h"
#include "windowstr.h" #include "windowstr.h"
@ -56,7 +57,7 @@ check_for_touch_selection_conflicts(ClientPtr B, WindowPtr win, int deviceid,
for (; A; A = A->next) { for (; A; A = A->next) {
DeviceIntPtr tmp; DeviceIntPtr tmp;
if (CLIENT_ID(A->resource) == B->index) if (dixClientIdForXID(A->resource) == B->index)
continue; continue;
if (deviceid == XIAllDevices) if (deviceid == XIAllDevices)

View File

@ -43,6 +43,7 @@
#include <dix-config.h> #include <dix-config.h>
#include "dix/resource_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
#include "compint.h" #include "compint.h"
@ -332,7 +333,7 @@ compUnredirectWindow(ClientPtr pClient, WindowPtr pWin, int update)
return BadValue; return BadValue;
for (ccw = cw->clients; ccw; ccw = ccw->next) 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); FreeResource(ccw->id, X11_RESTYPE_NONE);
return Success; return Success;
} }
@ -430,7 +431,7 @@ compFreeClientSubwindows(WindowPtr pWin, XID id)
return; return;
for (prev = &csw->clients; (ccw = *prev); prev = &ccw->next) { for (prev = &csw->clients; (ccw = *prev); prev = &ccw->next) {
if (ccw->id == id) { if (ccw->id == id) {
ClientPtr pClient = clients[CLIENT_ID(id)]; ClientPtr pClient = clients[dixClientIdForXID(id)];
*prev = ccw->next; *prev = ccw->next;
if (ccw->update == CompositeRedirectManual) { if (ccw->update == CompositeRedirectManual) {
@ -479,7 +480,7 @@ compUnredirectSubwindows(ClientPtr pClient, WindowPtr pWin, int update)
if (!csw) if (!csw)
return BadValue; return BadValue;
for (ccw = csw->clients; ccw; ccw = ccw->next) 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); FreeResource(ccw->id, X11_RESTYPE_NONE);
return Success; return Success;
} }
@ -499,7 +500,7 @@ compRedirectOneSubwindow(WindowPtr pParent, WindowPtr pWin)
if (!csw) if (!csw)
return Success; return Success;
for (ccw = csw->clients; ccw; ccw = ccw->next) { 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); pWin, ccw->update);
if (ret != Success) if (ret != Success)
@ -521,7 +522,7 @@ compUnredirectOneSubwindow(WindowPtr pParent, WindowPtr pWin)
if (!csw) if (!csw)
return Success; return Success;
for (ccw = csw->clients; ccw; ccw = ccw->next) { 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); pWin, ccw->update);
if (ret != Success) if (ret != Success)

View File

@ -575,7 +575,7 @@ compCreateWindow(WindowPtr pWin)
(*pScreen->SetWindowPixmap) (pWin, parent_pixmap); (*pScreen->SetWindowPixmap) (pWin, parent_pixmap);
if (csw) if (csw)
for (ccw = csw->clients; ccw; ccw = ccw->next) for (ccw = csw->clients; ccw; ccw = ccw->next)
compRedirectWindow(clients[CLIENT_ID(ccw->id)], compRedirectWindow(clients[dixClientIdForXID(ccw->id)],
pWin, ccw->update); pWin, ccw->update);
if (compImplicitRedirect(pWin, pWin->parent)) if (compImplicitRedirect(pWin, pWin->parent))
compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic); compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);

View File

@ -54,6 +54,7 @@ SOFTWARE.
#include "dix/colormap_priv.h" #include "dix/colormap_priv.h"
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "os/osdep.h" #include "os/osdep.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
@ -417,7 +418,7 @@ FreeColormap(void *value, XID mid)
EntryPtr pent; EntryPtr pent;
ColormapPtr pmap = (ColormapPtr) value; ColormapPtr pmap = (ColormapPtr) value;
if (CLIENT_ID(mid) != SERVER_ID) { if (dixClientIdForXID(mid) != SERVER_ID) {
(*pmap->pScreen->UninstallColormap) (pmap); (*pmap->pScreen->UninstallColormap) (pmap);
WalkTree(pmap->pScreen, (VisitWindowProcPtr) TellNoMap, (void *) &mid); WalkTree(pmap->pScreen, (VisitWindowProcPtr) TellNoMap, (void *) &mid);
} }
@ -548,7 +549,7 @@ CopyColormapAndFree(Colormap mid, ColormapPtr pSrc, int client)
pScreen = pSrc->pScreen; pScreen = pSrc->pScreen;
pVisual = pSrc->pVisual; pVisual = pSrc->pVisual;
midSrc = pSrc->mid; midSrc = pSrc->mid;
alloc = ((pSrc->flags & CM_AllAllocated) && CLIENT_ID(midSrc) == client) ? alloc = ((pSrc->flags & CM_AllAllocated) && dixClientIdForXID(midSrc) == client) ?
AllocAll : AllocNone; AllocAll : AllocNone;
size = pVisual->ColormapEntries; size = pVisual->ColormapEntries;
@ -1088,7 +1089,8 @@ AllocColor(ColormapPtr pmap,
* resource manager that the client has pixels in this colormap which * resource manager that the client has pixels in this colormap which
* should be freed when the client dies */ * should be freed when the client dies */
if ((pmap->numPixelsRed[client] == 1) && if ((pmap->numPixelsRed[client] == 1) &&
(CLIENT_ID(pmap->mid) != client) && !(pmap->flags & CM_BeingCreated)) { (dixClientIdForXID(pmap->mid) != client) && !(pmap->flags & CM_BeingCreated)) {
colorResource *pcr = calloc(1, sizeof(colorResource)); colorResource *pcr = calloc(1, sizeof(colorResource));
if (!pcr) { if (!pcr) {
(void) FreeColors(pmap, client, 1, pPix, (Pixel) 0); (void) FreeColors(pmap, client, 1, pPix, (Pixel) 0);
@ -1507,7 +1509,7 @@ AllocColorCells(ClientPtr pClient, ColormapPtr pmap, int colors, int planes,
oldcount = pmap->numPixelsRed[client]; oldcount = pmap->numPixelsRed[client];
if (pmap->class == DirectColor) if (pmap->class == DirectColor)
oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { if (!oldcount && (dixClientIdForXID(pmap->mid) != client)) {
pcr = calloc(1, sizeof(colorResource)); pcr = calloc(1, sizeof(colorResource));
if (!pcr) if (!pcr)
return BadAlloc; return BadAlloc;
@ -1574,7 +1576,7 @@ AllocColorPlanes(int client, ColormapPtr pmap, int colors,
oldcount = pmap->numPixelsRed[client]; oldcount = pmap->numPixelsRed[client];
if (class == DirectColor) if (class == DirectColor)
oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client]; oldcount += pmap->numPixelsGreen[client] + pmap->numPixelsBlue[client];
if (!oldcount && (CLIENT_ID(pmap->mid) != client)) { if (!oldcount && (dixClientIdForXID(pmap->mid) != client)) {
pcr = calloc(1, sizeof(colorResource)); pcr = calloc(1, sizeof(colorResource));
if (!pcr) if (!pcr)
return BadAlloc; return BadAlloc;

View File

@ -26,6 +26,7 @@
#include "include/gc.h" #include "include/gc.h"
#include "include/input.h" #include "include/input.h"
#include "include/os.h" #include "include/os.h"
#include "include/resource.h"
#include "include/window.h" #include "include/window.h"
/* server setting: maximum size for big requests */ /* server setting: maximum size for big requests */

View File

@ -87,6 +87,7 @@ Author: Adobe Systems Incorporated
#include "dix/callback_priv.h" #include "dix/callback_priv.h"
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "misc.h" #include "misc.h"
#include "windowstr.h" #include "windowstr.h"
@ -221,7 +222,7 @@ int
dixLookupResourceOwner(ClientPtr *result, XID id, ClientPtr client, Mask access_mode) dixLookupResourceOwner(ClientPtr *result, XID id, ClientPtr client, Mask access_mode)
{ {
void *pRes; void *pRes;
int rc = BadValue, clientIndex = CLIENT_ID(id); int rc = BadValue, clientIndex = dixClientIdForXID(id);
if (!clientIndex || !clients[clientIndex] || (id & SERVER_BIT)) if (!clientIndex || !clients[clientIndex] || (id & SERVER_BIT))
goto bad; goto bad;

View File

@ -1426,8 +1426,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode)
else { /* free both if same client owns both */ else { /* free both if same client owns both */
thisDev->deviceGrab.sync.state = GRAB_STATE_THAWED; thisDev->deviceGrab.sync.state = GRAB_STATE_THAWED;
if (thisDev->deviceGrab.sync.other && if (thisDev->deviceGrab.sync.other &&
(CLIENT_BITS(thisDev->deviceGrab.sync.other->resource) == (dixClientIdForXID(thisDev->deviceGrab.sync.other->resource) ==
CLIENT_BITS(grab->resource))) dixClientIdForXID(grab->resource)))
thisDev->deviceGrab.sync.other = NullGrab; thisDev->deviceGrab.sync.other = NullGrab;
} }
@ -1437,8 +1437,8 @@ CheckGrabForSyncs(DeviceIntPtr thisDev, Bool thisMode, Bool otherMode)
dev->deviceGrab.sync.other = grab; dev->deviceGrab.sync.other = grab;
else { /* free both if same client owns both */ else { /* free both if same client owns both */
if (dev->deviceGrab.sync.other && if (dev->deviceGrab.sync.other &&
(CLIENT_BITS(dev->deviceGrab.sync.other->resource) == (dixClientIdForXID(dev->deviceGrab.sync.other->resource) ==
CLIENT_BITS(grab->resource))) dixClientIdForXID(grab->resource)))
dev->deviceGrab.sync.other = NullGrab; dev->deviceGrab.sync.other = NullGrab;
} }
} }
@ -4424,8 +4424,8 @@ FreezeThisEventIfNeededForSyncGrab(DeviceIntPtr thisDev, InternalEvent *event)
if (dev) { if (dev) {
FreezeThaw(dev, TRUE); FreezeThaw(dev, TRUE);
if ((dev->deviceGrab.sync.state == GRAB_STATE_FREEZE_BOTH_NEXT_EVENT) && if ((dev->deviceGrab.sync.state == GRAB_STATE_FREEZE_BOTH_NEXT_EVENT) &&
(CLIENT_BITS(grab->resource) == (dixClientIdForXID(grab->resource) ==
CLIENT_BITS(dev->deviceGrab.grab->resource))) dixClientIdForXID(dev->deviceGrab.grab->resource)))
dev->deviceGrab.sync.state = GRAB_STATE_FROZEN_NO_EVENT; dev->deviceGrab.sync.state = GRAB_STATE_FROZEN_NO_EVENT;
else else
dev->deviceGrab.sync.other = grab; dev->deviceGrab.sync.other = grab;
@ -6286,5 +6286,5 @@ IsWrongPointerBarrierClient(ClientPtr client, DeviceIntPtr dev, xEvent *event)
if (ev->evtype != XI_BarrierHit && ev->evtype != XI_BarrierLeave) if (ev->evtype != XI_BarrierHit && ev->evtype != XI_BarrierLeave)
return FALSE; return FALSE;
return client->index != CLIENT_ID(ev->barrier); return client->index != dixClientIdForXID(ev->barrier);
} }

View File

@ -55,6 +55,7 @@ SOFTWARE.
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/dixgrabs_priv.h" #include "dix/dixgrabs_priv.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/resource_priv.h"
#include "os/auth.h" #include "os/auth.h"
#include "os/client_priv.h" #include "os/client_priv.h"
@ -88,7 +89,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
(grab->grabtype == XI2) ? "xi2" : (grab->grabtype == XI2) ? "xi2" :
((grab->grabtype == CORE) ? "core" : "xi1"), dev->name, dev->id); ((grab->grabtype == CORE) ? "core" : "xi1"), dev->name, dev->id);
client = clients[CLIENT_ID(grab->resource)]; client = clients[dixClientIdForXID(grab->resource)];
if (client) { if (client) {
pid_t clientpid = GetClientPid(client); pid_t clientpid = GetClientPid(client);
const char *cmdname = GetClientCmdName(client); const char *cmdname = GetClientCmdName(client);
@ -110,7 +111,7 @@ PrintDeviceGrabInfo(DeviceIntPtr dev)
} }
if (!clientIdPrinted) { if (!clientIdPrinted) {
ErrorF(" (no client information available for client %d)\n", ErrorF(" (no client information available for client %d)\n",
CLIENT_ID(grab->resource)); dixClientIdForXID(grab->resource));
} }
/* XXX is this even correct? */ /* XXX is this even correct? */
@ -181,7 +182,7 @@ UngrabAllDevices(Bool kill_client)
if (!dev->deviceGrab.grab) if (!dev->deviceGrab.grab)
continue; continue;
PrintDeviceGrabInfo(dev); PrintDeviceGrabInfo(dev);
client = clients[CLIENT_ID(dev->deviceGrab.grab->resource)]; client = clients[dixClientIdForXID(dev->deviceGrab.grab->resource)];
if (!kill_client || !client || client->clientGone) if (!kill_client || !client || client->clientGone)
dev->deviceGrab.DeactivateGrab(dev); dev->deviceGrab.DeactivateGrab(dev);
if (kill_client) if (kill_client)
@ -538,7 +539,7 @@ AddPassiveGrabToList(ClientPtr client, GrabPtr pGrab)
for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) { for (grab = wPassiveGrabs(pGrab->window); grab; grab = grab->next) {
if (GrabMatchesSecond(pGrab, grab, (pGrab->grabtype == CORE))) { 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); FreeGrab(pGrab);
return BadAccess; return BadAccess;
} }
@ -618,7 +619,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
ok = TRUE; ok = TRUE;
for (grab = wPassiveGrabs(pMinuendGrab->window); for (grab = wPassiveGrabs(pMinuendGrab->window);
grab && ok; grab = grab->next) { 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))) || !GrabMatchesSecond(grab, pMinuendGrab, (grab->grabtype == CORE)))
continue; continue;
if (GrabSupersedesSecond(pMinuendGrab, grab)) { if (GrabSupersedesSecond(pMinuendGrab, grab)) {
@ -646,7 +647,7 @@ DeletePassiveGrabFromList(GrabPtr pMinuendGrab)
param.other_devices_mode = grab->pointerMode; param.other_devices_mode = grab->pointerMode;
param.modifiers = any_modifier; param.modifiers = any_modifier;
pNewGrab = CreateGrab(CLIENT_ID(grab->resource), grab->device, pNewGrab = CreateGrab(dixClientIdForXID(grab->resource), grab->device,
grab->modifierDevice, grab->window, grab->modifierDevice, grab->window,
grab->grabtype, grab->grabtype,
(GrabMask *) &grab->eventMask, (GrabMask *) &grab->eventMask,

View File

@ -16,26 +16,26 @@ ClientPtr dixClientForWindow(WindowPtr pWin) {
if (!pWin) if (!pWin)
return NullClient; return NullClient;
return clients[CLIENT_ID(pWin->drawable.id)]; return clients[dixClientIdForXID(pWin->drawable.id)];
} }
ClientPtr dixClientForGrab(GrabPtr pGrab) { ClientPtr dixClientForGrab(GrabPtr pGrab) {
if (!pGrab) if (!pGrab)
return NullClient; return NullClient;
return clients[CLIENT_ID(pGrab->resource)]; return clients[dixClientIdForXID(pGrab->resource)];
} }
ClientPtr dixClientForInputClients(InputClientsPtr pInputClients) { ClientPtr dixClientForInputClients(InputClientsPtr pInputClients) {
if (!pInputClients) if (!pInputClients)
return NullClient; return NullClient;
return clients[CLIENT_ID(pInputClients->resource)]; return clients[dixClientIdForXID(pInputClients->resource)];
} }
ClientPtr dixClientForOtherClients(OtherClientsPtr pOtherClients) { ClientPtr dixClientForOtherClients(OtherClientsPtr pOtherClients) {
if (!pOtherClients) if (!pOtherClients)
return NullClient; return NullClient;
return clients[CLIENT_ID(pOtherClients->resource)]; return clients[dixClientIdForXID(pOtherClients->resource)];
} }

View File

@ -112,7 +112,7 @@ Equipment Corporation.
* like it belongs to a client. This ID, however, must not be one * 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 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 * 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 * 1, and an otherwise arbitrary ID in the low 22 bits, we can create a
* resource "owned" by the client. * resource "owned" by the client.
*/ */
@ -126,6 +126,7 @@ Equipment Corporation.
#include "dix/dixgrabs_priv.h" #include "dix/dixgrabs_priv.h"
#include "dix/gc_priv.h" #include "dix/gc_priv.h"
#include "dix/registry_priv.h" #include "dix/registry_priv.h"
#include "dix/resource_priv.h"
#include "os/osdep.h" #include "os/osdep.h"
#include "misc.h" #include "misc.h"
@ -824,7 +825,7 @@ AddResource(XID id, RESTYPE type, void *value)
#ifdef XSERVER_DTRACE #ifdef XSERVER_DTRACE
XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type)); XSERVER_RESOURCE_ALLOC(id, type, value, TypeNameString(type));
#endif #endif
client = CLIENT_ID(id); client = dixClientIdForXID(id);
rrec = &clientTable[client]; rrec = &clientTable[client];
if (!rrec->buckets) { if (!rrec->buckets) {
ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n", ErrorF("[dix] AddResource(%lx, %x, %lx), client=%d \n",
@ -912,7 +913,7 @@ FreeResource(XID id, RESTYPE skipDeleteFuncType)
int *eltptr; int *eltptr;
int elements; 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)]; head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
eltptr = &clientTable[cid].elements; eltptr = &clientTable[cid].elements;
@ -946,7 +947,7 @@ FreeResourceByType(XID id, RESTYPE type, Bool skipFree)
ResourcePtr res; ResourcePtr res;
ResourcePtr *prev, *head; 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)]; head = &clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
prev = head; prev = head;
@ -981,7 +982,7 @@ ChangeResourceValue(XID id, RESTYPE rtype, void *value)
int cid; int cid;
ResourcePtr res; 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)]; res = clientTable[cid].resources[HashResourceID(id, clientTable[cid].hashsize)];
for (; res; res = res->next) for (; res; res = res->next)
@ -1212,7 +1213,7 @@ int
dixLookupResourceByType(void **result, XID id, RESTYPE rtype, dixLookupResourceByType(void **result, XID id, RESTYPE rtype,
ClientPtr client, Mask mode) ClientPtr client, Mask mode)
{ {
int cid = CLIENT_ID(id); int cid = dixClientIdForXID(id);
ResourcePtr res = NULL; ResourcePtr res = NULL;
*result = NULL; *result = NULL;
@ -1249,7 +1250,7 @@ int
dixLookupResourceByClass(void **result, XID id, RESTYPE rclass, dixLookupResourceByClass(void **result, XID id, RESTYPE rclass,
ClientPtr client, Mask mode) ClientPtr client, Mask mode)
{ {
int cid = CLIENT_ID(id); int cid = dixClientIdForXID(id);
ResourcePtr res = NULL; ResourcePtr res = NULL;
*result = NULL; *result = NULL;

View File

@ -51,4 +51,19 @@ ClientPtr dixClientForInputClients(InputClientsPtr pInputClients);
*/ */
ClientPtr dixClientForOtherClients(OtherClientsPtr pOtherClients); 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 */ #endif /* _XSERVER_DIX_RESOURCE_PRIV_H */

View File

@ -31,6 +31,7 @@
#include "dix/eventconvert.h" #include "dix/eventconvert.h"
#include "dix/exevents_priv.h" #include "dix/exevents_priv.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/resource_priv.h"
#include "mi/mi_priv.h" #include "mi/mi_priv.h"
#include "os/bug_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++) { 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) ti->listeners[i].window->drawable.id == grab_window)
break; break;
} }

View File

@ -36,6 +36,7 @@
#include <X11/extensions/presenttokens.h> #include <X11/extensions/presenttokens.h>
#include "dix/dix_priv.h" #include "dix/dix_priv.h"
#include "dix/resource_priv.h"
#include "os/bug_priv.h" #include "os/bug_priv.h"
#include "glxserver.h" #include "glxserver.h"
@ -2504,7 +2505,7 @@ void
__glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust, __glXsendSwapEvent(__GLXdrawable *drawable, int type, CARD64 ust,
CARD64 msc, CARD32 sbc) CARD64 msc, CARD32 sbc)
{ {
ClientPtr client = clients[CLIENT_ID(drawable->drawId)]; ClientPtr client = clients[dixClientIdForXID(drawable->drawId)];
xGLXBufferSwapComplete2 wire = { xGLXBufferSwapComplete2 wire = {
.type = __glXEventBase + GLX_BufferSwapComplete .type = __glXEventBase + GLX_BufferSwapComplete

View File

@ -29,6 +29,8 @@
#include <xwayland-config.h> #include <xwayland-config.h>
#include <wayland-client.h> #include <wayland-client.h>
#include "dix/resource_priv.h"
#include "pixmapstr.h" #include "pixmapstr.h"
/* This is an opaque structure implemented in the different backends */ /* This is an opaque structure implemented in the different backends */
@ -48,7 +50,7 @@ Bool xwl_pixmap_init(void);
static inline Bool static inline Bool
xwl_is_client_pixmap(PixmapPtr pixmap) 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 */ #endif /* XWAYLAND_PIXMAP_H */

View File

@ -471,7 +471,7 @@ window_is_wm_window(WindowPtr window)
{ {
struct xwl_screen *xwl_screen = xwl_screen_get(window->drawable.pScreen); 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 static WindowPtr
@ -1787,7 +1787,7 @@ xwl_change_window_attributes(WindowPtr window, unsigned long mask)
for (others = wOtherClients(window); others; others = others->next) { for (others = wOtherClients(window); others; others = others->next) {
if (others->mask & (SubstructureRedirectMask | ResizeRedirectMask)) if (others->mask & (SubstructureRedirectMask | ResizeRedirectMask))
xwl_screen->wm_client_id = CLIENT_ID(others->resource); xwl_screen->wm_client_id = dixClientIdForXID(others->resource);
} }
return ret; return ret;

View File

@ -110,8 +110,6 @@ extern _X_EXPORT unsigned int ResourceClientBits(void);
#define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET) #define RESOURCE_CLIENT_MASK (((1 << RESOURCE_CLIENT_BITS) - 1) << CLIENTOFFSET)
/* extract the client mask from an XID */ /* extract the client mask from an XID */
#define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK) #define CLIENT_BITS(id) ((id) & RESOURCE_CLIENT_MASK)
/* extract the client id from an XID */
#define CLIENT_ID(id) ((int)(CLIENT_BITS(id) >> CLIENTOFFSET))
/* /*
* Resource IDs having that bit set still belonging to some client, * Resource IDs having that bit set still belonging to some client,

View File

@ -37,6 +37,7 @@ and Jim Haggerty of Metheus.
#include "dix/cursor_priv.h" #include "dix/cursor_priv.h"
#include "dix/eventconvert.h" #include "dix/eventconvert.h"
#include "dix/input_priv.h" #include "dix/input_priv.h"
#include "dix/resource_priv.h"
#include "os/client_priv.h" #include "os/client_priv.h"
#include "dixstruct.h" #include "dixstruct.h"
@ -865,7 +866,7 @@ RecordInstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient)
if (pRCAP->pRequestMajorOpSet) { if (pRCAP->pRequestMajorOpSet) {
RecordSetIteratePtr pIter = NULL; RecordSetIteratePtr pIter = NULL;
RecordSetInterval interval; RecordSetInterval interval;
ClientPtr pClient = clients[CLIENT_ID(client)]; ClientPtr pClient = clients[dixClientIdForXID(client)];
if (pClient && !RecordClientPrivate(pClient)) { if (pClient && !RecordClientPrivate(pClient)) {
RecordClientPrivatePtr pClientPriv; RecordClientPrivatePtr pClientPriv;
@ -948,7 +949,7 @@ RecordUninstallHooks(RecordClientsAndProtocolPtr pRCAP, XID oneclient)
while (client) { while (client) {
if (client != XRecordFutureClients) { if (client != XRecordFutureClients) {
if (pRCAP->pRequestMajorOpSet) { if (pRCAP->pRequestMajorOpSet) {
ClientPtr pClient = clients[CLIENT_ID(client)]; ClientPtr pClient = clients[dixClientIdForXID(client)];
int c; int c;
Bool otherRCAPwantsProcVector = FALSE; Bool otherRCAPwantsProcVector = FALSE;
RecordClientPrivatePtr pClientPriv = NULL; RecordClientPrivatePtr pClientPriv = NULL;
@ -1153,7 +1154,7 @@ RecordSanityCheckClientSpecifiers(ClientPtr client, XID *clientspecs,
continue; continue;
if (errorspec && (CLIENT_BITS(clientspecs[i]) == errorspec)) if (errorspec && (CLIENT_BITS(clientspecs[i]) == errorspec))
return BadMatch; return BadMatch;
clientIndex = CLIENT_ID(clientspecs[i]); clientIndex = dixClientIdForXID(clientspecs[i]);
if (clientIndex && clients[clientIndex] && if (clientIndex && clients[clientIndex] &&
clients[clientIndex]->clientState == ClientStateRunning) { clients[clientIndex]->clientState == ClientStateRunning) {
if (clientspecs[i] == clients[clientIndex]->clientAsMask) if (clientspecs[i] == clients[clientIndex]->clientAsMask)