Xext: shm: use REQUEST_HEAD_STRUCT and REQUEST_FIELD_* macros

Use the new macros to make request struct parsing / field swapping
much easier.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult
2024-07-03 19:31:02 +02:00
parent e913998fc2
commit ef8ade4c81

View File

@@ -45,6 +45,7 @@ in this Software without prior written authorization from The Open Group.
#include <X11/Xfuncproto.h>
#include "dix/dix_priv.h"
#include "dix/request_priv.h"
#include "os/auth.h"
#include "os/busfault.h"
#include "os/osdep.h"
@@ -278,6 +279,8 @@ ShmRegisterFbFuncs(ScreenPtr pScreen)
static int
ProcShmQueryVersion(ClientPtr client)
{
REQUEST_HEAD_STRUCT(xShmQueryVersionReq);
xShmQueryVersionReply rep = {
.type = X_Reply,
.sharedPixmaps = sharedPixmaps,
@@ -290,8 +293,6 @@ ProcShmQueryVersion(ClientPtr client)
.pixmapFormat = sharedPixmaps ? ZPixmap : 0
};
REQUEST_SIZE_MATCH(xShmQueryVersionReq);
if (client->swapped) {
swaps(&rep.sequenceNumber);
swapl(&rep.length);
@@ -373,8 +374,9 @@ shm_access(ClientPtr client, SHMPERM_TYPE * perm, int readonly)
static int
ProcShmAttach(ClientPtr client)
{
REQUEST(xShmAttachReq);
REQUEST_SIZE_MATCH(xShmAttachReq);
REQUEST_HEAD_STRUCT(xShmAttachReq);
REQUEST_FIELD_CARD32(shmseg);
REQUEST_FIELD_CARD32(shmid);
if (!client->local)
return BadRequest;
@@ -458,8 +460,8 @@ ShmDetachSegment(void *value, /* must conform to DeleteType */
static int
ProcShmDetach(ClientPtr client)
{
REQUEST(xShmDetachReq);
REQUEST_SIZE_MATCH(xShmDetachReq);
REQUEST_HEAD_STRUCT(xShmDetachReq);
REQUEST_FIELD_CARD32(shmseg);
if (!client->local)
return BadRequest;
@@ -736,8 +738,19 @@ ShmGetImage(ClientPtr client, xShmGetImageReq *stuff)
static int
ProcShmPutImage(ClientPtr client)
{
REQUEST(xShmPutImageReq);
REQUEST_SIZE_MATCH(xShmPutImageReq);
REQUEST_HEAD_STRUCT(xShmPutImageReq);
REQUEST_FIELD_CARD32(drawable);
REQUEST_FIELD_CARD32(gc);
REQUEST_FIELD_CARD16(totalWidth);
REQUEST_FIELD_CARD16(totalHeight);
REQUEST_FIELD_CARD16(srcX);
REQUEST_FIELD_CARD16(srcY);
REQUEST_FIELD_CARD16(srcWidth);
REQUEST_FIELD_CARD16(srcHeight);
REQUEST_FIELD_CARD16(dstX);
REQUEST_FIELD_CARD16(dstY);
REQUEST_FIELD_CARD32(shmseg);
REQUEST_FIELD_CARD32(offset);
if (!client->local)
return BadRequest;
@@ -788,8 +801,15 @@ ProcShmPutImage(ClientPtr client)
static int
ProcShmGetImage(ClientPtr client)
{
REQUEST(xShmGetImageReq);
REQUEST_SIZE_MATCH(xShmGetImageReq);
REQUEST_HEAD_STRUCT(xShmGetImageReq);
REQUEST_FIELD_CARD32(drawable);
REQUEST_FIELD_CARD16(x);
REQUEST_FIELD_CARD16(y);
REQUEST_FIELD_CARD16(width);
REQUEST_FIELD_CARD16(height);
REQUEST_FIELD_CARD32(planeMask);
REQUEST_FIELD_CARD32(shmseg);
REQUEST_FIELD_CARD32(offset);
if (!client->local)
return BadRequest;
@@ -938,8 +958,13 @@ ProcShmGetImage(ClientPtr client)
static int
ProcShmCreatePixmap(ClientPtr client)
{
REQUEST(xShmCreatePixmapReq);
REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
REQUEST_HEAD_STRUCT(xShmCreatePixmapReq);
REQUEST_FIELD_CARD32(pid);
REQUEST_FIELD_CARD32(drawable);
REQUEST_FIELD_CARD16(width);
REQUEST_FIELD_CARD16(height);
REQUEST_FIELD_CARD32(shmseg);
REQUEST_FIELD_CARD32(offset);
if (!client->local)
return BadRequest;
@@ -1171,8 +1196,8 @@ ShmBusfaultNotify(void *context)
static int
ProcShmAttachFd(ClientPtr client)
{
REQUEST(xShmAttachFdReq);
REQUEST_SIZE_MATCH(xShmAttachFdReq);
REQUEST_HEAD_STRUCT(xShmAttachFdReq);
REQUEST_FIELD_CARD32(shmseg);
if (!client->local)
return BadRequest;
@@ -1291,8 +1316,9 @@ shm_tmpfile(void)
static int
ProcShmCreateSegment(ClientPtr client)
{
REQUEST(xShmCreateSegmentReq);
REQUEST_SIZE_MATCH(xShmCreateSegmentReq);
REQUEST_HEAD_STRUCT(xShmCreateSegmentReq);
REQUEST_FIELD_CARD32(shmseg);
REQUEST_FIELD_CARD32(size);
if (!client->local)
return BadRequest;
@@ -1406,141 +1432,6 @@ SShmCompletionEvent(xShmCompletionEvent * from, xShmCompletionEvent * to)
cpswapl(from->offset, to->offset);
}
static int _X_COLD
SProcShmQueryVersion(ClientPtr client)
{
REQUEST(xShmQueryVersionReq);
swaps(&stuff->length);
return ProcShmQueryVersion(client);
}
static int _X_COLD
SProcShmAttach(ClientPtr client)
{
REQUEST(xShmAttachReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmAttachReq);
swapl(&stuff->shmseg);
swapl(&stuff->shmid);
return ProcShmAttach(client);
}
static int _X_COLD
SProcShmDetach(ClientPtr client)
{
REQUEST(xShmDetachReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmDetachReq);
swapl(&stuff->shmseg);
return ProcShmDetach(client);
}
static int _X_COLD
SProcShmPutImage(ClientPtr client)
{
REQUEST(xShmPutImageReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmPutImageReq);
swapl(&stuff->drawable);
swapl(&stuff->gc);
swaps(&stuff->totalWidth);
swaps(&stuff->totalHeight);
swaps(&stuff->srcX);
swaps(&stuff->srcY);
swaps(&stuff->srcWidth);
swaps(&stuff->srcHeight);
swaps(&stuff->dstX);
swaps(&stuff->dstY);
swapl(&stuff->shmseg);
swapl(&stuff->offset);
return ProcShmPutImage(client);
}
static int _X_COLD
SProcShmGetImage(ClientPtr client)
{
REQUEST(xShmGetImageReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmGetImageReq);
swapl(&stuff->drawable);
swaps(&stuff->x);
swaps(&stuff->y);
swaps(&stuff->width);
swaps(&stuff->height);
swapl(&stuff->planeMask);
swapl(&stuff->shmseg);
swapl(&stuff->offset);
return ProcShmGetImage(client);
}
static int _X_COLD
SProcShmCreatePixmap(ClientPtr client)
{
REQUEST(xShmCreatePixmapReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmCreatePixmapReq);
swapl(&stuff->pid);
swapl(&stuff->drawable);
swaps(&stuff->width);
swaps(&stuff->height);
swapl(&stuff->shmseg);
swapl(&stuff->offset);
return ProcShmCreatePixmap(client);
}
#ifdef SHM_FD_PASSING
static int _X_COLD
SProcShmAttachFd(ClientPtr client)
{
REQUEST(xShmAttachFdReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmAttachFdReq);
swapl(&stuff->shmseg);
return ProcShmAttachFd(client);
}
static int _X_COLD
SProcShmCreateSegment(ClientPtr client)
{
REQUEST(xShmCreateSegmentReq);
swaps(&stuff->length);
REQUEST_SIZE_MATCH(xShmCreateSegmentReq);
swapl(&stuff->shmseg);
swapl(&stuff->size);
return ProcShmCreateSegment(client);
}
#endif /* SHM_FD_PASSING */
static int _X_COLD
SProcShmDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data) {
case X_ShmQueryVersion:
return SProcShmQueryVersion(client);
case X_ShmAttach:
return SProcShmAttach(client);
case X_ShmDetach:
return SProcShmDetach(client);
case X_ShmPutImage:
return SProcShmPutImage(client);
case X_ShmGetImage:
return SProcShmGetImage(client);
case X_ShmCreatePixmap:
return SProcShmCreatePixmap(client);
#ifdef SHM_FD_PASSING
case X_ShmAttachFd:
return SProcShmAttachFd(client);
case X_ShmCreateSegment:
return SProcShmCreateSegment(client);
#endif
default:
return BadRequest;
}
}
void
ShmExtensionInit(void)
{
@@ -1580,7 +1471,7 @@ ShmExtensionInit(void)
ShmSegType = CreateNewResourceType(ShmDetachSegment, "ShmSeg");
if (ShmSegType &&
(extEntry = AddExtension(SHMNAME, ShmNumberEvents, ShmNumberErrors,
ProcShmDispatch, SProcShmDispatch,
ProcShmDispatch, ProcShmDispatch,
ShmResetProc, StandardMinorOpcode))) {
ShmReqCode = (unsigned char) extEntry->base;
ShmCompletionCode = extEntry->eventBase;