Xext: vidmode: tidy up multi-version request control flow, part 2

Some requests using different structs dependending on which protocol version
(v1 vs. v2) had been selected. That's is handled by coverting v1 structs into v2,
before proceeding with the actual handling.

The code flow of this is very complex and hard to understand. Cleaning this up
in several smaller steps, that are easier to digest.

This part is splitting the huge request handlers into upper and lower half,
where the upper is doing the version check and converting v1 requests into v2,
while the lower one is doing the actual request processing, operating on the
struct pointer passed in from the upper one, instead of the client struct's
request buffer.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2024-07-04 19:56:06 +02:00
parent f7280e51db
commit ad26a0595e

View File

@ -433,6 +433,8 @@ ProcVidModeGetAllModeLines(ClientPtr client)
&& VidModeGetModeValue(mode, VIDMODE_V_TOTAL) == stuff->vtotal \ && VidModeGetModeValue(mode, VIDMODE_V_TOTAL) == stuff->vtotal \
&& VidModeGetModeValue(mode, VIDMODE_FLAGS) == stuff->flags ) && VidModeGetModeValue(mode, VIDMODE_FLAGS) == stuff->flags )
static int VidModeAddModeLine(ClientPtr client, xXF86VidModeAddModeLineReq* stuff);
static int static int
ProcVidModeAddModeLine(ClientPtr client) ProcVidModeAddModeLine(ClientPtr client)
{ {
@ -440,11 +442,7 @@ ProcVidModeAddModeLine(ClientPtr client)
xXF86OldVidModeAddModeLineReq *oldstuff = xXF86OldVidModeAddModeLineReq *oldstuff =
(xXF86OldVidModeAddModeLineReq *) client->requestBuffer; (xXF86OldVidModeAddModeLineReq *) client->requestBuffer;
xXF86VidModeAddModeLineReq newstuff; xXF86VidModeAddModeLineReq newstuff;
ScreenPtr pScreen;
VidModePtr pVidMode;
DisplayModePtr mode;
int len; int len;
int dotClock;
int ver; int ver;
/* limited to local-only connections */ /* limited to local-only connections */
@ -501,6 +499,16 @@ ProcVidModeAddModeLine(ClientPtr client)
stuff->after_vtotal = oldstuff->after_vtotal; stuff->after_vtotal = oldstuff->after_vtotal;
stuff->after_flags = oldstuff->after_flags; stuff->after_flags = oldstuff->after_flags;
} }
return VidModeAddModeLine(client, stuff);
}
static int VidModeAddModeLine(ClientPtr client, xXF86VidModeAddModeLineReq* stuff)
{
ScreenPtr pScreen;
DisplayModePtr mode;
VidModePtr pVidMode;
int dotClock;
DebugF("AddModeLine - scrn: %d clock: %ld\n", DebugF("AddModeLine - scrn: %d clock: %ld\n",
(int) stuff->screen, (unsigned long) stuff->dotclock); (int) stuff->screen, (unsigned long) stuff->dotclock);
DebugF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n", DebugF("AddModeLine - hdsp: %d hbeg: %d hend: %d httl: %d\n",
@ -609,6 +617,9 @@ ProcVidModeAddModeLine(ClientPtr client)
return Success; return Success;
} }
static int
VidModeDeleteModeLine(ClientPtr client, xXF86VidModeDeleteModeLineReq* stuff);
static int static int
ProcVidModeDeleteModeLine(ClientPtr client) ProcVidModeDeleteModeLine(ClientPtr client)
{ {
@ -616,10 +627,7 @@ ProcVidModeDeleteModeLine(ClientPtr client)
xXF86OldVidModeDeleteModeLineReq *oldstuff = xXF86OldVidModeDeleteModeLineReq *oldstuff =
(xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer; (xXF86OldVidModeDeleteModeLineReq *) client->requestBuffer;
xXF86VidModeDeleteModeLineReq newstuff; xXF86VidModeDeleteModeLineReq newstuff;
ScreenPtr pScreen; int len;
VidModePtr pVidMode;
DisplayModePtr mode;
int len, dotClock;
int ver; int ver;
/* limited to local-only connections */ /* limited to local-only connections */
@ -677,6 +685,17 @@ ProcVidModeDeleteModeLine(ClientPtr client)
stuff->flags = oldstuff->flags; stuff->flags = oldstuff->flags;
stuff->privsize = oldstuff->privsize; stuff->privsize = oldstuff->privsize;
} }
return VidModeDeleteModeLine(client, stuff);
}
static int
VidModeDeleteModeLine(ClientPtr client, xXF86VidModeDeleteModeLineReq* stuff)
{
int dotClock;
DisplayModePtr mode;
VidModePtr pVidMode;
ScreenPtr pScreen;
DebugF("DeleteModeLine - scrn: %d clock: %ld\n", DebugF("DeleteModeLine - scrn: %d clock: %ld\n",
(int) stuff->screen, (unsigned long) stuff->dotclock); (int) stuff->screen, (unsigned long) stuff->dotclock);
DebugF(" hdsp: %d hbeg: %d hend: %d httl: %d\n", DebugF(" hdsp: %d hbeg: %d hend: %d httl: %d\n",
@ -744,6 +763,9 @@ ProcVidModeDeleteModeLine(ClientPtr client)
return BadValue; return BadValue;
} }
static int
VidModeModModeLine(ClientPtr client, xXF86VidModeModModeLineReq *stuff);
static int static int
ProcVidModeModModeLine(ClientPtr client) ProcVidModeModModeLine(ClientPtr client)
{ {
@ -751,10 +773,7 @@ ProcVidModeModModeLine(ClientPtr client)
xXF86OldVidModeModModeLineReq *oldstuff = xXF86OldVidModeModModeLineReq *oldstuff =
(xXF86OldVidModeModModeLineReq *) client->requestBuffer; (xXF86OldVidModeModModeLineReq *) client->requestBuffer;
xXF86VidModeModModeLineReq newstuff; xXF86VidModeModModeLineReq newstuff;
ScreenPtr pScreen; int len;
VidModePtr pVidMode;
DisplayModePtr mode;
int len, dotClock;
int ver; int ver;
/* limited to local-only connections */ /* limited to local-only connections */
@ -799,6 +818,17 @@ ProcVidModeModModeLine(ClientPtr client)
stuff->flags = oldstuff->flags; stuff->flags = oldstuff->flags;
stuff->privsize = oldstuff->privsize; stuff->privsize = oldstuff->privsize;
} }
return VidModeModModeLine(client, stuff);
}
static int
VidModeModModeLine(ClientPtr client, xXF86VidModeModModeLineReq *stuff)
{
ScreenPtr pScreen;
VidModePtr pVidMode;
DisplayModePtr mode;
int dotClock;
DebugF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n", DebugF("ModModeLine - scrn: %d hdsp: %d hbeg: %d hend: %d httl: %d\n",
(int) stuff->screen, stuff->hdisplay, stuff->hsyncstart, (int) stuff->screen, stuff->hdisplay, stuff->hsyncstart,
stuff->hsyncend, stuff->htotal); stuff->hsyncend, stuff->htotal);
@ -886,6 +916,9 @@ ProcVidModeModModeLine(ClientPtr client)
return Success; return Success;
} }
static int
VidModeValidateModeLine(ClientPtr client, xXF86VidModeValidateModeLineReq *stuff);
static int static int
ProcVidModeValidateModeLine(ClientPtr client) ProcVidModeValidateModeLine(ClientPtr client)
{ {
@ -893,11 +926,7 @@ ProcVidModeValidateModeLine(ClientPtr client)
xXF86OldVidModeValidateModeLineReq *oldstuff = xXF86OldVidModeValidateModeLineReq *oldstuff =
(xXF86OldVidModeValidateModeLineReq *) client->requestBuffer; (xXF86OldVidModeValidateModeLineReq *) client->requestBuffer;
xXF86VidModeValidateModeLineReq newstuff; xXF86VidModeValidateModeLineReq newstuff;
xXF86VidModeValidateModeLineReply rep; int len;
ScreenPtr pScreen;
VidModePtr pVidMode;
DisplayModePtr mode, modetmp = NULL;
int len, status, dotClock;
int ver; int ver;
DEBUG_P("XF86VidModeValidateModeline"); DEBUG_P("XF86VidModeValidateModeline");
@ -938,6 +967,17 @@ ProcVidModeValidateModeLine(ClientPtr client)
stuff->flags = oldstuff->flags; stuff->flags = oldstuff->flags;
stuff->privsize = oldstuff->privsize; stuff->privsize = oldstuff->privsize;
} }
return VidModeValidateModeLine(client, stuff);
}
static int
VidModeValidateModeLine(ClientPtr client, xXF86VidModeValidateModeLineReq *stuff)
{
ScreenPtr pScreen;
VidModePtr pVidMode;
DisplayModePtr mode, modetmp = NULL;
int status, dotClock;
xXF86VidModeValidateModeLineReply rep = { 0 };
DebugF("ValidateModeLine - scrn: %d clock: %ld\n", DebugF("ValidateModeLine - scrn: %d clock: %ld\n",
(int) stuff->screen, (unsigned long) stuff->dotclock); (int) stuff->screen, (unsigned long) stuff->dotclock);
@ -948,9 +988,6 @@ ProcVidModeValidateModeLine(ClientPtr client)
stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal, stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
(unsigned long) stuff->flags); (unsigned long) stuff->flags);
if (len != stuff->privsize)
return BadLength;
if (stuff->screen >= screenInfo.numScreens) if (stuff->screen >= screenInfo.numScreens)
return BadValue; return BadValue;
pScreen = screenInfo.screens[stuff->screen]; pScreen = screenInfo.screens[stuff->screen];
@ -1050,6 +1087,9 @@ ProcVidModeSwitchMode(ClientPtr client)
return Success; return Success;
} }
static int
VidModeSwitchToMode(ClientPtr client, xXF86VidModeSwitchToModeReq *stuff);
static int static int
ProcVidModeSwitchToMode(ClientPtr client) ProcVidModeSwitchToMode(ClientPtr client)
{ {
@ -1057,10 +1097,7 @@ ProcVidModeSwitchToMode(ClientPtr client)
xXF86OldVidModeSwitchToModeReq *oldstuff = xXF86OldVidModeSwitchToModeReq *oldstuff =
(xXF86OldVidModeSwitchToModeReq *) client->requestBuffer; (xXF86OldVidModeSwitchToModeReq *) client->requestBuffer;
xXF86VidModeSwitchToModeReq newstuff; xXF86VidModeSwitchToModeReq newstuff;
ScreenPtr pScreen; int len;
VidModePtr pVidMode;
DisplayModePtr mode;
int len, dotClock;
int ver; int ver;
DEBUG_P("XF86VidModeSwitchToMode"); DEBUG_P("XF86VidModeSwitchToMode");
@ -1106,6 +1143,16 @@ ProcVidModeSwitchToMode(ClientPtr client)
stuff->flags = oldstuff->flags; stuff->flags = oldstuff->flags;
stuff->privsize = oldstuff->privsize; stuff->privsize = oldstuff->privsize;
} }
return VidModeSwitchToMode(client, stuff);
}
static int
VidModeSwitchToMode(ClientPtr client, xXF86VidModeSwitchToModeReq *stuff)
{
ScreenPtr pScreen;
VidModePtr pVidMode;
DisplayModePtr mode;
int dotClock;
DebugF("SwitchToMode - scrn: %d clock: %ld\n", DebugF("SwitchToMode - scrn: %d clock: %ld\n",
(int) stuff->screen, (unsigned long) stuff->dotclock); (int) stuff->screen, (unsigned long) stuff->dotclock);