xace: typesafe hook function for XACE_SEND_ACCESS

The generic XaceHook() call isn't typesafe (und unnecessarily slow).
Better add an explicit function, just like we already have for others.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1556>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-05-16 20:34:50 +02:00 committed by Marge Bot
parent 9524ffee89
commit 67e468c8bd
4 changed files with 18 additions and 21 deletions

View File

@ -78,13 +78,20 @@ int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode)
return rec.status;
}
int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
xEventPtr ev, int count)
{
XaceSendAccessRec rec = { client, dev, win, ev, count, Success };
CallCallbacks(&XaceHooks[XACE_SEND_ACCESS], &rec);
return rec.status;
}
/* Entry point for hook functions. Called by Xserver.
*/
int
XaceHook(int hook, ...)
{
union {
XaceSendAccessRec send;
XaceReceiveAccessRec recv;
XaceClientAccessRec client;
XaceExtAccessRec ext;
@ -107,17 +114,6 @@ XaceHook(int hook, ...)
* sets calldata directly to a single argument (with no return result)
*/
switch (hook) {
case XACE_SEND_ACCESS:
u.send.client = va_arg(ap, ClientPtr);
u.send.dev = va_arg(ap, DeviceIntPtr);
u.send.pWin = va_arg(ap, WindowPtr);
u.send.events = va_arg(ap, xEventPtr);
u.send.count = va_arg(ap, int);
u.send.status = Success; /* default allow */
prv = &u.send.status;
break;
case XACE_RECEIVE_ACCESS:
u.recv.client = va_arg(ap, ClientPtr);
u.recv.pWin = va_arg(ap, WindowPtr);

View File

@ -84,6 +84,9 @@ _X_EXPORT int XaceHookResourceAccess(ClientPtr client, XID id, RESTYPE rtype, vo
int XaceHookDeviceAccess(ClientPtr client, DeviceIntPtr dev, Mask access_mode);
int XaceHookSendAccess(ClientPtr client, DeviceIntPtr dev, WindowPtr win,
xEventPtr ev, int count);
/* Register a callback for a given hook.
*/
#define XaceRegisterCallback(hook,callback,data) \

View File

@ -2957,7 +2957,7 @@ SendEvent(ClientPtr client, DeviceIntPtr d, Window dest, Bool propagate,
break;
}
}
else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, ev, count))
else if (!XaceHookSendAccess(client, NULL, pWin, ev, count))
DeliverEventsToWindow(d, pWin, ev, count, mask, NullGrab);
return Success;
}

View File

@ -2789,7 +2789,7 @@ DeliverEvent(DeviceIntPtr dev, xEvent *xE, int count,
Mask filter;
int deliveries = 0;
if (XaceHook(XACE_SEND_ACCESS, NULL, dev, win, xE, count) == Success) {
if (XaceHookSendAccess(NULL, dev, win, xE, count) == Success) {
filter = GetEventFilter(dev, xE);
FixUpEventFromWindow(pSprite, xE, win, child, FALSE);
deliveries = DeliverEventsToWindow(dev, win, xE, count, filter, grab);
@ -4213,7 +4213,7 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
rc = EventToXI(event, &xE, &count);
if (rc == Success &&
XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, xE, count) == Success) {
XaceHookSendAccess(NULL, keybd, focus, xE, count) == Success) {
FixUpEventFromWindow(ptr->spriteInfo->sprite, xE, focus, None, FALSE);
deliveries = DeliverEventsToWindow(keybd, focus, xE, count,
GetEventFilter(keybd, xE), NullGrab);
@ -4229,7 +4229,7 @@ DeliverFocusedEvent(DeviceIntPtr keybd, InternalEvent *event, WindowPtr window)
if (sendCore) {
rc = EventToCore(event, &core, &count);
if (rc == Success) {
if (XaceHook(XACE_SEND_ACCESS, NULL, keybd, focus, core, count) ==
if (XaceHookSendAccess(NULL, keybd, focus, core, count) ==
Success) {
FixUpEventFromWindow(keybd->spriteInfo->sprite, core, focus,
None, FALSE);
@ -4302,8 +4302,7 @@ DeliverOneGrabbedEvent(InternalEvent *event, DeviceIntPtr dev,
if (rc == Success) {
FixUpEventFromWindow(pSprite, xE, grab->window, None, TRUE);
if (XaceHook(XACE_SEND_ACCESS, 0, dev,
grab->window, xE, count) ||
if (XaceHookSendAccess(0, dev, grab->window, xE, count) ||
XaceHook(XACE_RECEIVE_ACCESS, rClient(grab),
grab->window, xE, count))
deliveries = 1; /* don't send, but pretend we did */
@ -5532,8 +5531,7 @@ ProcSendEvent(ClientPtr client)
stuff->event.u.u.type |= SEND_EVENT_BIT;
if (stuff->propagate) {
for (; pWin; pWin = pWin->parent) {
if (XaceHook(XACE_SEND_ACCESS, client, NULL, pWin,
&stuff->event, 1))
if (XaceHookSendAccess(client, NULL, pWin, &stuff->event, 1))
return Success;
if (DeliverEventsToWindow(dev, pWin,
&stuff->event, 1, stuff->eventMask,
@ -5546,7 +5544,7 @@ ProcSendEvent(ClientPtr client)
break;
}
}
else if (!XaceHook(XACE_SEND_ACCESS, client, NULL, pWin, &stuff->event, 1))
else if (!XaceHookSendAccess(client, NULL, pWin, &stuff->event, 1))
DeliverEventsToWindow(dev, pWin, &stuff->event,
1, stuff->eventMask, NullGrab);
return Success;