Bug Summary

File:dix/dispatch.c
Location:line 3579, column 5
Description:Value stored to 'numScreens' is never read

Annotated Source Code

1/************************************************************
2
3Copyright 1987, 1989, 1998 The Open Group
4
5Permission to use, copy, modify, distribute, and sell this software and its
6documentation for any purpose is hereby granted without fee, provided that
7the above copyright notice appear in all copies and that both that
8copyright notice and this permission notice appear in supporting
9documentation.
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21Except as contained in this notice, the name of The Open Group shall not be
22used in advertising or otherwise to promote the sale, use or other dealings
23in this Software without prior written authorization from The Open Group.
24
25Copyright 1987, 1989 by Digital Equipment Corporation, Maynard, Massachusetts.
26
27 All Rights Reserved
28
29Permission to use, copy, modify, and distribute this software and its
30documentation for any purpose and without fee is hereby granted,
31provided that the above copyright notice appear in all copies and that
32both that copyright notice and this permission notice appear in
33supporting documentation, and that the name of Digital not be
34used in advertising or publicity pertaining to distribution of the
35software without specific, written prior permission.
36
37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43SOFTWARE.
44
45********************************************************/
46
47/* The panoramix components contained the following notice */
48/*****************************************************************
49
50Copyright (c) 1991, 1997 Digital Equipment Corporation, Maynard, Massachusetts.
51
52Permission is hereby granted, free of charge, to any person obtaining a copy
53of this software and associated documentation files (the "Software"), to deal
54in the Software without restriction, including without limitation the rights
55to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
56copies of the Software.
57
58The above copyright notice and this permission notice shall be included in
59all copies or substantial portions of the Software.
60
61THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
64DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
65BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
66WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
67IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
68
69Except as contained in this notice, the name of Digital Equipment Corporation
70shall not be used in advertising or otherwise to promote the sale, use or other
71dealings in this Software without prior written authorization from Digital
72Equipment Corporation.
73
74******************************************************************/
75
76/* XSERVER_DTRACE additions:
77 * Copyright (c) 2005-2006, Oracle and/or its affiliates. All rights reserved.
78 *
79 * Permission is hereby granted, free of charge, to any person obtaining a
80 * copy of this software and associated documentation files (the "Software"),
81 * to deal in the Software without restriction, including without limitation
82 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
83 * and/or sell copies of the Software, and to permit persons to whom the
84 * Software is furnished to do so, subject to the following conditions:
85 *
86 * The above copyright notice and this permission notice (including the next
87 * paragraph) shall be included in all copies or substantial portions of the
88 * Software.
89 *
90 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
93 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
95 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
96 * DEALINGS IN THE SOFTWARE.
97 */
98
99#ifdef HAVE_DIX_CONFIG_H1
100#include <dix-config.h>
101#include <version-config.h>
102#endif
103
104#ifdef PANORAMIX_DEBUG
105#include <stdio.h>
106int ProcInitialConnection();
107#endif
108
109#include "windowstr.h"
110#include <X11/fonts/fontstruct.h>
111#include "dixfontstr.h"
112#include "gcstruct.h"
113#include "selection.h"
114#include "colormapst.h"
115#include "cursorstr.h"
116#include "scrnintstr.h"
117#include "opaque.h"
118#include "input.h"
119#include "servermd.h"
120#include "extnsionst.h"
121#include "dixfont.h"
122#include "dispatch.h"
123#include "swaprep.h"
124#include "swapreq.h"
125#include "privates.h"
126#include "xace.h"
127#include "inputstr.h"
128#include "xkbsrv.h"
129#include "site.h"
130#include "client.h"
131
132#ifdef XSERVER_DTRACE1
133#include "registry.h"
134#include "probes.h"
135#endif
136
137#define mskcnt((256 + 31) / 32) ((MAXCLIENTS256 + 31) / 32)
138#define BITMASK(i)(1U << ((i) & 31)) (1U << ((i) & 31))
139#define MASKIDX(i)((i) >> 5) ((i) >> 5)
140#define MASKWORD(buf, i)buf[((i) >> 5)] buf[MASKIDX(i)((i) >> 5)]
141#define BITSET(buf, i)buf[((i) >> 5)] |= (1U << ((i) & 31)) MASKWORD(buf, i)buf[((i) >> 5)] |= BITMASK(i)(1U << ((i) & 31))
142#define BITCLEAR(buf, i)buf[((i) >> 5)] &= ~(1U << ((i) & 31)) MASKWORD(buf, i)buf[((i) >> 5)] &= ~BITMASK(i)(1U << ((i) & 31))
143#define GETBIT(buf, i)(buf[((i) >> 5)] & (1U << ((i) & 31))) (MASKWORD(buf, i)buf[((i) >> 5)] & BITMASK(i)(1U << ((i) & 31)))
144
145xConnSetupPrefix connSetupPrefix;
146
147PaddingInfo PixmapWidthPaddingInfo[33];
148
149static ClientPtr grabClient;
150
151#define GrabNone0 0
152#define GrabActive1 1
153#define GrabKickout2 2
154static int grabState = GrabNone0;
155static long grabWaiters[mskcnt((256 + 31) / 32)];
156CallbackListPtr ServerGrabCallback = NULL((void*)0);
157HWEventQueuePtr checkForInput[2];
158int connBlockScreenStart;
159
160static void KillAllClients(void);
161
162static int nextFreeClientID; /* always MIN free client ID */
163
164static int nClients; /* number of authorized clients */
165
166CallbackListPtr ClientStateCallback;
167
168/* dispatchException & isItTimeToYield must be declared volatile since they
169 * are modified by signal handlers - otherwise optimizer may assume it doesn't
170 * need to actually check value in memory when used and may miss changes from
171 * signal handlers.
172 */
173volatile char dispatchException = 0;
174volatile char isItTimeToYield;
175
176#define SAME_SCREENS(a, b)( (a.pScreen == b.pScreen)) (\
177 (a.pScreen == b.pScreen))
178
179void
180SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1)
181{
182 checkForInput[0] = c0;
183 checkForInput[1] = c1;
184}
185
186void
187UpdateCurrentTime(void)
188{
189 TimeStamp systime;
190
191 /* To avoid time running backwards, we must call GetTimeInMillis before
192 * calling ProcessInputEvents.
193 */
194 systime.months = currentTime.months;
195 systime.milliseconds = GetTimeInMillis();
196 if (systime.milliseconds < currentTime.milliseconds)
197 systime.months++;
198 if (*checkForInput[0] != *checkForInput[1])
199 ProcessInputEvents();
200 if (CompareTimeStamps(systime, currentTime) == LATER1)
201 currentTime = systime;
202}
203
204/* Like UpdateCurrentTime, but can't call ProcessInputEvents */
205void
206UpdateCurrentTimeIf(void)
207{
208 TimeStamp systime;
209
210 systime.months = currentTime.months;
211 systime.milliseconds = GetTimeInMillis();
212 if (systime.milliseconds < currentTime.milliseconds)
213 systime.months++;
214 if (CompareTimeStamps(systime, currentTime) == LATER1)
215 currentTime = systime;
216}
217
218#undef SMART_DEBUG
219
220/* in milliseconds */
221#define SMART_SCHEDULE_DEFAULT_INTERVAL5 5
222#define SMART_SCHEDULE_MAX_SLICE15 15
223
224#if defined(WIN32) && !defined(__CYGWIN__)
225Bool SmartScheduleDisable = TRUE1;
226#else
227Bool SmartScheduleDisable = FALSE0;
228#endif
229long SmartScheduleSlice = SMART_SCHEDULE_DEFAULT_INTERVAL5;
230long SmartScheduleInterval = SMART_SCHEDULE_DEFAULT_INTERVAL5;
231long SmartScheduleMaxSlice = SMART_SCHEDULE_MAX_SLICE15;
232long SmartScheduleTime;
233int SmartScheduleLatencyLimited = 0;
234static ClientPtr SmartLastClient;
235static int SmartLastIndex[SMART_MAX_PRIORITY(20) - SMART_MIN_PRIORITY(-20) + 1];
236
237#ifdef SMART_DEBUG
238long SmartLastPrint;
239#endif
240
241void Dispatch(void);
242
243static int
244SmartScheduleClient(int *clientReady, int nready)
245{
246 ClientPtr pClient;
247 int i;
248 int client;
249 int bestPrio, best = 0;
250 int bestRobin, robin;
251 long now = SmartScheduleTime;
252 long idle;
253
254 bestPrio = -0x7fffffff;
255 bestRobin = 0;
256 idle = 2 * SmartScheduleSlice;
257 for (i = 0; i < nready; i++) {
258 client = clientReady[i];
259 pClient = clients[client];
260 /* Praise clients which haven't run in a while */
261 if ((now - pClient->smart_stop_tick) >= idle) {
262 if (pClient->smart_priority < 0)
263 pClient->smart_priority++;
264 }
265
266 /* check priority to select best client */
267 robin =
268 (pClient->index -
269 SmartLastIndex[pClient->smart_priority -
270 SMART_MIN_PRIORITY(-20)]) & 0xff;
271 if (pClient->smart_priority > bestPrio ||
272 (pClient->smart_priority == bestPrio && robin > bestRobin)) {
273 bestPrio = pClient->smart_priority;
274 bestRobin = robin;
275 best = client;
276 }
277#ifdef SMART_DEBUG
278 if ((now - SmartLastPrint) >= 5000)
279 fprintf(stderr__stderrp, " %2d: %3d", client, pClient->smart_priority);
280#endif
281 }
282#ifdef SMART_DEBUG
283 if ((now - SmartLastPrint) >= 5000) {
284 fprintf(stderr__stderrp, " use %2d\n", best);
285 SmartLastPrint = now;
286 }
287#endif
288 pClient = clients[best];
289 SmartLastIndex[bestPrio - SMART_MIN_PRIORITY(-20)] = pClient->index;
290 /*
291 * Set current client pointer
292 */
293 if (SmartLastClient != pClient) {
294 pClient->smart_start_tick = now;
295 SmartLastClient = pClient;
296 }
297 /*
298 * Adjust slice
299 */
300 if (nready == 1 && SmartScheduleLatencyLimited == 0) {
301 /*
302 * If it's been a long time since another client
303 * has run, bump the slice up to get maximal
304 * performance from a single client
305 */
306 if ((now - pClient->smart_start_tick) > 1000 &&
307 SmartScheduleSlice < SmartScheduleMaxSlice) {
308 SmartScheduleSlice += SmartScheduleInterval;
309 }
310 }
311 else {
312 SmartScheduleSlice = SmartScheduleInterval;
313 }
314 return best;
315}
316
317void
318EnableLimitedSchedulingLatency(void)
319{
320 ++SmartScheduleLatencyLimited;
321 SmartScheduleSlice = SmartScheduleInterval;
322}
323
324void
325DisableLimitedSchedulingLatency(void)
326{
327 --SmartScheduleLatencyLimited;
328
329 /* protect against bugs */
330 if (SmartScheduleLatencyLimited < 0)
331 SmartScheduleLatencyLimited = 0;
332}
333
334void
335Dispatch(void)
336{
337 int *clientReady; /* array of request ready clients */
338 int result;
339 ClientPtr client;
340 int nready;
341 HWEventQueuePtr *icheck = checkForInput;
342 long start_tick;
343
344 nextFreeClientID = 1;
345 nClients = 0;
346
347 clientReady = malloc(sizeof(int) * MaxClients);
348 if (!clientReady)
349 return;
350
351 SmartScheduleSlice = SmartScheduleInterval;
352 while (!dispatchException) {
353 if (*icheck[0] != *icheck[1]) {
354 ProcessInputEvents();
355 FlushIfCriticalOutputPending();
356 }
357
358 nready = WaitForSomething(clientReady);
359
360 if (nready && !SmartScheduleDisable) {
361 clientReady[0] = SmartScheduleClient(clientReady, nready);
362 nready = 1;
363 }
364 /*****************
365 * Handle events in round robin fashion, doing input between
366 * each round
367 *****************/
368
369 while (!dispatchException && (--nready >= 0)) {
370 client = clients[clientReady[nready]];
371 if (!client) {
372 /* KillClient can cause this to happen */
373 continue;
374 }
375 /* GrabServer activation can cause this to be true */
376 if (grabState == GrabKickout2) {
377 grabState = GrabActive1;
378 break;
379 }
380 isItTimeToYield = FALSE0;
381
382 start_tick = SmartScheduleTime;
383 while (!isItTimeToYield) {
384 if (*icheck[0] != *icheck[1])
385 ProcessInputEvents();
386
387 FlushIfCriticalOutputPending();
388 if (!SmartScheduleDisable &&
389 (SmartScheduleTime - start_tick) >= SmartScheduleSlice) {
390 /* Penalize clients which consume ticks */
391 if (client->smart_priority > SMART_MIN_PRIORITY(-20))
392 client->smart_priority--;
393 break;
394 }
395 /* now, finally, deal with client requests */
396
397 /* Update currentTime so request time checks, such as for input
398 * device grabs, are calculated correctly */
399 UpdateCurrentTimeIf();
400 result = ReadRequestFromClient(client);
401 if (result <= 0) {
402 if (result < 0)
403 CloseDownClient(client);
404 break;
405 }
406
407 client->sequence++;
408 client->majorOp = ((xReq *) client->requestBuffer)->reqType;
409 client->minorOp = 0;
410 if (client->majorOp >= EXTENSION_BASE128) {
411 ExtensionEntry *ext = GetExtensionEntry(client->majorOp);
412
413 if (ext)
414 client->minorOp = ext->MinorOpcode(client);
415 }
416#ifdef XSERVER_DTRACE1
417 if (XSERVER_REQUEST_START_ENABLED()({ int _r = __dtrace_isenabled$Xserver$request__start$v1(); __asm__
volatile(""); _r; })
)
418 XSERVER_REQUEST_START(LookupMajorName(client->majorOp),do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__start$v1$63686172202a$75696e74385f74$75696e7431365f74$696e74$766f6964202a
(LookupMajorName(client->majorOp), client->majorOp, ((xReq
*) client->requestBuffer)->length, client->index, client
->requestBuffer); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
419 client->majorOp,do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__start$v1$63686172202a$75696e74385f74$75696e7431365f74$696e74$766f6964202a
(LookupMajorName(client->majorOp), client->majorOp, ((xReq
*) client->requestBuffer)->length, client->index, client
->requestBuffer); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
420 ((xReq *) client->requestBuffer)->length,do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__start$v1$63686172202a$75696e74385f74$75696e7431365f74$696e74$766f6964202a
(LookupMajorName(client->majorOp), client->majorOp, ((xReq
*) client->requestBuffer)->length, client->index, client
->requestBuffer); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
421 client->index,do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__start$v1$63686172202a$75696e74385f74$75696e7431365f74$696e74$766f6964202a
(LookupMajorName(client->majorOp), client->majorOp, ((xReq
*) client->requestBuffer)->length, client->index, client
->requestBuffer); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
422 client->requestBuffer)do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__start$v1$63686172202a$75696e74385f74$75696e7431365f74$696e74$766f6964202a
(LookupMajorName(client->majorOp), client->majorOp, ((xReq
*) client->requestBuffer)->length, client->index, client
->requestBuffer); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
;
423#endif
424 if (result > (maxBigRequestSize << 2))
425 result = BadLength16;
426 else {
427 result = XaceHookDispatch(client, client->majorOp);
428 if (result == Success0)
429 result =
430 (*client->requestVector[client->majorOp]) (client);
431 XaceHookAuditEnd(client, result);
432 }
433#ifdef XSERVER_DTRACE1
434 if (XSERVER_REQUEST_DONE_ENABLED()({ int _r = __dtrace_isenabled$Xserver$request__done$v1(); __asm__
volatile(""); _r; })
)
435 XSERVER_REQUEST_DONE(LookupMajorName(client->majorOp),do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__done$v1$63686172202a$75696e74385f74$75696e7433325f74$696e74$696e74
(LookupMajorName(client->majorOp), client->majorOp, client
->sequence, client->index, result); __asm__ volatile(".reference "
"___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
436 client->majorOp, client->sequence,do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__done$v1$63686172202a$75696e74385f74$75696e7433325f74$696e74$696e74
(LookupMajorName(client->majorOp), client->majorOp, client
->sequence, client->index, result); __asm__ volatile(".reference "
"___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
437 client->index, result)do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$request__done$v1$63686172202a$75696e74385f74$75696e7433325f74$696e74$696e74
(LookupMajorName(client->majorOp), client->majorOp, client
->sequence, client->index, result); __asm__ volatile(".reference "
"___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
;
438#endif
439
440 if (client->noClientException != Success0) {
441 CloseDownClient(client);
442 break;
443 }
444 else if (result != Success0) {
445 SendErrorToClient(client, client->majorOp,
446 client->minorOp,
447 client->errorValue, result);
448 break;
449 }
450 }
451 FlushAllOutput();
452 client = clients[clientReady[nready]];
453 if (client)
454 client->smart_stop_tick = SmartScheduleTime;
455 }
456 dispatchException &= ~DE_PRIORITYCHANGE4;
457 }
458#if defined(DDXBEFORERESET)
459 ddxBeforeReset();
460#endif
461 KillAllClients();
462 free(clientReady);
463 dispatchException &= ~DE_RESET1;
464 SmartScheduleLatencyLimited = 0;
465 ResetOsBuffers();
466}
467
468static int VendorRelease = VENDOR_RELEASE(((1) * 10000000) + ((17) * 100000) + ((4) * 1000) + 0);
469static const char *VendorString = VENDOR_NAME"The X.Org Foundation";
470
471void
472SetVendorRelease(int release)
473{
474 VendorRelease = release;
475}
476
477void
478SetVendorString(const char *vendor)
479{
480 VendorString = vendor;
481}
482
483Bool
484CreateConnectionBlock(void)
485{
486 xConnSetup setup;
487 xWindowRoot root;
488 xDepth depth;
489 xVisualType visual;
490 xPixmapFormat format;
491 unsigned long vid;
492 int i, j, k, lenofblock, sizesofar = 0;
493 char *pBuf;
494
495 memset(&setup, 0, sizeof(xConnSetup))__builtin___memset_chk (&setup, 0, sizeof(xConnSetup), __builtin_object_size
(&setup, 0))
;
496 /* Leave off the ridBase and ridMask, these must be sent with
497 connection */
498
499 setup.release = VendorRelease;
500 /*
501 * per-server image and bitmap parameters are defined in Xmd.h
502 */
503 setup.imageByteOrder = screenInfo.imageByteOrder;
504
505 setup.bitmapScanlineUnit = screenInfo.bitmapScanlineUnit;
506 setup.bitmapScanlinePad = screenInfo.bitmapScanlinePad;
507
508 setup.bitmapBitOrder = screenInfo.bitmapBitOrder;
509 setup.motionBufferSize = NumMotionEvents();
510 setup.numRoots = screenInfo.numScreens;
511 setup.nbytesVendor = strlen(VendorString);
512 setup.numFormats = screenInfo.numPixmapFormats;
513 setup.maxRequestSize = MAX_REQUEST_SIZE65535;
514 QueryMinMaxKeyCodes(&setup.minKeyCode, &setup.maxKeyCode);
515
516 lenofblock = sizeof(xConnSetup) +
517 pad_to_int32(setup.nbytesVendor) +
518 (setup.numFormats * sizeof(xPixmapFormat)) +
519 (setup.numRoots * sizeof(xWindowRoot));
520 ConnectionInfo = malloc(lenofblock);
521 if (!ConnectionInfo)
522 return FALSE0;
523
524 memmove(ConnectionInfo, (char *) &setup, sizeof(xConnSetup))__builtin___memmove_chk (ConnectionInfo, (char *) &setup,
sizeof(xConnSetup), __builtin_object_size (ConnectionInfo, 0
))
;
525 sizesofar = sizeof(xConnSetup);
526 pBuf = ConnectionInfo + sizeof(xConnSetup);
527
528 memmove(pBuf, VendorString, (int) setup.nbytesVendor)__builtin___memmove_chk (pBuf, VendorString, (int) setup.nbytesVendor
, __builtin_object_size (pBuf, 0))
;
529 sizesofar += setup.nbytesVendor;
530 pBuf += setup.nbytesVendor;
531 i = padding_for_int32(setup.nbytesVendor);
532 sizesofar += i;
533 while (--i >= 0)
534 *pBuf++ = 0;
535
536 memset(&format, 0, sizeof(xPixmapFormat))__builtin___memset_chk (&format, 0, sizeof(xPixmapFormat)
, __builtin_object_size (&format, 0))
;
537 for (i = 0; i < screenInfo.numPixmapFormats; i++) {
538 format.depth = screenInfo.formats[i].depth;
539 format.bitsPerPixel = screenInfo.formats[i].bitsPerPixel;
540 format.scanLinePad = screenInfo.formats[i].scanlinePad;
541 memmove(pBuf, (char *) &format, sizeof(xPixmapFormat))__builtin___memmove_chk (pBuf, (char *) &format, sizeof(xPixmapFormat
), __builtin_object_size (pBuf, 0))
;
542 pBuf += sizeof(xPixmapFormat);
543 sizesofar += sizeof(xPixmapFormat);
544 }
545
546 connBlockScreenStart = sizesofar;
547 memset(&depth, 0, sizeof(xDepth))__builtin___memset_chk (&depth, 0, sizeof(xDepth), __builtin_object_size
(&depth, 0))
;
548 memset(&visual, 0, sizeof(xVisualType))__builtin___memset_chk (&visual, 0, sizeof(xVisualType), __builtin_object_size
(&visual, 0))
;
549 for (i = 0; i < screenInfo.numScreens; i++) {
550 ScreenPtr pScreen;
551 DepthPtr pDepth;
552 VisualPtr pVisual;
553
554 pScreen = screenInfo.screens[i];
555 root.windowId = pScreen->root->drawable.id;
556 root.defaultColormap = pScreen->defColormap;
557 root.whitePixel = pScreen->whitePixel;
558 root.blackPixel = pScreen->blackPixel;
559 root.currentInputMask = 0; /* filled in when sent */
560 root.pixWidth = pScreen->width;
561 root.pixHeight = pScreen->height;
562 root.mmWidth = pScreen->mmWidth;
563 root.mmHeight = pScreen->mmHeight;
564 root.minInstalledMaps = pScreen->minInstalledCmaps;
565 root.maxInstalledMaps = pScreen->maxInstalledCmaps;
566 root.rootVisualID = pScreen->rootVisual;
567 root.backingStore = pScreen->backingStoreSupport;
568 root.saveUnders = FALSE0;
569 root.rootDepth = pScreen->rootDepth;
570 root.nDepths = pScreen->numDepths;
571 memmove(pBuf, (char *) &root, sizeof(xWindowRoot))__builtin___memmove_chk (pBuf, (char *) &root, sizeof(xWindowRoot
), __builtin_object_size (pBuf, 0))
;
572 sizesofar += sizeof(xWindowRoot);
573 pBuf += sizeof(xWindowRoot);
574
575 pDepth = pScreen->allowedDepths;
576 for (j = 0; j < pScreen->numDepths; j++, pDepth++) {
577 lenofblock += sizeof(xDepth) +
578 (pDepth->numVids * sizeof(xVisualType));
579 pBuf = (char *) realloc(ConnectionInfo, lenofblock);
580 if (!pBuf) {
581 free(ConnectionInfo);
582 return FALSE0;
583 }
584 ConnectionInfo = pBuf;
585 pBuf += sizesofar;
586 depth.depth = pDepth->depth;
587 depth.nVisuals = pDepth->numVids;
588 memmove(pBuf, (char *) &depth, sizeof(xDepth))__builtin___memmove_chk (pBuf, (char *) &depth, sizeof(xDepth
), __builtin_object_size (pBuf, 0))
;
589 pBuf += sizeof(xDepth);
590 sizesofar += sizeof(xDepth);
591 for (k = 0; k < pDepth->numVids; k++) {
592 vid = pDepth->vids[k];
593 for (pVisual = pScreen->visuals;
594 pVisual->vid != vid; pVisual++);
595 visual.visualID = vid;
596 visual.class = pVisual->class;
597 visual.bitsPerRGB = pVisual->bitsPerRGBValue;
598 visual.colormapEntries = pVisual->ColormapEntries;
599 visual.redMask = pVisual->redMask;
600 visual.greenMask = pVisual->greenMask;
601 visual.blueMask = pVisual->blueMask;
602 memmove(pBuf, (char *) &visual, sizeof(xVisualType))__builtin___memmove_chk (pBuf, (char *) &visual, sizeof(xVisualType
), __builtin_object_size (pBuf, 0))
;
603 pBuf += sizeof(xVisualType);
604 sizesofar += sizeof(xVisualType);
605 }
606 }
607 }
608 connSetupPrefix.success = xTrue1;
609 connSetupPrefix.length = lenofblock / 4;
610 connSetupPrefix.majorVersion = X_PROTOCOL11;
611 connSetupPrefix.minorVersion = X_PROTOCOL_REVISION0;
612 return TRUE1;
613}
614
615int
616ProcBadRequest(ClientPtr client)
617{
618 return BadRequest1;
619}
620
621int
622ProcCreateWindow(ClientPtr client)
623{
624 WindowPtr pParent, pWin;
625
626 REQUEST(xCreateWindowReq)xCreateWindowReq *stuff = (xCreateWindowReq *)client->requestBuffer;
627 int len, rc;
628
629 REQUEST_AT_LEAST_SIZE(xCreateWindowReq)if ((sizeof(xCreateWindowReq) >> 2) > client->req_len
) return(16)
;
630
631 LEGAL_NEW_RESOURCE(stuff->wid, client)if (!LegalNewID(stuff->wid,client)) { client->errorValue
= stuff->wid; return 14; }
;
632 rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess(1<<12));
633 if (rc != Success0)
634 return rc;
635 len = client->req_len - bytes_to_int32(sizeof(xCreateWindowReq));
636 if (Ones(stuff->mask) != len)
637 return BadLength16;
638 if (!stuff->width || !stuff->height) {
639 client->errorValue = 0;
640 return BadValue2;
641 }
642 pWin = CreateWindow(stuff->wid, pParent, stuff->x,
643 stuff->y, stuff->width, stuff->height,
644 stuff->borderWidth, stuff->class,
645 stuff->mask, (XID *) &stuff[1],
646 (int) stuff->depth, client, stuff->visual, &rc);
647 if (pWin) {
648 Mask mask = pWin->eventMask;
649
650 pWin->eventMask = 0; /* subterfuge in case AddResource fails */
651 if (!AddResourceDarwin_X_AddResource(stuff->wid, RT_WINDOW((RESTYPE)1|((RESTYPE)1<<30)), (void *) pWin))
652 return BadAlloc11;
653 pWin->eventMask = mask;
654 }
655 return rc;
656}
657
658int
659ProcChangeWindowAttributes(ClientPtr client)
660{
661 WindowPtr pWin;
662
663 REQUEST(xChangeWindowAttributesReq)xChangeWindowAttributesReq *stuff = (xChangeWindowAttributesReq
*)client->requestBuffer
;
664 int len, rc;
665 Mask access_mode = 0;
666
667 REQUEST_AT_LEAST_SIZE(xChangeWindowAttributesReq)if ((sizeof(xChangeWindowAttributesReq) >> 2) > client
->req_len ) return(16)
;
668 access_mode |= (stuff->valueMask & CWEventMask(1L<<11)) ? DixReceiveAccess(1<<23) : 0;
669 access_mode |= (stuff->valueMask & ~CWEventMask(1L<<11)) ? DixSetAttrAccess(1<<5) : 0;
670 rc = dixLookupWindow(&pWin, stuff->window, client, access_mode);
671 if (rc != Success0)
672 return rc;
673 len = client->req_len - bytes_to_int32(sizeof(xChangeWindowAttributesReq));
674 if (len != Ones(stuff->valueMask))
675 return BadLength16;
676 return ChangeWindowAttributesDarwin_X_ChangeWindowAttributes(pWin,
677 stuff->valueMask, (XID *) &stuff[1], client);
678}
679
680int
681ProcGetWindowAttributes(ClientPtr client)
682{
683 WindowPtr pWin;
684
685 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
686 xGetWindowAttributesReply wa;
687 int rc;
688
689 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
690 rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess(1<<4));
691 if (rc != Success0)
692 return rc;
693 memset(&wa, 0, sizeof(xGetWindowAttributesReply))__builtin___memset_chk (&wa, 0, sizeof(xGetWindowAttributesReply
), __builtin_object_size (&wa, 0))
;
694 GetWindowAttributes(pWin, client, &wa)Darwin_X_GetWindowAttributes(pWin,client,&wa);
695 WriteReplyToClient(client, sizeof(xGetWindowAttributesReply), &wa){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetWindowAttributesReply
)), &wa); else WriteToClient(client, (int)(sizeof(xGetWindowAttributesReply
)), (&wa)); }
;
696 return Success0;
697}
698
699int
700ProcDestroyWindow(ClientPtr client)
701{
702 WindowPtr pWin;
703
704 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
705 int rc;
706
707 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
708 rc = dixLookupWindow(&pWin, stuff->id, client, DixDestroyAccess(1<<2));
709 if (rc != Success0)
710 return rc;
711 if (pWin->parent) {
712 rc = dixLookupWindow(&pWin, pWin->parent->drawable.id, client,
713 DixRemoveAccess(1<<13));
714 if (rc != Success0)
715 return rc;
716 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
717 }
718 return Success0;
719}
720
721int
722ProcDestroySubwindows(ClientPtr client)
723{
724 WindowPtr pWin;
725
726 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
727 int rc;
728
729 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
730 rc = dixLookupWindow(&pWin, stuff->id, client, DixRemoveAccess(1<<13));
731 if (rc != Success0)
732 return rc;
733 DestroySubwindows(pWin, client);
734 return Success0;
735}
736
737int
738ProcChangeSaveSet(ClientPtr client)
739{
740 WindowPtr pWin;
741
742 REQUEST(xChangeSaveSetReq)xChangeSaveSetReq *stuff = (xChangeSaveSetReq *)client->requestBuffer;
743 int rc;
744
745 REQUEST_SIZE_MATCH(xChangeSaveSetReq)if ((sizeof(xChangeSaveSetReq) >> 2) != client->req_len
) return(16)
;
746 rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess(1<<25));
747 if (rc != Success0)
748 return rc;
749 if (client->clientAsMask == (CLIENT_BITS(pWin->drawable.id)((pWin->drawable.id) & (((1 << 8) - 1) << (
29 - 8)))
))
750 return BadMatch8;
751 if ((stuff->mode == SetModeInsert0) || (stuff->mode == SetModeDelete1))
752 return AlterSaveSetForClient(client, pWin, stuff->mode, FALSE0, TRUE1);
753 client->errorValue = stuff->mode;
754 return BadValue2;
755}
756
757int
758ProcReparentWindow(ClientPtr client)
759{
760 WindowPtr pWin, pParent;
761
762 REQUEST(xReparentWindowReq)xReparentWindowReq *stuff = (xReparentWindowReq *)client->
requestBuffer
;
763 int rc;
764
765 REQUEST_SIZE_MATCH(xReparentWindowReq)if ((sizeof(xReparentWindowReq) >> 2) != client->req_len
) return(16)
;
766 rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess(1<<25));
767 if (rc != Success0)
768 return rc;
769 rc = dixLookupWindow(&pParent, stuff->parent, client, DixAddAccess(1<<12));
770 if (rc != Success0)
771 return rc;
772 if (!SAME_SCREENS(pWin->drawable, pParent->drawable)( (pWin->drawable.pScreen == pParent->drawable.pScreen)
)
)
773 return BadMatch8;
774 if ((pWin->backgroundState == ParentRelative1L) &&
775 (pParent->drawable.depth != pWin->drawable.depth))
776 return BadMatch8;
777 if ((pWin->drawable.class != InputOnly2) &&
778 (pParent->drawable.class == InputOnly2))
779 return BadMatch8;
780 return ReparentWindow(pWin, pParent,
781 (short) stuff->x, (short) stuff->y, client);
782}
783
784int
785ProcMapWindow(ClientPtr client)
786{
787 WindowPtr pWin;
788
789 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
790 int rc;
791
792 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
793 rc = dixLookupWindow(&pWin, stuff->id, client, DixShowAccess(1<<15));
794 if (rc != Success0)
795 return rc;
796 MapWindow(pWin, client);
797 /* update cache to say it is mapped */
798 return Success0;
799}
800
801int
802ProcMapSubwindows(ClientPtr client)
803{
804 WindowPtr pWin;
805
806 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
807 int rc;
808
809 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
810 rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess(1<<11));
811 if (rc != Success0)
812 return rc;
813 MapSubwindows(pWin, client);
814 /* update cache to say it is mapped */
815 return Success0;
816}
817
818int
819ProcUnmapWindow(ClientPtr client)
820{
821 WindowPtr pWin;
822
823 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
824 int rc;
825
826 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
827 rc = dixLookupWindow(&pWin, stuff->id, client, DixHideAccess(1<<14));
828 if (rc != Success0)
829 return rc;
830 UnmapWindow(pWin, FALSE0);
831 /* update cache to say it is mapped */
832 return Success0;
833}
834
835int
836ProcUnmapSubwindows(ClientPtr client)
837{
838 WindowPtr pWin;
839
840 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
841 int rc;
842
843 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
844 rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess(1<<11));
845 if (rc != Success0)
846 return rc;
847 UnmapSubwindows(pWin);
848 return Success0;
849}
850
851int
852ProcConfigureWindow(ClientPtr client)
853{
854 WindowPtr pWin;
855
856 REQUEST(xConfigureWindowReq)xConfigureWindowReq *stuff = (xConfigureWindowReq *)client->
requestBuffer
;
857 int len, rc;
858
859 REQUEST_AT_LEAST_SIZE(xConfigureWindowReq)if ((sizeof(xConfigureWindowReq) >> 2) > client->
req_len ) return(16)
;
860 rc = dixLookupWindow(&pWin, stuff->window, client,
861 DixManageAccess(1<<25) | DixSetAttrAccess(1<<5));
862 if (rc != Success0)
863 return rc;
864 len = client->req_len - bytes_to_int32(sizeof(xConfigureWindowReq));
865 if (Ones((Mask) stuff->mask) != len)
866 return BadLength16;
867 return ConfigureWindow(pWin, (Mask) stuff->mask, (XID *) &stuff[1], client);
868}
869
870int
871ProcCirculateWindow(ClientPtr client)
872{
873 WindowPtr pWin;
874
875 REQUEST(xCirculateWindowReq)xCirculateWindowReq *stuff = (xCirculateWindowReq *)client->
requestBuffer
;
876 int rc;
877
878 REQUEST_SIZE_MATCH(xCirculateWindowReq)if ((sizeof(xCirculateWindowReq) >> 2) != client->req_len
) return(16)
;
879 if ((stuff->direction != RaiseLowest0) && (stuff->direction != LowerHighest1)) {
880 client->errorValue = stuff->direction;
881 return BadValue2;
882 }
883 rc = dixLookupWindow(&pWin, stuff->window, client, DixManageAccess(1<<25));
884 if (rc != Success0)
885 return rc;
886 CirculateWindow(pWin, (int) stuff->direction, client);
887 return Success0;
888}
889
890static int
891GetGeometry(ClientPtr client, xGetGeometryReply * rep)
892{
893 DrawablePtr pDraw;
894 int rc;
895
896 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
897 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
898
899 rc = dixLookupDrawable(&pDraw, stuff->id, client, M_ANY(-1), DixGetAttrAccess(1<<4));
900 if (rc != Success0)
901 return rc;
902
903 rep->type = X_Reply1;
904 rep->length = 0;
905 rep->sequenceNumber = client->sequence;
906 rep->root = pDraw->pScreen->root->drawable.id;
907 rep->depth = pDraw->depth;
908 rep->width = pDraw->width;
909 rep->height = pDraw->height;
910
911 if (WindowDrawable(pDraw->type)((pDraw->type == 0) || (pDraw->type == 2))) {
912 WindowPtr pWin = (WindowPtr) pDraw;
913
914 rep->x = pWin->origin.x - wBorderWidth(pWin)((int) (pWin)->borderWidth);
915 rep->y = pWin->origin.y - wBorderWidth(pWin)((int) (pWin)->borderWidth);
916 rep->borderWidth = pWin->borderWidth;
917 }
918 else { /* DRAWABLE_PIXMAP */
919
920 rep->x = rep->y = rep->borderWidth = 0;
921 }
922
923 return Success0;
924}
925
926int
927ProcGetGeometry(ClientPtr client)
928{
929 xGetGeometryReply rep = { .type = X_Reply1 };
930 int status;
931
932 if ((status = GetGeometry(client, &rep)) != Success0)
933 return status;
934
935 WriteReplyToClient(client, sizeof(xGetGeometryReply), &rep){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetGeometryReply
)), &rep); else WriteToClient(client, (int)(sizeof(xGetGeometryReply
)), (&rep)); }
;
936 return Success0;
937}
938
939int
940ProcQueryTree(ClientPtr client)
941{
942 xQueryTreeReply reply;
943 int rc, numChildren = 0;
944 WindowPtr pChild, pWin, pHead;
945 Window *childIDs = (Window *) NULL((void*)0);
946
947 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
948
949 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
950 rc = dixLookupWindow(&pWin, stuff->id, client, DixListAccess(1<<11));
951 if (rc != Success0)
952 return rc;
953
954 reply = (xQueryTreeReply) {
955 .type = X_Reply1,
956 .sequenceNumber = client->sequence,
957 .root = pWin->drawable.pScreen->root->drawable.id,
958 .parent = (pWin->parent) ? pWin->parent->drawable.id : (Window) None0L
959 };
960 pHead = RealChildHead(pWin);
961 for (pChild = pWin->lastChild; pChild != pHead; pChild = pChild->prevSib)
962 numChildren++;
963 if (numChildren) {
964 int curChild = 0;
965
966 childIDs = malloc(numChildren * sizeof(Window));
967 if (!childIDs)
968 return BadAlloc11;
969 for (pChild = pWin->lastChild; pChild != pHead;
970 pChild = pChild->prevSib)
971 childIDs[curChild++] = pChild->drawable.id;
972 }
973
974 reply.nChildren = numChildren;
975 reply.length = bytes_to_int32(numChildren * sizeof(Window));
976
977 WriteReplyToClient(client, sizeof(xQueryTreeReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xQueryTreeReply
)), &reply); else WriteToClient(client, (int)(sizeof(xQueryTreeReply
)), (&reply)); }
;
978 if (numChildren) {
979 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
980 WriteSwappedDataToClient(client, numChildren * sizeof(Window),if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(numChildren * sizeof(Window)), childIDs); else WriteToClient
(client, (int)(numChildren * sizeof(Window)), (childIDs));
981 childIDs)if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(numChildren * sizeof(Window)), childIDs); else WriteToClient
(client, (int)(numChildren * sizeof(Window)), (childIDs));
;
982 free(childIDs);
983 }
984
985 return Success0;
986}
987
988int
989ProcInternAtom(ClientPtr client)
990{
991 Atom atom;
992 char *tchar;
993
994 REQUEST(xInternAtomReq)xInternAtomReq *stuff = (xInternAtomReq *)client->requestBuffer;
995
996 REQUEST_FIXED_SIZE(xInternAtomReq, stuff->nbytes)if (((sizeof(xInternAtomReq) >> 2) > client->req_len
) || (((stuff->nbytes) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xInternAtomReq) + (stuff->nbytes
) + 3) >> 2) != (uint64_t) client->req_len)) return(
16)
;
997 if ((stuff->onlyIfExists != xTrue1) && (stuff->onlyIfExists != xFalse0)) {
998 client->errorValue = stuff->onlyIfExists;
999 return BadValue2;
1000 }
1001 tchar = (char *) &stuff[1];
1002 atom = MakeAtom(tchar, stuff->nbytes, !stuff->onlyIfExists);
1003 if (atom != BAD_RESOURCE0xe0000000) {
1004 xInternAtomReply reply = {
1005 .type = X_Reply1,
1006 .sequenceNumber = client->sequence,
1007 .length = 0,
1008 .atom = atom
1009 };
1010 WriteReplyToClient(client, sizeof(xInternAtomReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xInternAtomReply
)), &reply); else WriteToClient(client, (int)(sizeof(xInternAtomReply
)), (&reply)); }
;
1011 return Success0;
1012 }
1013 else
1014 return BadAlloc11;
1015}
1016
1017int
1018ProcGetAtomName(ClientPtr client)
1019{
1020 const char *str;
1021
1022 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
1023
1024 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
1025 if ((str = NameForAtom(stuff->id))) {
1026 int len = strlen(str);
1027 xGetAtomNameReply reply = {
1028 .type = X_Reply1,
1029 .sequenceNumber = client->sequence,
1030 .length = bytes_to_int32(len),
1031 .nameLength = len
1032 };
1033
1034 WriteReplyToClient(client, sizeof(xGetAtomNameReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetAtomNameReply
)), &reply); else WriteToClient(client, (int)(sizeof(xGetAtomNameReply
)), (&reply)); }
;
1035 WriteToClient(client, len, str);
1036 return Success0;
1037 }
1038 else {
1039 client->errorValue = stuff->id;
1040 return BadAtom5;
1041 }
1042}
1043
1044int
1045ProcGrabServer(ClientPtr client)
1046{
1047 int rc;
1048
1049 REQUEST_SIZE_MATCH(xReq)if ((sizeof(xReq) >> 2) != client->req_len) return(16
)
;
1050 if (grabState != GrabNone0 && client != grabClient) {
1051 ResetCurrentRequest(client);
1052 client->sequence--;
1053 BITSET(grabWaiters, client->index)grabWaiters[((client->index) >> 5)] |= (1U << (
(client->index) & 31))
;
1054 IgnoreClient(client);
1055 return Success0;
1056 }
1057 rc = OnlyListenToOneClient(client);
1058 if (rc != Success0)
1059 return rc;
1060 grabState = GrabKickout2;
1061 grabClient = client;
1062
1063 if (ServerGrabCallback) {
1064 ServerGrabInfoRec grabinfo;
1065
1066 grabinfo.client = client;
1067 grabinfo.grabstate = SERVER_GRABBED;
1068 CallCallbacks(&ServerGrabCallback, (void *) &grabinfo);
1069 }
1070
1071 return Success0;
1072}
1073
1074static void
1075UngrabServer(ClientPtr client)
1076{
1077 int i;
1078
1079 grabState = GrabNone0;
1080 ListenToAllClients();
1081 for (i = mskcnt((256 + 31) / 32); --i >= 0 && !grabWaiters[i];);
1082 if (i >= 0) {
1083 i <<= 5;
1084 while (!GETBIT(grabWaiters, i)(grabWaiters[((i) >> 5)] & (1U << ((i) & 31
)))
)
1085 i++;
1086 BITCLEAR(grabWaiters, i)grabWaiters[((i) >> 5)] &= ~(1U << ((i) &
31))
;
1087 AttendClient(clients[i]);
1088 }
1089
1090 if (ServerGrabCallback) {
1091 ServerGrabInfoRec grabinfo;
1092
1093 grabinfo.client = client;
1094 grabinfo.grabstate = SERVER_UNGRABBED;
1095 CallCallbacks(&ServerGrabCallback, (void *) &grabinfo);
1096 }
1097}
1098
1099int
1100ProcUngrabServer(ClientPtr client)
1101{
1102 REQUEST_SIZE_MATCH(xReq)if ((sizeof(xReq) >> 2) != client->req_len) return(16
)
;
1103 UngrabServer(client);
1104 return Success0;
1105}
1106
1107int
1108ProcTranslateCoords(ClientPtr client)
1109{
1110 REQUEST(xTranslateCoordsReq)xTranslateCoordsReq *stuff = (xTranslateCoordsReq *)client->
requestBuffer
;
1111
1112 WindowPtr pWin, pDst;
1113 xTranslateCoordsReply rep;
1114 int rc;
1115
1116 REQUEST_SIZE_MATCH(xTranslateCoordsReq)if ((sizeof(xTranslateCoordsReq) >> 2) != client->req_len
) return(16)
;
1117 rc = dixLookupWindow(&pWin, stuff->srcWid, client, DixGetAttrAccess(1<<4));
1118 if (rc != Success0)
1119 return rc;
1120 rc = dixLookupWindow(&pDst, stuff->dstWid, client, DixGetAttrAccess(1<<4));
1121 if (rc != Success0)
1122 return rc;
1123
1124 rep = (xTranslateCoordsReply) {
1125 .type = X_Reply1,
1126 .sequenceNumber = client->sequence,
1127 .length = 0
1128 };
1129 if (!SAME_SCREENS(pWin->drawable, pDst->drawable)( (pWin->drawable.pScreen == pDst->drawable.pScreen))) {
1130 rep.sameScreen = xFalse0;
1131 rep.child = None0L;
1132 rep.dstX = rep.dstY = 0;
1133 }
1134 else {
1135 INT16 x, y;
1136
1137 rep.sameScreen = xTrue1;
1138 rep.child = None0L;
1139 /* computing absolute coordinates -- adjust to destination later */
1140 x = pWin->drawable.x + stuff->srcX;
1141 y = pWin->drawable.y + stuff->srcY;
1142 pWin = pDst->firstChild;
1143 while (pWin) {
1144 BoxRec box;
1145
1146 if ((pWin->mapped) &&
1147 (x >= pWin->drawable.x - wBorderWidth(pWin)((int) (pWin)->borderWidth)) &&
1148 (x < pWin->drawable.x + (int) pWin->drawable.width +
1149 wBorderWidth(pWin)((int) (pWin)->borderWidth)) &&
1150 (y >= pWin->drawable.y - wBorderWidth(pWin)((int) (pWin)->borderWidth)) &&
1151 (y < pWin->drawable.y + (int) pWin->drawable.height +
1152 wBorderWidth(pWin)((int) (pWin)->borderWidth))
1153 /* When a window is shaped, a further check
1154 * is made to see if the point is inside
1155 * borderSize
1156 */
1157 && (!wBoundingShape(pWin)((pWin)->optional ? (pWin)->optional->boundingShape :
((void*)0))
||
1158 RegionContainsPoint(&pWin->borderSize, x, y, &box))
1159
1160 && (!wInputShape(pWin)((pWin)->optional ? (pWin)->optional->inputShape : (
(void*)0))
||
1161 RegionContainsPoint(wInputShape(pWin)((pWin)->optional ? (pWin)->optional->inputShape : (
(void*)0))
,
1162 x - pWin->drawable.x,
1163 y - pWin->drawable.y, &box))
1164 ) {
1165 rep.child = pWin->drawable.id;
1166 pWin = (WindowPtr) NULL((void*)0);
1167 }
1168 else
1169 pWin = pWin->nextSib;
1170 }
1171 /* adjust to destination coordinates */
1172 rep.dstX = x - pDst->drawable.x;
1173 rep.dstY = y - pDst->drawable.y;
1174 }
1175 WriteReplyToClient(client, sizeof(xTranslateCoordsReply), &rep){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xTranslateCoordsReply
)), &rep); else WriteToClient(client, (int)(sizeof(xTranslateCoordsReply
)), (&rep)); }
;
1176 return Success0;
1177}
1178
1179int
1180ProcOpenFont(ClientPtr client)
1181{
1182 int err;
1183
1184 REQUEST(xOpenFontReq)xOpenFontReq *stuff = (xOpenFontReq *)client->requestBuffer;
1185
1186 REQUEST_FIXED_SIZE(xOpenFontReq, stuff->nbytes)if (((sizeof(xOpenFontReq) >> 2) > client->req_len
) || (((stuff->nbytes) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xOpenFontReq) + (stuff->nbytes) +
3) >> 2) != (uint64_t) client->req_len)) return(16)
;
1187 client->errorValue = stuff->fid;
1188 LEGAL_NEW_RESOURCE(stuff->fid, client)if (!LegalNewID(stuff->fid,client)) { client->errorValue
= stuff->fid; return 14; }
;
1189 err = OpenFont(client, stuff->fid, (Mask) 0,
1190 stuff->nbytes, (char *) &stuff[1]);
1191 if (err == Success0) {
1192 return Success0;
1193 }
1194 else
1195 return err;
1196}
1197
1198int
1199ProcCloseFont(ClientPtr client)
1200{
1201 FontPtr pFont;
1202 int rc;
1203
1204 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
1205
1206 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
1207 rc = dixLookupResourceByType((void **) &pFont, stuff->id, RT_FONT((RESTYPE)4),
1208 client, DixDestroyAccess(1<<2));
1209 if (rc == Success0) {
1210 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
1211 return Success0;
1212 }
1213 else {
1214 client->errorValue = stuff->id;
1215 return rc;
1216 }
1217}
1218
1219int
1220ProcQueryFont(ClientPtr client)
1221{
1222 xQueryFontReply *reply;
1223 FontPtr pFont;
1224 int rc;
1225
1226 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
1227 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
1228
1229 rc = dixLookupFontable(&pFont, stuff->id, client, DixGetAttrAccess(1<<4));
1230 if (rc != Success0)
1231 return rc;
1232
1233 {
1234 xCharInfo *pmax = FONTINKMAX(pFont)(&((pFont)->info.ink_maxbounds));
1235 xCharInfo *pmin = FONTINKMIN(pFont)(&((pFont)->info.ink_minbounds));
1236 int nprotoxcistructs;
1237 int rlength;
1238
1239 nprotoxcistructs = (pmax->rightSideBearing == pmin->rightSideBearing &&
1240 pmax->leftSideBearing == pmin->leftSideBearing &&
1241 pmax->descent == pmin->descent &&
1242 pmax->ascent == pmin->ascent &&
1243 pmax->characterWidth == pmin->characterWidth) ?
1244 0 : N2dChars(pFont)(((pFont)->info.lastCol - (pFont)->info.firstCol + 1) *
((pFont)->info.lastRow - (pFont)->info.firstRow + 1))
;
1245
1246 rlength = sizeof(xQueryFontReply) +
1247 FONTINFONPROPS(FONTCHARSET(pFont))((pFont))->info.nprops * sizeof(xFontProp) +
1248 nprotoxcistructs * sizeof(xCharInfo);
1249 reply = calloc(1, rlength);
1250 if (!reply) {
1251 return BadAlloc11;
1252 }
1253
1254 reply->type = X_Reply1;
1255 reply->length = bytes_to_int32(rlength - sizeof(xGenericReply));
1256 reply->sequenceNumber = client->sequence;
1257 QueryFont(pFont, reply, nprotoxcistructs);
1258
1259 WriteReplyToClient(client, rlength, reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(rlength), reply
); else WriteToClient(client, (int)(rlength), (reply)); }
;
1260 free(reply);
1261 return Success0;
1262 }
1263}
1264
1265int
1266ProcQueryTextExtents(ClientPtr client)
1267{
1268 xQueryTextExtentsReply reply;
1269 FontPtr pFont;
1270 ExtentInfoRec info;
1271 unsigned long length;
1272 int rc;
1273
1274 REQUEST(xQueryTextExtentsReq)xQueryTextExtentsReq *stuff = (xQueryTextExtentsReq *)client->
requestBuffer
;
1275 REQUEST_AT_LEAST_SIZE(xQueryTextExtentsReq)if ((sizeof(xQueryTextExtentsReq) >> 2) > client->
req_len ) return(16)
;
1276
1277 rc = dixLookupFontable(&pFont, stuff->fid, client, DixGetAttrAccess(1<<4));
1278 if (rc != Success0)
1279 return rc;
1280
1281 length = client->req_len - bytes_to_int32(sizeof(xQueryTextExtentsReq));
1282 length = length << 1;
1283 if (stuff->oddLength) {
1284 if (length == 0)
1285 return BadLength16;
1286 length--;
1287 }
1288 if (!QueryTextExtents(pFont, length, (unsigned char *) &stuff[1], &info))
1289 return BadAlloc11;
1290 reply = (xQueryTextExtentsReply) {
1291 .type = X_Reply1,
1292 .drawDirection = info.drawDirection,
1293 .sequenceNumber = client->sequence,
1294 .length = 0,
1295 .fontAscent = info.fontAscent,
1296 .fontDescent = info.fontDescent,
1297 .overallAscent = info.overallAscent,
1298 .overallDescent = info.overallDescent,
1299 .overallWidth = info.overallWidth,
1300 .overallLeft = info.overallLeft,
1301 .overallRight = info.overallRight
1302 };
1303 WriteReplyToClient(client, sizeof(xQueryTextExtentsReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xQueryTextExtentsReply
)), &reply); else WriteToClient(client, (int)(sizeof(xQueryTextExtentsReply
)), (&reply)); }
;
1304 return Success0;
1305}
1306
1307int
1308ProcListFonts(ClientPtr client)
1309{
1310 REQUEST(xListFontsReq)xListFontsReq *stuff = (xListFontsReq *)client->requestBuffer;
1311
1312 REQUEST_FIXED_SIZE(xListFontsReq, stuff->nbytes)if (((sizeof(xListFontsReq) >> 2) > client->req_len
) || (((stuff->nbytes) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xListFontsReq) + (stuff->nbytes)
+ 3) >> 2) != (uint64_t) client->req_len)) return(16
)
;
1313
1314 return ListFonts(client, (unsigned char *) &stuff[1], stuff->nbytes,
1315 stuff->maxNames);
1316}
1317
1318int
1319ProcListFontsWithInfo(ClientPtr client)
1320{
1321 REQUEST(xListFontsWithInfoReq)xListFontsWithInfoReq *stuff = (xListFontsWithInfoReq *)client
->requestBuffer
;
1322
1323 REQUEST_FIXED_SIZE(xListFontsWithInfoReq, stuff->nbytes)if (((sizeof(xListFontsWithInfoReq) >> 2) > client->
req_len) || (((stuff->nbytes) >> 2) >= client->
req_len) || ((((uint64_t) sizeof(xListFontsWithInfoReq) + (stuff
->nbytes) + 3) >> 2) != (uint64_t) client->req_len
)) return(16)
;
1324
1325 return StartListFontsWithInfo(client, stuff->nbytes,
1326 (unsigned char *) &stuff[1], stuff->maxNames);
1327}
1328
1329/**
1330 *
1331 * \param value must conform to DeleteType
1332 */
1333int
1334dixDestroyPixmap(void *value, XID pid)
1335{
1336 PixmapPtr pPixmap = (PixmapPtr) value;
1337
1338 return (*pPixmap->drawable.pScreen->DestroyPixmap) (pPixmap);
1339}
1340
1341int
1342ProcCreatePixmap(ClientPtr client)
1343{
1344 PixmapPtr pMap;
1345 DrawablePtr pDraw;
1346
1347 REQUEST(xCreatePixmapReq)xCreatePixmapReq *stuff = (xCreatePixmapReq *)client->requestBuffer;
1348 DepthPtr pDepth;
1349 int i, rc;
1350
1351 REQUEST_SIZE_MATCH(xCreatePixmapReq)if ((sizeof(xCreatePixmapReq) >> 2) != client->req_len
) return(16)
;
1352 client->errorValue = stuff->pid;
1353 LEGAL_NEW_RESOURCE(stuff->pid, client)if (!LegalNewID(stuff->pid,client)) { client->errorValue
= stuff->pid; return 14; }
;
1354
1355 rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY(-1),
1356 DixGetAttrAccess(1<<4));
1357 if (rc != Success0)
1358 return rc;
1359
1360 if (!stuff->width || !stuff->height) {
1361 client->errorValue = 0;
1362 return BadValue2;
1363 }
1364 if (stuff->width > 32767 || stuff->height > 32767) {
1365 /* It is allowed to try and allocate a pixmap which is larger than
1366 * 32767 in either dimension. However, all of the framebuffer code
1367 * is buggy and does not reliably draw to such big pixmaps, basically
1368 * because the Region data structure operates with signed shorts
1369 * for the rectangles in it.
1370 *
1371 * Furthermore, several places in the X server computes the
1372 * size in bytes of the pixmap and tries to store it in an
1373 * integer. This integer can overflow and cause the allocated size
1374 * to be much smaller.
1375 *
1376 * So, such big pixmaps are rejected here with a BadAlloc
1377 */
1378 return BadAlloc11;
1379 }
1380 if (stuff->depth != 1) {
1381 pDepth = pDraw->pScreen->allowedDepths;
1382 for (i = 0; i < pDraw->pScreen->numDepths; i++, pDepth++)
1383 if (pDepth->depth == stuff->depth)
1384 goto CreatePmap;
1385 client->errorValue = stuff->depth;
1386 return BadValue2;
1387 }
1388 CreatePmap:
1389 pMap = (PixmapPtr) (*pDraw->pScreen->CreatePixmap)
1390 (pDraw->pScreen, stuff->width, stuff->height, stuff->depth, 0);
1391 if (pMap) {
1392 pMap->drawable.serialNumber = NEXT_SERIAL_NUMBER((++globalSerialNumber) > (1L<<28) ? (globalSerialNumber
= 1): globalSerialNumber)
;
1393 pMap->drawable.id = stuff->pid;
1394 /* security creation/labeling check */
1395 rc = XaceHook(XACE_RESOURCE_ACCESS2, client, stuff->pid, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)),
1396 pMap, RT_NONE((RESTYPE)0), NULL((void*)0), DixCreateAccess(1<<3));
1397 if (rc != Success0) {
1398 (*pDraw->pScreen->DestroyPixmap) (pMap);
1399 return rc;
1400 }
1401 if (AddResourceDarwin_X_AddResource(stuff->pid, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)), (void *) pMap))
1402 return Success0;
1403 }
1404 return BadAlloc11;
1405}
1406
1407int
1408ProcFreePixmap(ClientPtr client)
1409{
1410 PixmapPtr pMap;
1411 int rc;
1412
1413 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
1414 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
1415
1416 rc = dixLookupResourceByType((void **) &pMap, stuff->id, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)),
1417 client, DixDestroyAccess(1<<2));
1418 if (rc == Success0) {
1419 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
1420 return Success0;
1421 }
1422 else {
1423 client->errorValue = stuff->id;
1424 return rc;
1425 }
1426}
1427
1428int
1429ProcCreateGC(ClientPtr client)
1430{
1431 int error, rc;
1432 GC *pGC;
1433 DrawablePtr pDraw;
1434 unsigned len;
1435
1436 REQUEST(xCreateGCReq)xCreateGCReq *stuff = (xCreateGCReq *)client->requestBuffer;
1437
1438 REQUEST_AT_LEAST_SIZE(xCreateGCReq)if ((sizeof(xCreateGCReq) >> 2) > client->req_len
) return(16)
;
1439 client->errorValue = stuff->gc;
1440 LEGAL_NEW_RESOURCE(stuff->gc, client)if (!LegalNewID(stuff->gc,client)) { client->errorValue
= stuff->gc; return 14; }
;
1441 rc = dixLookupDrawable(&pDraw, stuff->drawable, client, 0,
1442 DixGetAttrAccess(1<<4));
1443 if (rc != Success0)
1444 return rc;
1445
1446 len = client->req_len - bytes_to_int32(sizeof(xCreateGCReq));
1447 if (len != Ones(stuff->mask))
1448 return BadLength16;
1449 pGC = (GC *) CreateGC(pDraw, stuff->mask, (XID *) &stuff[1], &error,
1450 stuff->gc, client);
1451 if (error != Success0)
1452 return error;
1453 if (!AddResourceDarwin_X_AddResource(stuff->gc, RT_GC((RESTYPE)3), (void *) pGC))
1454 return BadAlloc11;
1455 return Success0;
1456}
1457
1458int
1459ProcChangeGC(ClientPtr client)
1460{
1461 GC *pGC;
1462 int result;
1463 unsigned len;
1464
1465 REQUEST(xChangeGCReq)xChangeGCReq *stuff = (xChangeGCReq *)client->requestBuffer;
1466 REQUEST_AT_LEAST_SIZE(xChangeGCReq)if ((sizeof(xChangeGCReq) >> 2) > client->req_len
) return(16)
;
1467
1468 result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess(1<<5));
1469 if (result != Success0)
1470 return result;
1471
1472 len = client->req_len - bytes_to_int32(sizeof(xChangeGCReq));
1473 if (len != Ones(stuff->mask))
1474 return BadLength16;
1475
1476 return ChangeGCXIDs(client, pGC, stuff->mask, (CARD32 *) &stuff[1]);
1477}
1478
1479int
1480ProcCopyGC(ClientPtr client)
1481{
1482 GC *dstGC;
1483 GC *pGC;
1484 int result;
1485
1486 REQUEST(xCopyGCReq)xCopyGCReq *stuff = (xCopyGCReq *)client->requestBuffer;
1487 REQUEST_SIZE_MATCH(xCopyGCReq)if ((sizeof(xCopyGCReq) >> 2) != client->req_len) return
(16)
;
1488
1489 result = dixLookupGC(&pGC, stuff->srcGC, client, DixGetAttrAccess(1<<4));
1490 if (result != Success0)
1491 return result;
1492 result = dixLookupGC(&dstGC, stuff->dstGC, client, DixSetAttrAccess(1<<5));
1493 if (result != Success0)
1494 return result;
1495 if ((dstGC->pScreen != pGC->pScreen) || (dstGC->depth != pGC->depth))
1496 return BadMatch8;
1497 if (stuff->mask & ~GCAllBits((1 << (22 + 1)) - 1)) {
1498 client->errorValue = stuff->mask;
1499 return BadValue2;
1500 }
1501 return CopyGC(pGC, dstGC, stuff->mask);
1502}
1503
1504int
1505ProcSetDashes(ClientPtr client)
1506{
1507 GC *pGC;
1508 int result;
1509
1510 REQUEST(xSetDashesReq)xSetDashesReq *stuff = (xSetDashesReq *)client->requestBuffer;
1511
1512 REQUEST_FIXED_SIZE(xSetDashesReq, stuff->nDashes)if (((sizeof(xSetDashesReq) >> 2) > client->req_len
) || (((stuff->nDashes) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xSetDashesReq) + (stuff->nDashes
) + 3) >> 2) != (uint64_t) client->req_len)) return(
16)
;
1513 if (stuff->nDashes == 0) {
1514 client->errorValue = 0;
1515 return BadValue2;
1516 }
1517
1518 result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess(1<<5));
1519 if (result != Success0)
1520 return result;
1521
1522 /* If there's an error, either there's no sensible errorValue,
1523 * or there was a dash segment of 0. */
1524 client->errorValue = 0;
1525 return SetDashes(pGC, stuff->dashOffset, stuff->nDashes,
1526 (unsigned char *) &stuff[1]);
1527}
1528
1529int
1530ProcSetClipRectangles(ClientPtr client)
1531{
1532 int nr, result;
1533 GC *pGC;
1534
1535 REQUEST(xSetClipRectanglesReq)xSetClipRectanglesReq *stuff = (xSetClipRectanglesReq *)client
->requestBuffer
;
1536
1537 REQUEST_AT_LEAST_SIZE(xSetClipRectanglesReq)if ((sizeof(xSetClipRectanglesReq) >> 2) > client->
req_len ) return(16)
;
1538 if ((stuff->ordering != Unsorted0) && (stuff->ordering != YSorted1) &&
1539 (stuff->ordering != YXSorted2) && (stuff->ordering != YXBanded3)) {
1540 client->errorValue = stuff->ordering;
1541 return BadValue2;
1542 }
1543 result = dixLookupGC(&pGC, stuff->gc, client, DixSetAttrAccess(1<<5));
1544 if (result != Success0)
1545 return result;
1546
1547 nr = (client->req_len << 2) - sizeof(xSetClipRectanglesReq);
1548 if (nr & 4)
1549 return BadLength16;
1550 nr >>= 3;
1551 return SetClipRects(pGC, stuff->xOrigin, stuff->yOrigin,
1552 nr, (xRectangle *) &stuff[1], (int) stuff->ordering);
1553}
1554
1555int
1556ProcFreeGC(ClientPtr client)
1557{
1558 GC *pGC;
1559 int rc;
1560
1561 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
1562 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
1563
1564 rc = dixLookupGC(&pGC, stuff->id, client, DixDestroyAccess(1<<2));
1565 if (rc != Success0)
1566 return rc;
1567
1568 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
1569 return Success0;
1570}
1571
1572int
1573ProcClearToBackground(ClientPtr client)
1574{
1575 REQUEST(xClearAreaReq)xClearAreaReq *stuff = (xClearAreaReq *)client->requestBuffer;
1576 WindowPtr pWin;
1577 int rc;
1578
1579 REQUEST_SIZE_MATCH(xClearAreaReq)if ((sizeof(xClearAreaReq) >> 2) != client->req_len)
return(16)
;
1580 rc = dixLookupWindow(&pWin, stuff->window, client, DixWriteAccess(1<<1));
1581 if (rc != Success0)
1582 return rc;
1583 if (pWin->drawable.class == InputOnly2) {
1584 client->errorValue = stuff->window;
1585 return BadMatch8;
1586 }
1587 if ((stuff->exposures != xTrue1) && (stuff->exposures != xFalse0)) {
1588 client->errorValue = stuff->exposures;
1589 return BadValue2;
1590 }
1591 (*pWin->drawable.pScreen->ClearToBackground) (pWin, stuff->x, stuff->y,
1592 stuff->width, stuff->height,
1593 (Bool) stuff->exposures);
1594 return Success0;
1595}
1596
1597/* send GraphicsExpose events, or a NoExpose event, based on the region */
1598void
1599SendGraphicsExpose(ClientPtr client, RegionPtr pRgn, XID drawable,
1600 int major, int minor)
1601{
1602 if (pRgn && !RegionNil(pRgn)) {
1603 xEvent *pEvent;
1604 xEvent *pe;
1605 BoxPtr pBox;
1606 int i;
1607 int numRects;
1608
1609 numRects = RegionNumRects(pRgn);
1610 pBox = RegionRects(pRgn);
1611 if (!(pEvent = calloc(numRects, sizeof(xEvent))))
1612 return;
1613 pe = pEvent;
1614
1615 for (i = 1; i <= numRects; i++, pe++, pBox++) {
1616 pe->u.u.type = GraphicsExpose13;
1617 pe->u.graphicsExposure.drawable = drawable;
1618 pe->u.graphicsExposure.x = pBox->x1;
1619 pe->u.graphicsExposure.y = pBox->y1;
1620 pe->u.graphicsExposure.width = pBox->x2 - pBox->x1;
1621 pe->u.graphicsExposure.height = pBox->y2 - pBox->y1;
1622 pe->u.graphicsExposure.count = numRects - i;
1623 pe->u.graphicsExposure.majorEvent = major;
1624 pe->u.graphicsExposure.minorEvent = minor;
1625 }
1626 /* GraphicsExpose is a "critical event", which TryClientEvents
1627 * handles specially. */
1628 TryClientEvents(client, NULL((void*)0), pEvent, numRects,
1629 (Mask) 0, NoEventMask0L, NullGrab((GrabPtr)((void*)0)));
1630 free(pEvent);
1631 }
1632 else {
1633 xEvent event = {
1634 .u.noExposure.drawable = drawable,
1635 .u.noExposure.majorEvent = major,
1636 .u.noExposure.minorEvent = minor
1637 };
1638 event.u.u.type = NoExpose14;
1639 WriteEventsToClient(client, 1, &event);
1640 }
1641}
1642
1643int
1644ProcCopyArea(ClientPtr client)
1645{
1646 DrawablePtr pDst;
1647 DrawablePtr pSrc;
1648 GC *pGC;
1649
1650 REQUEST(xCopyAreaReq)xCopyAreaReq *stuff = (xCopyAreaReq *)client->requestBuffer;
1651 RegionPtr pRgn;
1652 int rc;
1653
1654 REQUEST_SIZE_MATCH(xCopyAreaReq)if ((sizeof(xCopyAreaReq) >> 2) != client->req_len) return
(16)
;
1655
1656 VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pDst, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDst), stuff->dstDrawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDst->
depth) || (pGC->pScreen != pDst->pScreen)) return 8; } if
(pGC->serialNumber != pDst->serialNumber) ValidateGC(pDst
, pGC);
;
1657 if (stuff->dstDrawable != stuff->srcDrawable) {
1658 rc = dixLookupDrawable(&pSrc, stuff->srcDrawable, client, 0,
1659 DixReadAccess(1<<0));
1660 if (rc != Success0)
1661 return rc;
1662 if ((pDst->pScreen != pSrc->pScreen) || (pDst->depth != pSrc->depth)) {
1663 client->errorValue = stuff->dstDrawable;
1664 return BadMatch8;
1665 }
1666 }
1667 else
1668 pSrc = pDst;
1669
1670 pRgn = (*pGC->ops->CopyArea) (pSrc, pDst, pGC, stuff->srcX, stuff->srcY,
1671 stuff->width, stuff->height,
1672 stuff->dstX, stuff->dstY);
1673 if (pGC->graphicsExposures) {
1674 SendGraphicsExpose(client, pRgn, stuff->dstDrawable, X_CopyArea62, 0);
1675 if (pRgn)
1676 RegionDestroy(pRgn);
1677 }
1678
1679 return Success0;
1680}
1681
1682int
1683ProcCopyPlane(ClientPtr client)
1684{
1685 DrawablePtr psrcDraw, pdstDraw;
1686 GC *pGC;
1687
1688 REQUEST(xCopyPlaneReq)xCopyPlaneReq *stuff = (xCopyPlaneReq *)client->requestBuffer;
1689 RegionPtr pRgn;
1690 int rc;
1691
1692 REQUEST_SIZE_MATCH(xCopyPlaneReq)if ((sizeof(xCopyPlaneReq) >> 2) != client->req_len)
return(16)
;
1693
1694 VALIDATE_DRAWABLE_AND_GC(stuff->dstDrawable, pdstDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pdstDraw), stuff->dstDrawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pdstDraw
->depth) || (pGC->pScreen != pdstDraw->pScreen)) return
8; } if (pGC->serialNumber != pdstDraw->serialNumber) ValidateGC
(pdstDraw, pGC);
;
1695 if (stuff->dstDrawable != stuff->srcDrawable) {
1696 rc = dixLookupDrawable(&psrcDraw, stuff->srcDrawable, client, 0,
1697 DixReadAccess(1<<0));
1698 if (rc != Success0)
1699 return rc;
1700
1701 if (pdstDraw->pScreen != psrcDraw->pScreen) {
1702 client->errorValue = stuff->dstDrawable;
1703 return BadMatch8;
1704 }
1705 }
1706 else
1707 psrcDraw = pdstDraw;
1708
1709 /* Check to see if stuff->bitPlane has exactly ONE good bit set */
1710 if (stuff->bitPlane == 0 || (stuff->bitPlane & (stuff->bitPlane - 1)) ||
1711 (stuff->bitPlane > (1L << (psrcDraw->depth - 1)))) {
1712 client->errorValue = stuff->bitPlane;
1713 return BadValue2;
1714 }
1715
1716 pRgn =
1717 (*pGC->ops->CopyPlane) (psrcDraw, pdstDraw, pGC, stuff->srcX,
1718 stuff->srcY, stuff->width, stuff->height,
1719 stuff->dstX, stuff->dstY, stuff->bitPlane);
1720 if (pGC->graphicsExposures) {
1721 SendGraphicsExpose(client, pRgn, stuff->dstDrawable, X_CopyPlane63, 0);
1722 if (pRgn)
1723 RegionDestroy(pRgn);
1724 }
1725 return Success0;
1726}
1727
1728int
1729ProcPolyPoint(ClientPtr client)
1730{
1731 int npoint;
1732 GC *pGC;
1733 DrawablePtr pDraw;
1734
1735 REQUEST(xPolyPointReq)xPolyPointReq *stuff = (xPolyPointReq *)client->requestBuffer;
1736
1737 REQUEST_AT_LEAST_SIZE(xPolyPointReq)if ((sizeof(xPolyPointReq) >> 2) > client->req_len
) return(16)
;
1738 if ((stuff->coordMode != CoordModeOrigin0) &&
1739 (stuff->coordMode != CoordModePrevious1)) {
1740 client->errorValue = stuff->coordMode;
1741 return BadValue2;
1742 }
1743 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1744 npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyPointReq));
1745 if (npoint)
1746 (*pGC->ops->PolyPoint) (pDraw, pGC, stuff->coordMode, npoint,
1747 (xPoint *) &stuff[1]);
1748 return Success0;
1749}
1750
1751int
1752ProcPolyLine(ClientPtr client)
1753{
1754 int npoint;
1755 GC *pGC;
1756 DrawablePtr pDraw;
1757
1758 REQUEST(xPolyLineReq)xPolyLineReq *stuff = (xPolyLineReq *)client->requestBuffer;
1759
1760 REQUEST_AT_LEAST_SIZE(xPolyLineReq)if ((sizeof(xPolyLineReq) >> 2) > client->req_len
) return(16)
;
1761 if ((stuff->coordMode != CoordModeOrigin0) &&
1762 (stuff->coordMode != CoordModePrevious1)) {
1763 client->errorValue = stuff->coordMode;
1764 return BadValue2;
1765 }
1766 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1767 npoint = bytes_to_int32((client->req_len << 2) - sizeof(xPolyLineReq));
1768 if (npoint > 1)
1769 (*pGC->ops->Polylines) (pDraw, pGC, stuff->coordMode, npoint,
1770 (DDXPointPtr) &stuff[1]);
1771 return Success0;
1772}
1773
1774int
1775ProcPolySegment(ClientPtr client)
1776{
1777 int nsegs;
1778 GC *pGC;
1779 DrawablePtr pDraw;
1780
1781 REQUEST(xPolySegmentReq)xPolySegmentReq *stuff = (xPolySegmentReq *)client->requestBuffer;
1782
1783 REQUEST_AT_LEAST_SIZE(xPolySegmentReq)if ((sizeof(xPolySegmentReq) >> 2) > client->req_len
) return(16)
;
1784 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1785 nsegs = (client->req_len << 2) - sizeof(xPolySegmentReq);
1786 if (nsegs & 4)
1787 return BadLength16;
1788 nsegs >>= 3;
1789 if (nsegs)
1790 (*pGC->ops->PolySegment) (pDraw, pGC, nsegs, (xSegment *) &stuff[1]);
1791 return Success0;
1792}
1793
1794int
1795ProcPolyRectangle(ClientPtr client)
1796{
1797 int nrects;
1798 GC *pGC;
1799 DrawablePtr pDraw;
1800
1801 REQUEST(xPolyRectangleReq)xPolyRectangleReq *stuff = (xPolyRectangleReq *)client->requestBuffer;
1802
1803 REQUEST_AT_LEAST_SIZE(xPolyRectangleReq)if ((sizeof(xPolyRectangleReq) >> 2) > client->req_len
) return(16)
;
1804 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1805 nrects = (client->req_len << 2) - sizeof(xPolyRectangleReq);
1806 if (nrects & 4)
1807 return BadLength16;
1808 nrects >>= 3;
1809 if (nrects)
1810 (*pGC->ops->PolyRectangle) (pDraw, pGC,
1811 nrects, (xRectangle *) &stuff[1]);
1812 return Success0;
1813}
1814
1815int
1816ProcPolyArc(ClientPtr client)
1817{
1818 int narcs;
1819 GC *pGC;
1820 DrawablePtr pDraw;
1821
1822 REQUEST(xPolyArcReq)xPolyArcReq *stuff = (xPolyArcReq *)client->requestBuffer;
1823
1824 REQUEST_AT_LEAST_SIZE(xPolyArcReq)if ((sizeof(xPolyArcReq) >> 2) > client->req_len )
return(16)
;
1825 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1826 narcs = (client->req_len << 2) - sizeof(xPolyArcReq);
1827 if (narcs % sizeof(xArc))
1828 return BadLength16;
1829 narcs /= sizeof(xArc);
1830 if (narcs)
1831 (*pGC->ops->PolyArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]);
1832 return Success0;
1833}
1834
1835int
1836ProcFillPoly(ClientPtr client)
1837{
1838 int things;
1839 GC *pGC;
1840 DrawablePtr pDraw;
1841
1842 REQUEST(xFillPolyReq)xFillPolyReq *stuff = (xFillPolyReq *)client->requestBuffer;
1843
1844 REQUEST_AT_LEAST_SIZE(xFillPolyReq)if ((sizeof(xFillPolyReq) >> 2) > client->req_len
) return(16)
;
1845 if ((stuff->shape != Complex0) && (stuff->shape != Nonconvex1) &&
1846 (stuff->shape != Convex2)) {
1847 client->errorValue = stuff->shape;
1848 return BadValue2;
1849 }
1850 if ((stuff->coordMode != CoordModeOrigin0) &&
1851 (stuff->coordMode != CoordModePrevious1)) {
1852 client->errorValue = stuff->coordMode;
1853 return BadValue2;
1854 }
1855
1856 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1857 things = bytes_to_int32((client->req_len << 2) - sizeof(xFillPolyReq));
1858 if (things)
1859 (*pGC->ops->FillPolygon) (pDraw, pGC, stuff->shape,
1860 stuff->coordMode, things,
1861 (DDXPointPtr) &stuff[1]);
1862 return Success0;
1863}
1864
1865int
1866ProcPolyFillRectangle(ClientPtr client)
1867{
1868 int things;
1869 GC *pGC;
1870 DrawablePtr pDraw;
1871
1872 REQUEST(xPolyFillRectangleReq)xPolyFillRectangleReq *stuff = (xPolyFillRectangleReq *)client
->requestBuffer
;
1873
1874 REQUEST_AT_LEAST_SIZE(xPolyFillRectangleReq)if ((sizeof(xPolyFillRectangleReq) >> 2) > client->
req_len ) return(16)
;
1875 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1876 things = (client->req_len << 2) - sizeof(xPolyFillRectangleReq);
1877 if (things & 4)
1878 return BadLength16;
1879 things >>= 3;
1880
1881 if (things)
1882 (*pGC->ops->PolyFillRect) (pDraw, pGC, things,
1883 (xRectangle *) &stuff[1]);
1884 return Success0;
1885}
1886
1887int
1888ProcPolyFillArc(ClientPtr client)
1889{
1890 int narcs;
1891 GC *pGC;
1892 DrawablePtr pDraw;
1893
1894 REQUEST(xPolyFillArcReq)xPolyFillArcReq *stuff = (xPolyFillArcReq *)client->requestBuffer;
1895
1896 REQUEST_AT_LEAST_SIZE(xPolyFillArcReq)if ((sizeof(xPolyFillArcReq) >> 2) > client->req_len
) return(16)
;
1897 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1898 narcs = (client->req_len << 2) - sizeof(xPolyFillArcReq);
1899 if (narcs % sizeof(xArc))
1900 return BadLength16;
1901 narcs /= sizeof(xArc);
1902 if (narcs)
1903 (*pGC->ops->PolyFillArc) (pDraw, pGC, narcs, (xArc *) &stuff[1]);
1904 return Success0;
1905}
1906
1907#ifdef MATCH_CLIENT_ENDIAN
1908
1909int
1910ServerOrder(void)
1911{
1912 int whichbyte = 1;
1913
1914 if (*((char *) &whichbyte))
1915 return LSBFirst0;
1916 return MSBFirst1;
1917}
1918
1919#define ClientOrder(client) ((client)->swapped ? !ServerOrder() : ServerOrder())
1920
1921void
1922ReformatImage(char *base, int nbytes, int bpp, int order)
1923{
1924 switch (bpp) {
1925 case 1: /* yuck */
1926 if (BITMAP_BIT_ORDER0 != order)
1927 BitOrderInvert((unsigned char *) base, nbytes);
1928#if IMAGE_BYTE_ORDER0 != BITMAP_BIT_ORDER0 && BITMAP_SCANLINE_UNIT32 != 8
1929 ReformatImage(base, nbytes, BITMAP_SCANLINE_UNIT, order);
1930#endif
1931 break;
1932 case 4:
1933 break; /* yuck */
1934 case 8:
1935 break;
1936 case 16:
1937 if (IMAGE_BYTE_ORDER0 != order)
1938 TwoByteSwap((unsigned char *) base, nbytes);
1939 break;
1940 case 32:
1941 if (IMAGE_BYTE_ORDER0 != order)
1942 FourByteSwap((unsigned char *) base, nbytes);
1943 break;
1944 }
1945}
1946#else
1947#define ReformatImage(b,n,bpp,o)
1948#endif
1949
1950/* 64-bit server notes: the protocol restricts padding of images to
1951 * 8-, 16-, or 32-bits. We would like to have 64-bits for the server
1952 * to use internally. Removes need for internal alignment checking.
1953 * All of the PutImage functions could be changed individually, but
1954 * as currently written, they call other routines which require things
1955 * to be 64-bit padded on scanlines, so we changed things here.
1956 * If an image would be padded differently for 64- versus 32-, then
1957 * copy each scanline to a 64-bit padded scanline.
1958 * Also, we need to make sure that the image is aligned on a 64-bit
1959 * boundary, even if the scanlines are padded to our satisfaction.
1960 */
1961int
1962ProcPutImage(ClientPtr client)
1963{
1964 GC *pGC;
1965 DrawablePtr pDraw;
1966 long length; /* length of scanline server padded */
1967 long lengthProto; /* length of scanline protocol padded */
1968 char *tmpImage;
1969
1970 REQUEST(xPutImageReq)xPutImageReq *stuff = (xPutImageReq *)client->requestBuffer;
1971
1972 REQUEST_AT_LEAST_SIZE(xPutImageReq)if ((sizeof(xPutImageReq) >> 2) > client->req_len
) return(16)
;
1973 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
1974 if (stuff->format == XYBitmap0) {
1975 if ((stuff->depth != 1) ||
1976 (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad))
1977 return BadMatch8;
1978 length = BitmapBytePad(stuff->width + stuff->leftPad)(((int)((stuff->width + stuff->leftPad) + 32 - 1) >>
5) << 2)
;
1979 }
1980 else if (stuff->format == XYPixmap1) {
1981 if ((pDraw->depth != stuff->depth) ||
1982 (stuff->leftPad >= (unsigned int) screenInfo.bitmapScanlinePad))
1983 return BadMatch8;
1984 length = BitmapBytePad(stuff->width + stuff->leftPad)(((int)((stuff->width + stuff->leftPad) + 32 - 1) >>
5) << 2)
;
1985 length *= stuff->depth;
1986 }
1987 else if (stuff->format == ZPixmap2) {
1988 if ((pDraw->depth != stuff->depth) || (stuff->leftPad != 0))
1989 return BadMatch8;
1990 length = PixmapBytePad(stuff->width, stuff->depth)((PixmapWidthPaddingInfo[stuff->depth].notPower2 ? (((int)
(stuff->width) * PixmapWidthPaddingInfo[stuff->depth].bytesPerPixel
+ PixmapWidthPaddingInfo[stuff->depth].bytesPerPixel) >>
PixmapWidthPaddingInfo[stuff->depth].padBytesLog2) : ((int
)((stuff->width) + PixmapWidthPaddingInfo[stuff->depth]
.padRoundUp) >> PixmapWidthPaddingInfo[stuff->depth]
.padPixelsLog2)) << PixmapWidthPaddingInfo[stuff->depth
].padBytesLog2)
;
1991 }
1992 else {
1993 client->errorValue = stuff->format;
1994 return BadValue2;
1995 }
1996
1997 tmpImage = (char *) &stuff[1];
1998 lengthProto = length;
1999
2000 if (stuff->height != 0 && lengthProto >= (INT32_MAX2147483647 / stuff->height))
2001 return BadLength16;
2002
2003 if ((bytes_to_int32(lengthProto * stuff->height) +
2004 bytes_to_int32(sizeof(xPutImageReq))) != client->req_len)
2005 return BadLength16;
2006
2007 ReformatImage(tmpImage, lengthProto * stuff->height,
2008 stuff->format == ZPixmap ? BitsPerPixel(stuff->depth) : 1,
2009 ClientOrder(client));
2010
2011 (*pGC->ops->PutImage) (pDraw, pGC, stuff->depth, stuff->dstX, stuff->dstY,
2012 stuff->width, stuff->height,
2013 stuff->leftPad, stuff->format, tmpImage);
2014
2015 return Success0;
2016}
2017
2018static int
2019DoGetImage(ClientPtr client, int format, Drawable drawable,
2020 int x, int y, int width, int height,
2021 Mask planemask)
2022{
2023 DrawablePtr pDraw, pBoundingDraw;
2024 int nlines, linesPerBuf, rc;
2025 int linesDone;
2026
2027 /* coordinates relative to the bounding drawable */
2028 int relx, rely;
2029 long widthBytesLine, length;
2030 Mask plane = 0;
2031 char *pBuf;
2032 xGetImageReply xgi;
2033 RegionPtr pVisibleRegion = NULL((void*)0);
2034
2035 if ((format != XYPixmap1) && (format != ZPixmap2)) {
2036 client->errorValue = format;
2037 return BadValue2;
2038 }
2039 rc = dixLookupDrawable(&pDraw, drawable, client, 0, DixReadAccess(1<<0));
2040 if (rc != Success0)
2041 return rc;
2042
2043 memset(&xgi, 0, sizeof(xGetImageReply))__builtin___memset_chk (&xgi, 0, sizeof(xGetImageReply), __builtin_object_size
(&xgi, 0))
;
2044
2045 relx = x;
2046 rely = y;
2047
2048 if (pDraw->type == DRAWABLE_WINDOW0) {
2049 WindowPtr pWin = (WindowPtr) pDraw;
2050
2051 /* "If the drawable is a window, the window must be viewable ... or a
2052 * BadMatch error results" */
2053 if (!pWin->viewable)
2054 return BadMatch8;
2055
2056 /* If the drawable is a window, the rectangle must be contained within
2057 * its bounds (including the border). */
2058 if (x < -wBorderWidth(pWin)((int) (pWin)->borderWidth) ||
2059 x + width > wBorderWidth(pWin)((int) (pWin)->borderWidth) + (int) pDraw->width ||
2060 y < -wBorderWidth(pWin)((int) (pWin)->borderWidth) ||
2061 y + height > wBorderWidth(pWin)((int) (pWin)->borderWidth) + (int) pDraw->height)
2062 return BadMatch8;
2063
2064 relx += pDraw->x;
2065 rely += pDraw->y;
2066
2067 if (pDraw->pScreen->GetWindowPixmap) {
2068 PixmapPtr pPix = (*pDraw->pScreen->GetWindowPixmap) (pWin);
2069
2070 pBoundingDraw = &pPix->drawable;
2071#ifdef COMPOSITE
2072 relx -= pPix->screen_x;
2073 rely -= pPix->screen_y;
2074#endif
2075 }
2076 else {
2077 pBoundingDraw = (DrawablePtr) pDraw->pScreen->root;
2078 }
2079
2080 xgi.visual = wVisual(pWin)((pWin)->optional ? (pWin)->optional->visual : FindWindowWithOptional
(pWin)->optional->visual)
;
2081 }
2082 else {
2083 pBoundingDraw = pDraw;
2084 xgi.visual = None0L;
2085 }
2086
2087 /* "If the drawable is a pixmap, the given rectangle must be wholly
2088 * contained within the pixmap, or a BadMatch error results. If the
2089 * drawable is a window [...] it must be the case that if there were no
2090 * inferiors or overlapping windows, the specified rectangle of the window
2091 * would be fully visible on the screen and wholly contained within the
2092 * outside edges of the window, or a BadMatch error results."
2093 *
2094 * We relax the window case slightly to mean that the rectangle must exist
2095 * within the bounds of the window's backing pixmap. In particular, this
2096 * means that a GetImage request may succeed or fail with BadMatch depending
2097 * on whether any of its ancestor windows are redirected. */
2098 if (relx < 0 || relx + width > (int) pBoundingDraw->width ||
2099 rely < 0 || rely + height > (int) pBoundingDraw->height)
2100 return BadMatch8;
2101
2102 xgi.type = X_Reply1;
2103 xgi.sequenceNumber = client->sequence;
2104 xgi.depth = pDraw->depth;
2105 if (format == ZPixmap2) {
2106 widthBytesLine = PixmapBytePad(width, pDraw->depth)((PixmapWidthPaddingInfo[pDraw->depth].notPower2 ? (((int)
(width) * PixmapWidthPaddingInfo[pDraw->depth].bytesPerPixel
+ PixmapWidthPaddingInfo[pDraw->depth].bytesPerPixel) >>
PixmapWidthPaddingInfo[pDraw->depth].padBytesLog2) : ((int
)((width) + PixmapWidthPaddingInfo[pDraw->depth].padRoundUp
) >> PixmapWidthPaddingInfo[pDraw->depth].padPixelsLog2
)) << PixmapWidthPaddingInfo[pDraw->depth].padBytesLog2
)
;
2107 length = widthBytesLine * height;
2108
2109 }
2110 else {
2111 widthBytesLine = BitmapBytePad(width)(((int)((width) + 32 - 1) >> 5) << 2);
2112 plane = ((Mask) 1) << (pDraw->depth - 1);
2113 /* only planes asked for */
2114 length = widthBytesLine * height *
2115 Ones(planemask & (plane | (plane - 1)));
2116
2117 }
2118
2119 xgi.length = length;
2120
2121 xgi.length = bytes_to_int32(xgi.length);
2122 if (widthBytesLine == 0 || height == 0)
2123 linesPerBuf = 0;
2124 else if (widthBytesLine >= IMAGE_BUFSIZE(64*1024))
2125 linesPerBuf = 1;
2126 else {
2127 linesPerBuf = IMAGE_BUFSIZE(64*1024) / widthBytesLine;
2128 if (linesPerBuf > height)
2129 linesPerBuf = height;
2130 }
2131 length = linesPerBuf * widthBytesLine;
2132 if (linesPerBuf < height) {
2133 /* we have to make sure intermediate buffers don't need padding */
2134 while ((linesPerBuf > 1) &&
2135 (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD2) - 1))) {
2136 linesPerBuf--;
2137 length -= widthBytesLine;
2138 }
2139 while (length & ((1L << LOG2_BYTES_PER_SCANLINE_PAD2) - 1)) {
2140 linesPerBuf++;
2141 length += widthBytesLine;
2142 }
2143 }
2144 if (!(pBuf = calloc(1, length)))
2145 return BadAlloc11;
2146 WriteReplyToClient(client, sizeof(xGetImageReply), &xgi){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetImageReply
)), &xgi); else WriteToClient(client, (int)(sizeof(xGetImageReply
)), (&xgi)); }
;
2147
2148 if (pDraw->type == DRAWABLE_WINDOW0) {
2149 pVisibleRegion = NotClippedByChildren((WindowPtr) pDraw);
2150 if (pVisibleRegion) {
2151 RegionTranslate(pVisibleRegion, -pDraw->x, -pDraw->y);
2152 }
2153 }
2154
2155 if (linesPerBuf == 0) {
2156 /* nothing to do */
2157 }
2158 else if (format == ZPixmap2) {
2159 linesDone = 0;
2160 while (height - linesDone > 0) {
2161 nlines = min(linesPerBuf, height - linesDone)(((linesPerBuf) < (height - linesDone)) ? (linesPerBuf) : (
height - linesDone))
;
2162 (*pDraw->pScreen->GetImage) (pDraw,
2163 x,
2164 y + linesDone,
2165 width,
2166 nlines,
2167 format, planemask, (void *) pBuf);
2168 if (pVisibleRegion)
2169 XaceCensorImage(client, pVisibleRegion, widthBytesLine,
2170 pDraw, x, y + linesDone, width,
2171 nlines, format, pBuf);
2172
2173 /* Note that this is NOT a call to WriteSwappedDataToClient,
2174 as we do NOT byte swap */
2175 ReformatImage(pBuf, (int) (nlines * widthBytesLine),
2176 BitsPerPixel(pDraw->depth), ClientOrder(client));
2177
2178 WriteToClient(client, (int) (nlines * widthBytesLine), pBuf);
2179 linesDone += nlines;
2180 }
2181 }
2182 else { /* XYPixmap */
2183
2184 for (; plane; plane >>= 1) {
2185 if (planemask & plane) {
2186 linesDone = 0;
2187 while (height - linesDone > 0) {
2188 nlines = min(linesPerBuf, height - linesDone)(((linesPerBuf) < (height - linesDone)) ? (linesPerBuf) : (
height - linesDone))
;
2189 (*pDraw->pScreen->GetImage) (pDraw,
2190 x,
2191 y + linesDone,
2192 width,
2193 nlines,
2194 format, plane, (void *) pBuf);
2195 if (pVisibleRegion)
2196 XaceCensorImage(client, pVisibleRegion,
2197 widthBytesLine,
2198 pDraw, x, y + linesDone, width,
2199 nlines, format, pBuf);
2200
2201 /* Note: NOT a call to WriteSwappedDataToClient,
2202 as we do NOT byte swap */
2203 ReformatImage(pBuf, (int) (nlines * widthBytesLine),
2204 1, ClientOrder(client));
2205
2206 WriteToClient(client, (int)(nlines * widthBytesLine), pBuf);
2207 linesDone += nlines;
2208 }
2209 }
2210 }
2211 }
2212 if (pVisibleRegion)
2213 RegionDestroy(pVisibleRegion);
2214 free(pBuf);
2215 return Success0;
2216}
2217
2218int
2219ProcGetImage(ClientPtr client)
2220{
2221 REQUEST(xGetImageReq)xGetImageReq *stuff = (xGetImageReq *)client->requestBuffer;
2222
2223 REQUEST_SIZE_MATCH(xGetImageReq)if ((sizeof(xGetImageReq) >> 2) != client->req_len) return
(16)
;
2224
2225 return DoGetImage(client, stuff->format, stuff->drawable,
2226 stuff->x, stuff->y,
2227 (int) stuff->width, (int) stuff->height,
2228 stuff->planeMask);
2229}
2230
2231int
2232ProcPolyText(ClientPtr client)
2233{
2234 int err;
2235
2236 REQUEST(xPolyTextReq)xPolyTextReq *stuff = (xPolyTextReq *)client->requestBuffer;
2237 DrawablePtr pDraw;
2238 GC *pGC;
2239
2240 REQUEST_AT_LEAST_SIZE(xPolyTextReq)if ((sizeof(xPolyTextReq) >> 2) > client->req_len
) return(16)
;
2241 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
2242
2243 err = PolyText(client,
2244 pDraw,
2245 pGC,
2246 (unsigned char *) &stuff[1],
2247 ((unsigned char *) stuff) + (client->req_len << 2),
2248 stuff->x, stuff->y, stuff->reqType, stuff->drawable);
2249
2250 if (err == Success0) {
2251 return Success0;
2252 }
2253 else
2254 return err;
2255}
2256
2257int
2258ProcImageText8(ClientPtr client)
2259{
2260 int err;
2261 DrawablePtr pDraw;
2262 GC *pGC;
2263
2264 REQUEST(xImageTextReq)xImageTextReq *stuff = (xImageTextReq *)client->requestBuffer;
2265
2266 REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars)if (((sizeof(xImageTextReq) >> 2) > client->req_len
) || (((stuff->nChars) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xImageTextReq) + (stuff->nChars)
+ 3) >> 2) != (uint64_t) client->req_len)) return(16
)
;
2267 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
2268
2269 err = ImageText(client,
2270 pDraw,
2271 pGC,
2272 stuff->nChars,
2273 (unsigned char *) &stuff[1],
2274 stuff->x, stuff->y, stuff->reqType, stuff->drawable);
2275
2276 if (err == Success0) {
2277 return Success0;
2278 }
2279 else
2280 return err;
2281}
2282
2283int
2284ProcImageText16(ClientPtr client)
2285{
2286 int err;
2287 DrawablePtr pDraw;
2288 GC *pGC;
2289
2290 REQUEST(xImageTextReq)xImageTextReq *stuff = (xImageTextReq *)client->requestBuffer;
2291
2292 REQUEST_FIXED_SIZE(xImageTextReq, stuff->nChars << 1)if (((sizeof(xImageTextReq) >> 2) > client->req_len
) || (((stuff->nChars << 1) >> 2) >= client
->req_len) || ((((uint64_t) sizeof(xImageTextReq) + (stuff
->nChars << 1) + 3) >> 2) != (uint64_t) client
->req_len)) return(16)
;
2293 VALIDATE_DRAWABLE_AND_GC(stuff->drawable, pDraw, DixWriteAccess){ int tmprc = dixLookupDrawable(&(pDraw), stuff->drawable
, client, (-1), (1<<1)); if (tmprc != 0) return tmprc; tmprc
= dixLookupGC(&(pGC), stuff->gc, client, (1<<24
)); if (tmprc != 0) return tmprc; if ((pGC->depth != pDraw
->depth) || (pGC->pScreen != pDraw->pScreen)) return
8; } if (pGC->serialNumber != pDraw->serialNumber) ValidateGC
(pDraw, pGC);
;
2294
2295 err = ImageText(client,
2296 pDraw,
2297 pGC,
2298 stuff->nChars,
2299 (unsigned char *) &stuff[1],
2300 stuff->x, stuff->y, stuff->reqType, stuff->drawable);
2301
2302 if (err == Success0) {
2303 return Success0;
2304 }
2305 else
2306 return err;
2307}
2308
2309int
2310ProcCreateColormap(ClientPtr client)
2311{
2312 VisualPtr pVisual;
2313 ColormapPtr pmap;
2314 Colormap mid;
2315 WindowPtr pWin;
2316 ScreenPtr pScreen;
2317
2318 REQUEST(xCreateColormapReq)xCreateColormapReq *stuff = (xCreateColormapReq *)client->
requestBuffer
;
2319 int i, result;
2320
2321 REQUEST_SIZE_MATCH(xCreateColormapReq)if ((sizeof(xCreateColormapReq) >> 2) != client->req_len
) return(16)
;
2322
2323 if ((stuff->alloc != AllocNone0) && (stuff->alloc != AllocAll1)) {
2324 client->errorValue = stuff->alloc;
2325 return BadValue2;
2326 }
2327 mid = stuff->mid;
2328 LEGAL_NEW_RESOURCE(mid, client)if (!LegalNewID(mid,client)) { client->errorValue = mid; return
14; }
;
2329 result = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess(1<<4));
2330 if (result != Success0)
2331 return result;
2332
2333 pScreen = pWin->drawable.pScreen;
2334 for (i = 0, pVisual = pScreen->visuals;
2335 i < pScreen->numVisuals; i++, pVisual++) {
2336 if (pVisual->vid != stuff->visual)
2337 continue;
2338 return CreateColormap(mid, pScreen, pVisual, &pmap,
2339 (int) stuff->alloc, client->index);
2340 }
2341 client->errorValue = stuff->visual;
2342 return BadMatch8;
2343}
2344
2345int
2346ProcFreeColormap(ClientPtr client)
2347{
2348 ColormapPtr pmap;
2349 int rc;
2350
2351 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
2352
2353 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
2354 rc = dixLookupResourceByType((void **) &pmap, stuff->id, RT_COLORMAP((RESTYPE)6),
2355 client, DixDestroyAccess(1<<2));
2356 if (rc == Success0) {
2357 /* Freeing a default colormap is a no-op */
2358 if (!(pmap->flags & IsDefault1))
2359 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
2360 return Success0;
2361 }
2362 else {
2363 client->errorValue = stuff->id;
2364 return rc;
2365 }
2366}
2367
2368int
2369ProcCopyColormapAndFree(ClientPtr client)
2370{
2371 Colormap mid;
2372 ColormapPtr pSrcMap;
2373
2374 REQUEST(xCopyColormapAndFreeReq)xCopyColormapAndFreeReq *stuff = (xCopyColormapAndFreeReq *)client
->requestBuffer
;
2375 int rc;
2376
2377 REQUEST_SIZE_MATCH(xCopyColormapAndFreeReq)if ((sizeof(xCopyColormapAndFreeReq) >> 2) != client->
req_len) return(16)
;
2378 mid = stuff->mid;
2379 LEGAL_NEW_RESOURCE(mid, client)if (!LegalNewID(mid,client)) { client->errorValue = mid; return
14; }
;
2380 rc = dixLookupResourceByType((void **) &pSrcMap, stuff->srcCmap,
2381 RT_COLORMAP((RESTYPE)6), client,
2382 DixReadAccess(1<<0) | DixRemoveAccess(1<<13));
2383 if (rc == Success0)
2384 return CopyColormapAndFree(mid, pSrcMap, client->index);
2385 client->errorValue = stuff->srcCmap;
2386 return rc;
2387}
2388
2389int
2390ProcInstallColormap(ClientPtr client)
2391{
2392 ColormapPtr pcmp;
2393 int rc;
2394
2395 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
2396 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
2397
2398 rc = dixLookupResourceByType((void **) &pcmp, stuff->id, RT_COLORMAP((RESTYPE)6),
2399 client, DixInstallAccess(1<<20));
2400 if (rc != Success0)
2401 goto out;
2402
2403 rc = XaceHook(XACE_SCREEN_ACCESS11, client, pcmp->pScreen, DixSetAttrAccess(1<<5));
2404 if (rc != Success0) {
2405 if (rc == BadValue2)
2406 rc = BadColor12;
2407 goto out;
2408 }
2409
2410 (*(pcmp->pScreen->InstallColormap)) (pcmp);
2411 return Success0;
2412
2413 out:
2414 client->errorValue = stuff->id;
2415 return rc;
2416}
2417
2418int
2419ProcUninstallColormap(ClientPtr client)
2420{
2421 ColormapPtr pcmp;
2422 int rc;
2423
2424 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
2425 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
2426
2427 rc = dixLookupResourceByType((void **) &pcmp, stuff->id, RT_COLORMAP((RESTYPE)6),
2428 client, DixUninstallAccess(1<<21));
2429 if (rc != Success0)
2430 goto out;
2431
2432 rc = XaceHook(XACE_SCREEN_ACCESS11, client, pcmp->pScreen, DixSetAttrAccess(1<<5));
2433 if (rc != Success0) {
2434 if (rc == BadValue2)
2435 rc = BadColor12;
2436 goto out;
2437 }
2438
2439 if (pcmp->mid != pcmp->pScreen->defColormap)
2440 (*(pcmp->pScreen->UninstallColormap)) (pcmp);
2441 return Success0;
2442
2443 out:
2444 client->errorValue = stuff->id;
2445 return rc;
2446}
2447
2448int
2449ProcListInstalledColormaps(ClientPtr client)
2450{
2451 xListInstalledColormapsReply *preply;
2452 int nummaps, rc;
2453 WindowPtr pWin;
2454
2455 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
2456 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
2457
2458 rc = dixLookupWindow(&pWin, stuff->id, client, DixGetAttrAccess(1<<4));
2459 if (rc != Success0)
2460 return rc;
2461
2462 rc = XaceHook(XACE_SCREEN_ACCESS11, client, pWin->drawable.pScreen,
2463 DixGetAttrAccess(1<<4));
2464 if (rc != Success0)
2465 return rc;
2466
2467 preply = malloc(sizeof(xListInstalledColormapsReply) +
2468 pWin->drawable.pScreen->maxInstalledCmaps *
2469 sizeof(Colormap));
2470 if (!preply)
2471 return BadAlloc11;
2472
2473 preply->type = X_Reply1;
2474 preply->sequenceNumber = client->sequence;
2475 nummaps = (*pWin->drawable.pScreen->ListInstalledColormaps)
2476 (pWin->drawable.pScreen, (Colormap *) &preply[1]);
2477 preply->nColormaps = nummaps;
2478 preply->length = nummaps;
2479 WriteReplyToClient(client, sizeof(xListInstalledColormapsReply), preply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xListInstalledColormapsReply
)), preply); else WriteToClient(client, (int)(sizeof(xListInstalledColormapsReply
)), (preply)); }
;
2480 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2481 WriteSwappedDataToClient(client, nummaps * sizeof(Colormap), &preply[1])if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(nummaps * sizeof(Colormap)), &preply[1]); else WriteToClient
(client, (int)(nummaps * sizeof(Colormap)), (&preply[1]))
;
;
2482 free(preply);
2483 return Success0;
2484}
2485
2486int
2487ProcAllocColor(ClientPtr client)
2488{
2489 ColormapPtr pmap;
2490 int rc;
2491
2492 REQUEST(xAllocColorReq)xAllocColorReq *stuff = (xAllocColorReq *)client->requestBuffer;
2493
2494 REQUEST_SIZE_MATCH(xAllocColorReq)if ((sizeof(xAllocColorReq) >> 2) != client->req_len
) return(16)
;
2495 rc = dixLookupResourceByType((void **) &pmap, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2496 client, DixAddAccess(1<<12));
2497 if (rc == Success0) {
2498 xAllocColorReply acr = {
2499 .type = X_Reply1,
2500 .sequenceNumber = client->sequence,
2501 .length = 0,
2502 .red = stuff->red,
2503 .green = stuff->green,
2504 .blue = stuff->blue,
2505 .pixel = 0
2506 };
2507 if ((rc = AllocColor(pmap, &acr.red, &acr.green, &acr.blue,
2508 &acr.pixel, client->index)))
2509 return rc;
2510#ifdef PANORAMIX1
2511 if (noPanoramiXExtension || !pmap->pScreen->myNum)
2512#endif
2513 WriteReplyToClient(client, sizeof(xAllocColorReply), &acr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xAllocColorReply
)), &acr); else WriteToClient(client, (int)(sizeof(xAllocColorReply
)), (&acr)); }
;
2514 return Success0;
2515
2516 }
2517 else {
2518 client->errorValue = stuff->cmap;
2519 return rc;
2520 }
2521}
2522
2523int
2524ProcAllocNamedColor(ClientPtr client)
2525{
2526 ColormapPtr pcmp;
2527 int rc;
2528
2529 REQUEST(xAllocNamedColorReq)xAllocNamedColorReq *stuff = (xAllocNamedColorReq *)client->
requestBuffer
;
2530
2531 REQUEST_FIXED_SIZE(xAllocNamedColorReq, stuff->nbytes)if (((sizeof(xAllocNamedColorReq) >> 2) > client->
req_len) || (((stuff->nbytes) >> 2) >= client->
req_len) || ((((uint64_t) sizeof(xAllocNamedColorReq) + (stuff
->nbytes) + 3) >> 2) != (uint64_t) client->req_len
)) return(16)
;
2532 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2533 client, DixAddAccess(1<<12));
2534 if (rc == Success0) {
2535 xAllocNamedColorReply ancr = {
2536 .type = X_Reply1,
2537 .sequenceNumber = client->sequence,
2538 .length = 0
2539 };
2540 if (OsLookupColor
2541 (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
2542 &ancr.exactRed, &ancr.exactGreen, &ancr.exactBlue)) {
2543 ancr.screenRed = ancr.exactRed;
2544 ancr.screenGreen = ancr.exactGreen;
2545 ancr.screenBlue = ancr.exactBlue;
2546 ancr.pixel = 0;
2547 if ((rc = AllocColor(pcmp,
2548 &ancr.screenRed, &ancr.screenGreen,
2549 &ancr.screenBlue, &ancr.pixel, client->index)))
2550 return rc;
2551#ifdef PANORAMIX1
2552 if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2553#endif
2554 WriteReplyToClient(client, sizeof(xAllocNamedColorReply),{ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xAllocNamedColorReply
)), &ancr); else WriteToClient(client, (int)(sizeof(xAllocNamedColorReply
)), (&ancr)); }
2555 &ancr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xAllocNamedColorReply
)), &ancr); else WriteToClient(client, (int)(sizeof(xAllocNamedColorReply
)), (&ancr)); }
;
2556 return Success0;
2557 }
2558 else
2559 return BadName15;
2560
2561 }
2562 else {
2563 client->errorValue = stuff->cmap;
2564 return rc;
2565 }
2566}
2567
2568int
2569ProcAllocColorCells(ClientPtr client)
2570{
2571 ColormapPtr pcmp;
2572 int rc;
2573
2574 REQUEST(xAllocColorCellsReq)xAllocColorCellsReq *stuff = (xAllocColorCellsReq *)client->
requestBuffer
;
2575
2576 REQUEST_SIZE_MATCH(xAllocColorCellsReq)if ((sizeof(xAllocColorCellsReq) >> 2) != client->req_len
) return(16)
;
2577 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2578 client, DixAddAccess(1<<12));
2579 if (rc == Success0) {
2580 int npixels, nmasks;
2581 long length;
2582 Pixel *ppixels, *pmasks;
2583
2584 npixels = stuff->colors;
2585 if (!npixels) {
2586 client->errorValue = npixels;
2587 return BadValue2;
2588 }
2589 if (stuff->contiguous != xTrue1 && stuff->contiguous != xFalse0) {
2590 client->errorValue = stuff->contiguous;
2591 return BadValue2;
2592 }
2593 nmasks = stuff->planes;
2594 length = ((long) npixels + (long) nmasks) * sizeof(Pixel);
2595 ppixels = malloc(length);
2596 if (!ppixels)
2597 return BadAlloc11;
2598 pmasks = ppixels + npixels;
2599
2600 if ((rc = AllocColorCells(client->index, pcmp, npixels, nmasks,
2601 (Bool) stuff->contiguous, ppixels, pmasks))) {
2602 free(ppixels);
2603 return rc;
2604 }
2605#ifdef PANORAMIX1
2606 if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2607#endif
2608 {
2609 xAllocColorCellsReply accr = {
2610 .type = X_Reply1,
2611 .sequenceNumber = client->sequence,
2612 .length = bytes_to_int32(length),
2613 .nPixels = npixels,
2614 .nMasks = nmasks
2615 };
2616 WriteReplyToClient(client, sizeof(xAllocColorCellsReply), &accr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xAllocColorCellsReply
)), &accr); else WriteToClient(client, (int)(sizeof(xAllocColorCellsReply
)), (&accr)); }
;
2617 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2618 WriteSwappedDataToClient(client, length, ppixels)if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(length), ppixels); else WriteToClient(client, (int)(length
), (ppixels));
;
2619 }
2620 free(ppixels);
2621 return Success0;
2622 }
2623 else {
2624 client->errorValue = stuff->cmap;
2625 return rc;
2626 }
2627}
2628
2629int
2630ProcAllocColorPlanes(ClientPtr client)
2631{
2632 ColormapPtr pcmp;
2633 int rc;
2634
2635 REQUEST(xAllocColorPlanesReq)xAllocColorPlanesReq *stuff = (xAllocColorPlanesReq *)client->
requestBuffer
;
2636
2637 REQUEST_SIZE_MATCH(xAllocColorPlanesReq)if ((sizeof(xAllocColorPlanesReq) >> 2) != client->req_len
) return(16)
;
2638 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2639 client, DixAddAccess(1<<12));
2640 if (rc == Success0) {
2641 xAllocColorPlanesReply acpr;
2642 int npixels;
2643 long length;
2644 Pixel *ppixels;
2645
2646 npixels = stuff->colors;
2647 if (!npixels) {
2648 client->errorValue = npixels;
2649 return BadValue2;
2650 }
2651 if (stuff->contiguous != xTrue1 && stuff->contiguous != xFalse0) {
2652 client->errorValue = stuff->contiguous;
2653 return BadValue2;
2654 }
2655 acpr = (xAllocColorPlanesReply) {
2656 .type = X_Reply1,
2657 .sequenceNumber = client->sequence,
2658 .nPixels = npixels
2659 };
2660 length = (long) npixels *sizeof(Pixel);
2661
2662 ppixels = malloc(length);
2663 if (!ppixels)
2664 return BadAlloc11;
2665 if ((rc = AllocColorPlanes(client->index, pcmp, npixels,
2666 (int) stuff->red, (int) stuff->green,
2667 (int) stuff->blue, (Bool) stuff->contiguous,
2668 ppixels, &acpr.redMask, &acpr.greenMask,
2669 &acpr.blueMask))) {
2670 free(ppixels);
2671 return rc;
2672 }
2673 acpr.length = bytes_to_int32(length);
2674#ifdef PANORAMIX1
2675 if (noPanoramiXExtension || !pcmp->pScreen->myNum)
2676#endif
2677 {
2678 WriteReplyToClient(client, sizeof(xAllocColorPlanesReply), &acpr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xAllocColorPlanesReply
)), &acpr); else WriteToClient(client, (int)(sizeof(xAllocColorPlanesReply
)), (&acpr)); }
;
2679 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
2680 WriteSwappedDataToClient(client, length, ppixels)if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(length), ppixels); else WriteToClient(client, (int)(length
), (ppixels));
;
2681 }
2682 free(ppixels);
2683 return Success0;
2684 }
2685 else {
2686 client->errorValue = stuff->cmap;
2687 return rc;
2688 }
2689}
2690
2691int
2692ProcFreeColors(ClientPtr client)
2693{
2694 ColormapPtr pcmp;
2695 int rc;
2696
2697 REQUEST(xFreeColorsReq)xFreeColorsReq *stuff = (xFreeColorsReq *)client->requestBuffer;
2698
2699 REQUEST_AT_LEAST_SIZE(xFreeColorsReq)if ((sizeof(xFreeColorsReq) >> 2) > client->req_len
) return(16)
;
2700 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2701 client, DixRemoveAccess(1<<13));
2702 if (rc == Success0) {
2703 int count;
2704
2705 if (pcmp->flags & AllAllocated2)
2706 return BadAccess10;
2707 count = bytes_to_int32((client->req_len << 2) - sizeof(xFreeColorsReq));
2708 return FreeColors(pcmp, client->index, count,
2709 (Pixel *) &stuff[1], (Pixel) stuff->planeMask);
2710 }
2711 else {
2712 client->errorValue = stuff->cmap;
2713 return rc;
2714 }
2715}
2716
2717int
2718ProcStoreColors(ClientPtr client)
2719{
2720 ColormapPtr pcmp;
2721 int rc;
2722
2723 REQUEST(xStoreColorsReq)xStoreColorsReq *stuff = (xStoreColorsReq *)client->requestBuffer;
2724
2725 REQUEST_AT_LEAST_SIZE(xStoreColorsReq)if ((sizeof(xStoreColorsReq) >> 2) > client->req_len
) return(16)
;
2726 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2727 client, DixWriteAccess(1<<1));
2728 if (rc == Success0) {
2729 int count;
2730
2731 count = (client->req_len << 2) - sizeof(xStoreColorsReq);
2732 if (count % sizeof(xColorItem))
2733 return BadLength16;
2734 count /= sizeof(xColorItem);
2735 return StoreColors(pcmp, count, (xColorItem *) &stuff[1], client);
2736 }
2737 else {
2738 client->errorValue = stuff->cmap;
2739 return rc;
2740 }
2741}
2742
2743int
2744ProcStoreNamedColor(ClientPtr client)
2745{
2746 ColormapPtr pcmp;
2747 int rc;
2748
2749 REQUEST(xStoreNamedColorReq)xStoreNamedColorReq *stuff = (xStoreNamedColorReq *)client->
requestBuffer
;
2750
2751 REQUEST_FIXED_SIZE(xStoreNamedColorReq, stuff->nbytes)if (((sizeof(xStoreNamedColorReq) >> 2) > client->
req_len) || (((stuff->nbytes) >> 2) >= client->
req_len) || ((((uint64_t) sizeof(xStoreNamedColorReq) + (stuff
->nbytes) + 3) >> 2) != (uint64_t) client->req_len
)) return(16)
;
2752 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2753 client, DixWriteAccess(1<<1));
2754 if (rc == Success0) {
2755 xColorItem def;
2756
2757 if (OsLookupColor(pcmp->pScreen->myNum, (char *) &stuff[1],
2758 stuff->nbytes, &def.red, &def.green, &def.blue)) {
2759 def.flags = stuff->flags;
2760 def.pixel = stuff->pixel;
2761 return StoreColors(pcmp, 1, &def, client);
2762 }
2763 return BadName15;
2764 }
2765 else {
2766 client->errorValue = stuff->cmap;
2767 return rc;
2768 }
2769}
2770
2771int
2772ProcQueryColors(ClientPtr client)
2773{
2774 ColormapPtr pcmp;
2775 int rc;
2776
2777 REQUEST(xQueryColorsReq)xQueryColorsReq *stuff = (xQueryColorsReq *)client->requestBuffer;
2778
2779 REQUEST_AT_LEAST_SIZE(xQueryColorsReq)if ((sizeof(xQueryColorsReq) >> 2) > client->req_len
) return(16)
;
2780 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2781 client, DixReadAccess(1<<0));
2782 if (rc == Success0) {
2783 int count;
2784 xrgb *prgbs;
2785 xQueryColorsReply qcr;
2786
2787 count =
2788 bytes_to_int32((client->req_len << 2) - sizeof(xQueryColorsReq));
2789 prgbs = calloc(1, count * sizeof(xrgb));
2790 if (!prgbs && count)
2791 return BadAlloc11;
2792 if ((rc =
2793 QueryColors(pcmp, count, (Pixel *) &stuff[1], prgbs, client))) {
2794 free(prgbs);
2795 return rc;
2796 }
2797 qcr = (xQueryColorsReply) {
2798 .type = X_Reply1,
2799 .sequenceNumber = client->sequence,
2800 .length = bytes_to_int32(count * sizeof(xrgb)),
2801 .nColors = count
2802 };
2803 WriteReplyToClient(client, sizeof(xQueryColorsReply), &qcr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xQueryColorsReply
)), &qcr); else WriteToClient(client, (int)(sizeof(xQueryColorsReply
)), (&qcr)); }
;
2804 if (count) {
2805 client->pSwapReplyFunc = (ReplySwapPtr) SQColorsExtend;
2806 WriteSwappedDataToClient(client, count * sizeof(xrgb), prgbs)if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(count * sizeof(xrgb)), prgbs); else WriteToClient(client
, (int)(count * sizeof(xrgb)), (prgbs));
;
2807 }
2808 free(prgbs);
2809 return Success0;
2810
2811 }
2812 else {
2813 client->errorValue = stuff->cmap;
2814 return rc;
2815 }
2816}
2817
2818int
2819ProcLookupColor(ClientPtr client)
2820{
2821 ColormapPtr pcmp;
2822 int rc;
2823
2824 REQUEST(xLookupColorReq)xLookupColorReq *stuff = (xLookupColorReq *)client->requestBuffer;
2825
2826 REQUEST_FIXED_SIZE(xLookupColorReq, stuff->nbytes)if (((sizeof(xLookupColorReq) >> 2) > client->req_len
) || (((stuff->nbytes) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xLookupColorReq) + (stuff->nbytes
) + 3) >> 2) != (uint64_t) client->req_len)) return(
16)
;
2827 rc = dixLookupResourceByType((void **) &pcmp, stuff->cmap, RT_COLORMAP((RESTYPE)6),
2828 client, DixReadAccess(1<<0));
2829 if (rc == Success0) {
2830 CARD16 exactRed, exactGreen, exactBlue;
2831
2832 if (OsLookupColor
2833 (pcmp->pScreen->myNum, (char *) &stuff[1], stuff->nbytes,
2834 &exactRed, &exactGreen, &exactBlue)) {
2835 xLookupColorReply lcr = {
2836 .type = X_Reply1,
2837 .sequenceNumber = client->sequence,
2838 .length = 0,
2839 .exactRed = exactRed,
2840 .exactGreen = exactGreen,
2841 .exactBlue = exactBlue,
2842 .screenRed = exactRed,
2843 .screenGreen = exactGreen,
2844 .screenBlue = exactBlue
2845 };
2846 (*pcmp->pScreen->ResolveColor) (&lcr.screenRed,
2847 &lcr.screenGreen,
2848 &lcr.screenBlue, pcmp->pVisual);
2849 WriteReplyToClient(client, sizeof(xLookupColorReply), &lcr){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xLookupColorReply
)), &lcr); else WriteToClient(client, (int)(sizeof(xLookupColorReply
)), (&lcr)); }
;
2850 return Success0;
2851 }
2852 return BadName15;
2853 }
2854 else {
2855 client->errorValue = stuff->cmap;
2856 return rc;
2857 }
2858}
2859
2860int
2861ProcCreateCursor(ClientPtr client)
2862{
2863 CursorPtr pCursor;
2864 PixmapPtr src;
2865 PixmapPtr msk;
2866 unsigned char *srcbits;
2867 unsigned char *mskbits;
2868 unsigned short width, height;
2869 long n;
2870 CursorMetricRec cm;
2871 int rc;
2872
2873 REQUEST(xCreateCursorReq)xCreateCursorReq *stuff = (xCreateCursorReq *)client->requestBuffer;
2874
2875 REQUEST_SIZE_MATCH(xCreateCursorReq)if ((sizeof(xCreateCursorReq) >> 2) != client->req_len
) return(16)
;
2876 LEGAL_NEW_RESOURCE(stuff->cid, client)if (!LegalNewID(stuff->cid,client)) { client->errorValue
= stuff->cid; return 14; }
;
2877
2878 rc = dixLookupResourceByType((void **) &src, stuff->source, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)),
2879 client, DixReadAccess(1<<0));
2880 if (rc != Success0) {
2881 client->errorValue = stuff->source;
2882 return rc;
2883 }
2884
2885 if (src->drawable.depth != 1)
2886 return (BadMatch8);
2887
2888 /* Find and validate cursor mask pixmap, if one is provided */
2889 if (stuff->mask != None0L) {
2890 rc = dixLookupResourceByType((void **) &msk, stuff->mask, RT_PIXMAP((RESTYPE)2|((RESTYPE)1<<30)),
2891 client, DixReadAccess(1<<0));
2892 if (rc != Success0) {
2893 client->errorValue = stuff->mask;
2894 return rc;
2895 }
2896
2897 if (src->drawable.width != msk->drawable.width
2898 || src->drawable.height != msk->drawable.height
2899 || src->drawable.depth != 1 || msk->drawable.depth != 1)
2900 return BadMatch8;
2901 }
2902 else
2903 msk = NULL((void*)0);
2904
2905 width = src->drawable.width;
2906 height = src->drawable.height;
2907
2908 if (stuff->x > width || stuff->y > height)
2909 return BadMatch8;
2910
2911 n = BitmapBytePad(width)(((int)((width) + 32 - 1) >> 5) << 2) * height;
2912 srcbits = calloc(1, n);
2913 if (!srcbits)
2914 return BadAlloc11;
2915 mskbits = malloc(n);
2916 if (!mskbits) {
2917 free(srcbits);
2918 return BadAlloc11;
2919 }
2920
2921 (*src->drawable.pScreen->GetImage) ((DrawablePtr) src, 0, 0, width, height,
2922 XYPixmap1, 1, (void *) srcbits);
2923 if (msk == (PixmapPtr) NULL((void*)0)) {
2924 unsigned char *bits = mskbits;
2925
2926 while (--n >= 0)
2927 *bits++ = ~0;
2928 }
2929 else {
2930 /* zeroing the (pad) bits helps some ddx cursor handling */
2931 memset((char *) mskbits, 0, n)__builtin___memset_chk ((char *) mskbits, 0, n, __builtin_object_size
((char *) mskbits, 0))
;
2932 (*msk->drawable.pScreen->GetImage) ((DrawablePtr) msk, 0, 0, width,
2933 height, XYPixmap1, 1,
2934 (void *) mskbits);
2935 }
2936 cm.width = width;
2937 cm.height = height;
2938 cm.xhot = stuff->x;
2939 cm.yhot = stuff->y;
2940 rc = AllocARGBCursor(srcbits, mskbits, NULL((void*)0), &cm,
2941 stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
2942 stuff->backRed, stuff->backGreen, stuff->backBlue,
2943 &pCursor, client, stuff->cid);
2944
2945 if (rc != Success0)
2946 goto bail;
2947 if (!AddResourceDarwin_X_AddResource(stuff->cid, RT_CURSOR((RESTYPE)5), (void *) pCursor)) {
2948 rc = BadAlloc11;
2949 goto bail;
2950 }
2951
2952 return Success0;
2953 bail:
2954 free(srcbits);
2955 free(mskbits);
2956 return rc;
2957}
2958
2959int
2960ProcCreateGlyphCursor(ClientPtr client)
2961{
2962 CursorPtr pCursor;
2963 int res;
2964
2965 REQUEST(xCreateGlyphCursorReq)xCreateGlyphCursorReq *stuff = (xCreateGlyphCursorReq *)client
->requestBuffer
;
2966
2967 REQUEST_SIZE_MATCH(xCreateGlyphCursorReq)if ((sizeof(xCreateGlyphCursorReq) >> 2) != client->
req_len) return(16)
;
2968 LEGAL_NEW_RESOURCE(stuff->cid, client)if (!LegalNewID(stuff->cid,client)) { client->errorValue
= stuff->cid; return 14; }
;
2969
2970 res = AllocGlyphCursor(stuff->source, stuff->sourceChar,
2971 stuff->mask, stuff->maskChar,
2972 stuff->foreRed, stuff->foreGreen, stuff->foreBlue,
2973 stuff->backRed, stuff->backGreen, stuff->backBlue,
2974 &pCursor, client, stuff->cid);
2975 if (res != Success0)
2976 return res;
2977 if (AddResourceDarwin_X_AddResource(stuff->cid, RT_CURSOR((RESTYPE)5), (void *) pCursor))
2978 return Success0;
2979 return BadAlloc11;
2980}
2981
2982int
2983ProcFreeCursor(ClientPtr client)
2984{
2985 CursorPtr pCursor;
2986 int rc;
2987
2988 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
2989
2990 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
2991 rc = dixLookupResourceByType((void **) &pCursor, stuff->id, RT_CURSOR((RESTYPE)5),
2992 client, DixDestroyAccess(1<<2));
2993 if (rc == Success0) {
2994 FreeResource(stuff->id, RT_NONE((RESTYPE)0));
2995 return Success0;
2996 }
2997 else {
2998 client->errorValue = stuff->id;
2999 return rc;
3000 }
3001}
3002
3003int
3004ProcQueryBestSize(ClientPtr client)
3005{
3006 xQueryBestSizeReply reply;
3007 DrawablePtr pDraw;
3008 ScreenPtr pScreen;
3009 int rc;
3010
3011 REQUEST(xQueryBestSizeReq)xQueryBestSizeReq *stuff = (xQueryBestSizeReq *)client->requestBuffer;
3012 REQUEST_SIZE_MATCH(xQueryBestSizeReq)if ((sizeof(xQueryBestSizeReq) >> 2) != client->req_len
) return(16)
;
3013
3014 if ((stuff->class != CursorShape0) &&
3015 (stuff->class != TileShape1) && (stuff->class != StippleShape2)) {
3016 client->errorValue = stuff->class;
3017 return BadValue2;
3018 }
3019
3020 rc = dixLookupDrawable(&pDraw, stuff->drawable, client, M_ANY(-1),
3021 DixGetAttrAccess(1<<4));
3022 if (rc != Success0)
3023 return rc;
3024 if (stuff->class != CursorShape0 && pDraw->type == UNDRAWABLE_WINDOW2)
3025 return BadMatch8;
3026 pScreen = pDraw->pScreen;
3027 rc = XaceHook(XACE_SCREEN_ACCESS11, client, pScreen, DixGetAttrAccess(1<<4));
3028 if (rc != Success0)
3029 return rc;
3030 (*pScreen->QueryBestSize) (stuff->class, &stuff->width,
3031 &stuff->height, pScreen);
3032 reply = (xQueryBestSizeReply) {
3033 .type = X_Reply1,
3034 .sequenceNumber = client->sequence,
3035 .length = 0,
3036 .width = stuff->width,
3037 .height = stuff->height
3038 };
3039 WriteReplyToClient(client, sizeof(xQueryBestSizeReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xQueryBestSizeReply
)), &reply); else WriteToClient(client, (int)(sizeof(xQueryBestSizeReply
)), (&reply)); }
;
3040 return Success0;
3041}
3042
3043int
3044ProcSetScreenSaver(ClientPtr client)
3045{
3046 int rc, i, blankingOption, exposureOption;
3047
3048 REQUEST(xSetScreenSaverReq)xSetScreenSaverReq *stuff = (xSetScreenSaverReq *)client->
requestBuffer
;
3049 REQUEST_SIZE_MATCH(xSetScreenSaverReq)if ((sizeof(xSetScreenSaverReq) >> 2) != client->req_len
) return(16)
;
3050
3051 for (i = 0; i < screenInfo.numScreens; i++) {
3052 rc = XaceHook(XACE_SCREENSAVER_ACCESS12, client, screenInfo.screens[i],
3053 DixSetAttrAccess(1<<5));
3054 if (rc != Success0)
3055 return rc;
3056 }
3057
3058 blankingOption = stuff->preferBlank;
3059 if ((blankingOption != DontPreferBlanking0) &&
3060 (blankingOption != PreferBlanking1) &&
3061 (blankingOption != DefaultBlanking2)) {
3062 client->errorValue = blankingOption;
3063 return BadValue2;
3064 }
3065 exposureOption = stuff->allowExpose;
3066 if ((exposureOption != DontAllowExposures0) &&
3067 (exposureOption != AllowExposures1) &&
3068 (exposureOption != DefaultExposures2)) {
3069 client->errorValue = exposureOption;
3070 return BadValue2;
3071 }
3072 if (stuff->timeout < -1) {
3073 client->errorValue = stuff->timeout;
3074 return BadValue2;
3075 }
3076 if (stuff->interval < -1) {
3077 client->errorValue = stuff->interval;
3078 return BadValue2;
3079 }
3080
3081 if (blankingOption == DefaultBlanking2)
3082 ScreenSaverBlanking = defaultScreenSaverBlanking;
3083 else
3084 ScreenSaverBlanking = blankingOption;
3085 if (exposureOption == DefaultExposures2)
3086 ScreenSaverAllowExposures = defaultScreenSaverAllowExposures;
3087 else
3088 ScreenSaverAllowExposures = exposureOption;
3089
3090 if (stuff->timeout >= 0)
3091 ScreenSaverTime = stuff->timeout * MILLI_PER_SECOND(1000);
3092 else
3093 ScreenSaverTime = defaultScreenSaverTime;
3094 if (stuff->interval >= 0)
3095 ScreenSaverInterval = stuff->interval * MILLI_PER_SECOND(1000);
3096 else
3097 ScreenSaverInterval = defaultScreenSaverInterval;
3098
3099 SetScreenSaverTimer();
3100 return Success0;
3101}
3102
3103int
3104ProcGetScreenSaver(ClientPtr client)
3105{
3106 xGetScreenSaverReply rep;
3107 int rc, i;
3108
3109 REQUEST_SIZE_MATCH(xReq)if ((sizeof(xReq) >> 2) != client->req_len) return(16
)
;
3110
3111 for (i = 0; i < screenInfo.numScreens; i++) {
3112 rc = XaceHook(XACE_SCREENSAVER_ACCESS12, client, screenInfo.screens[i],
3113 DixGetAttrAccess(1<<4));
3114 if (rc != Success0)
3115 return rc;
3116 }
3117
3118 rep = (xGetScreenSaverReply) {
3119 .type = X_Reply1,
3120 .sequenceNumber = client->sequence,
3121 .length = 0,
3122 .timeout = ScreenSaverTime / MILLI_PER_SECOND(1000),
3123 .interval = ScreenSaverInterval / MILLI_PER_SECOND(1000),
3124 .preferBlanking = ScreenSaverBlanking,
3125 .allowExposures = ScreenSaverAllowExposures
3126 };
3127 WriteReplyToClient(client, sizeof(xGetScreenSaverReply), &rep){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetScreenSaverReply
)), &rep); else WriteToClient(client, (int)(sizeof(xGetScreenSaverReply
)), (&rep)); }
;
3128 return Success0;
3129}
3130
3131int
3132ProcChangeHosts(ClientPtr client)
3133{
3134 REQUEST(xChangeHostsReq)xChangeHostsReq *stuff = (xChangeHostsReq *)client->requestBuffer;
3135
3136 REQUEST_FIXED_SIZE(xChangeHostsReq, stuff->hostLength)if (((sizeof(xChangeHostsReq) >> 2) > client->req_len
) || (((stuff->hostLength) >> 2) >= client->req_len
) || ((((uint64_t) sizeof(xChangeHostsReq) + (stuff->hostLength
) + 3) >> 2) != (uint64_t) client->req_len)) return(
16)
;
3137
3138 if (stuff->mode == HostInsert0)
3139 return AddHost(client, (int) stuff->hostFamily,
3140 stuff->hostLength, (void *) &stuff[1]);
3141 if (stuff->mode == HostDelete1)
3142 return RemoveHost(client, (int) stuff->hostFamily,
3143 stuff->hostLength, (void *) &stuff[1]);
3144 client->errorValue = stuff->mode;
3145 return BadValue2;
3146}
3147
3148int
3149ProcListHosts(ClientPtr client)
3150{
3151 xListHostsReply reply;
3152 int len, nHosts, result;
3153 BOOL enabled;
3154 void *pdata;
3155
3156 /* REQUEST(xListHostsReq); */
3157
3158 REQUEST_SIZE_MATCH(xListHostsReq)if ((sizeof(xListHostsReq) >> 2) != client->req_len)
return(16)
;
3159
3160 /* untrusted clients can't list hosts */
3161 result = XaceHook(XACE_SERVER_ACCESS9, client, DixReadAccess(1<<0));
3162 if (result != Success0)
3163 return result;
3164
3165 result = GetHosts(&pdata, &nHosts, &len, &enabled);
3166 if (result != Success0)
3167 return result;
3168
3169 reply = (xListHostsReply) {
3170 .type = X_Reply1,
3171 .enabled = enabled,
3172 .sequenceNumber = client->sequence,
3173 .length = bytes_to_int32(len),
3174 .nHosts = nHosts
3175 };
3176 WriteReplyToClient(client, sizeof(xListHostsReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xListHostsReply
)), &reply); else WriteToClient(client, (int)(sizeof(xListHostsReply
)), (&reply)); }
;
3177 if (nHosts) {
3178 client->pSwapReplyFunc = (ReplySwapPtr) SLHostsExtend;
3179 WriteSwappedDataToClient(client, len, pdata)if ((client)->swapped) (*(client)->pSwapReplyFunc)(client
, (int)(len), pdata); else WriteToClient(client, (int)(len), (
pdata));
;
3180 }
3181 free(pdata);
3182 return Success0;
3183}
3184
3185int
3186ProcChangeAccessControl(ClientPtr client)
3187{
3188 REQUEST(xSetAccessControlReq)xSetAccessControlReq *stuff = (xSetAccessControlReq *)client->
requestBuffer
;
3189
3190 REQUEST_SIZE_MATCH(xSetAccessControlReq)if ((sizeof(xSetAccessControlReq) >> 2) != client->req_len
) return(16)
;
3191 if ((stuff->mode != EnableAccess1) && (stuff->mode != DisableAccess0)) {
3192 client->errorValue = stuff->mode;
3193 return BadValue2;
3194 }
3195 return ChangeAccessControl(client, stuff->mode == EnableAccess1);
3196}
3197
3198/*********************
3199 * CloseDownRetainedResources
3200 *
3201 * Find all clients that are gone and have terminated in RetainTemporary
3202 * and destroy their resources.
3203 *********************/
3204
3205static void
3206CloseDownRetainedResources(void)
3207{
3208 int i;
3209 ClientPtr client;
3210
3211 for (i = 1; i < currentMaxClients; i++) {
3212 client = clients[i];
3213 if (client && (client->closeDownMode == RetainTemporary2)
3214 && (client->clientGone))
3215 CloseDownClient(client);
3216 }
3217}
3218
3219int
3220ProcKillClient(ClientPtr client)
3221{
3222 REQUEST(xResourceReq)xResourceReq *stuff = (xResourceReq *)client->requestBuffer;
3223 ClientPtr killclient;
3224 int rc;
3225
3226 REQUEST_SIZE_MATCH(xResourceReq)if ((sizeof(xResourceReq) >> 2) != client->req_len) return
(16)
;
3227 if (stuff->id == AllTemporary0L) {
3228 CloseDownRetainedResources();
3229 return Success0;
3230 }
3231
3232 rc = dixLookupClient(&killclient, stuff->id, client, DixDestroyAccess(1<<2));
3233 if (rc == Success0) {
3234 CloseDownClient(killclient);
3235 if (client == killclient) {
3236 /* force yield and return Success, so that Dispatch()
3237 * doesn't try to touch client
3238 */
3239 isItTimeToYield = TRUE1;
3240 }
3241 return Success0;
3242 }
3243 else
3244 return rc;
3245}
3246
3247int
3248ProcSetFontPath(ClientPtr client)
3249{
3250 unsigned char *ptr;
3251 unsigned long nbytes, total;
3252 long nfonts;
3253 int n;
3254
3255 REQUEST(xSetFontPathReq)xSetFontPathReq *stuff = (xSetFontPathReq *)client->requestBuffer;
3256
3257 REQUEST_AT_LEAST_SIZE(xSetFontPathReq)if ((sizeof(xSetFontPathReq) >> 2) > client->req_len
) return(16)
;
3258
3259 nbytes = (client->req_len << 2) - sizeof(xSetFontPathReq);
3260 total = nbytes;
3261 ptr = (unsigned char *) &stuff[1];
3262 nfonts = stuff->nFonts;
3263 while (--nfonts >= 0) {
3264 if ((total == 0) || (total < (n = (*ptr + 1))))
3265 return BadLength16;
3266 total -= n;
3267 ptr += n;
3268 }
3269 if (total >= 4)
3270 return BadLength16;
3271 return SetFontPath(client, stuff->nFonts, (unsigned char *) &stuff[1]);
3272}
3273
3274int
3275ProcGetFontPath(ClientPtr client)
3276{
3277 xGetFontPathReply reply;
3278 int rc, stringLens, numpaths;
3279 unsigned char *bufferStart;
3280
3281 /* REQUEST (xReq); */
3282
3283 REQUEST_SIZE_MATCH(xReq)if ((sizeof(xReq) >> 2) != client->req_len) return(16
)
;
3284 rc = GetFontPath(client, &numpaths, &stringLens, &bufferStart);
3285 if (rc != Success0)
3286 return rc;
3287
3288 reply = (xGetFontPathReply) {
3289 .type = X_Reply1,
3290 .sequenceNumber = client->sequence,
3291 .length = bytes_to_int32(stringLens + numpaths),
3292 .nPaths = numpaths
3293 };
3294
3295 WriteReplyToClient(client, sizeof(xGetFontPathReply), &reply){ if ((client)->swapped) (*ReplySwapVector[((xReq *)(client
)->requestBuffer)->reqType]) (client, (int)(sizeof(xGetFontPathReply
)), &reply); else WriteToClient(client, (int)(sizeof(xGetFontPathReply
)), (&reply)); }
;
3296 if (stringLens || numpaths)
3297 WriteToClient(client, stringLens + numpaths, bufferStart);
3298 return Success0;
3299}
3300
3301int
3302ProcChangeCloseDownMode(ClientPtr client)
3303{
3304 int rc;
3305
3306 REQUEST(xSetCloseDownModeReq)xSetCloseDownModeReq *stuff = (xSetCloseDownModeReq *)client->
requestBuffer
;
3307 REQUEST_SIZE_MATCH(xSetCloseDownModeReq)if ((sizeof(xSetCloseDownModeReq) >> 2) != client->req_len
) return(16)
;
3308
3309 rc = XaceHook(XACE_CLIENT_ACCESS7, client, client, DixManageAccess(1<<25));
3310 if (rc != Success0)
3311 return rc;
3312
3313 if ((stuff->mode == AllTemporary0L) ||
3314 (stuff->mode == RetainPermanent1) || (stuff->mode == RetainTemporary2)) {
3315 client->closeDownMode = stuff->mode;
3316 return Success0;
3317 }
3318 else {
3319 client->errorValue = stuff->mode;
3320 return BadValue2;
3321 }
3322}
3323
3324int
3325ProcForceScreenSaver(ClientPtr client)
3326{
3327 int rc;
3328
3329 REQUEST(xForceScreenSaverReq)xForceScreenSaverReq *stuff = (xForceScreenSaverReq *)client->
requestBuffer
;
3330
3331 REQUEST_SIZE_MATCH(xForceScreenSaverReq)if ((sizeof(xForceScreenSaverReq) >> 2) != client->req_len
) return(16)
;
3332
3333 if ((stuff->mode != ScreenSaverReset0) && (stuff->mode != ScreenSaverActive1)) {
3334 client->errorValue = stuff->mode;
3335 return BadValue2;
3336 }
3337 rc = dixSaveScreens(client, SCREEN_SAVER_FORCER2, (int) stuff->mode);
3338 if (rc != Success0)
3339 return rc;
3340 return Success0;
3341}
3342
3343int
3344ProcNoOperation(ClientPtr client)
3345{
3346 REQUEST_AT_LEAST_SIZE(xReq)if ((sizeof(xReq) >> 2) > client->req_len ) return
(16)
;
3347
3348 /* noop -- don't do anything */
3349 return Success0;
3350}
3351
3352/**********************
3353 * CloseDownClient
3354 *
3355 * Client can either mark his resources destroy or retain. If retained and
3356 * then killed again, the client is really destroyed.
3357 *********************/
3358
3359char dispatchExceptionAtReset = DE_RESET1;
3360
3361void
3362CloseDownClient(ClientPtr client)
3363{
3364 Bool really_close_down = client->clientGone ||
3365 client->closeDownMode == DestroyAll0;
3366
3367 if (!client->clientGone) {
3368 /* ungrab server if grabbing client dies */
3369 if (grabState != GrabNone0 && grabClient == client) {
3370 UngrabServer(client);
3371 }
3372 BITCLEAR(grabWaiters, client->index)grabWaiters[((client->index) >> 5)] &= ~(1U <<
((client->index) & 31))
;
3373 DeleteClientFromAnySelections(client);
3374 ReleaseActiveGrabs(client);
3375 DeleteClientFontStuff(client);
3376 if (!really_close_down) {
3377 /* This frees resources that should never be retained
3378 * no matter what the close down mode is. Actually we
3379 * could do this unconditionally, but it's probably
3380 * better not to traverse all the client's resources
3381 * twice (once here, once a few lines down in
3382 * FreeClientResources) in the common case of
3383 * really_close_down == TRUE.
3384 */
3385 FreeClientNeverRetainResources(client);
3386 client->clientState = ClientStateRetained;
3387 if (ClientStateCallback) {
3388 NewClientInfoRec clientinfo;
3389
3390 clientinfo.client = client;
3391 clientinfo.prefix = (xConnSetupPrefix *) NULL((void*)0);
3392 clientinfo.setup = (xConnSetup *) NULL((void*)0);
3393 CallCallbacks((&ClientStateCallback), (void *) &clientinfo);
3394 }
3395 }
3396 client->clientGone = TRUE1; /* so events aren't sent to client */
3397 if (ClientIsAsleep(client))
3398 ClientSignal(client);
3399 ProcessWorkQueueZombies();
3400 CloseDownConnection(client);
3401
3402 /* If the client made it to the Running stage, nClients has
3403 * been incremented on its behalf, so we need to decrement it
3404 * now. If it hasn't gotten to Running, nClients has *not*
3405 * been incremented, so *don't* decrement it.
3406 */
3407 if (client->clientState != ClientStateInitial) {
3408 --nClients;
3409 }
3410 }
3411
3412 if (really_close_down) {
3413 if (client->clientState == ClientStateRunning && nClients == 0)
3414 dispatchException |= dispatchExceptionAtReset;
3415
3416 client->clientState = ClientStateGone;
3417 if (ClientStateCallback) {
3418 NewClientInfoRec clientinfo;
3419
3420 clientinfo.client = client;
3421 clientinfo.prefix = (xConnSetupPrefix *) NULL((void*)0);
3422 clientinfo.setup = (xConnSetup *) NULL((void*)0);
3423 CallCallbacks((&ClientStateCallback), (void *) &clientinfo);
3424 }
3425 TouchListenerGone(client->clientAsMask);
3426 FreeClientResources(client);
3427 /* Disable client ID tracking. This must be done after
3428 * ClientStateCallback. */
3429 ReleaseClientIds(client);
3430#ifdef XSERVER_DTRACE1
3431 XSERVER_CLIENT_DISCONNECT(client->index)do { __asm__ volatile(".reference " "___dtrace_typedefs$Xserver$v2$636f6e73745f646f75626c655f70$636f6e73745f75696e74385f70"
); __dtrace_probe$Xserver$client__disconnect$v1$696e74(client
->index); __asm__ volatile(".reference " "___dtrace_stability$Xserver$v1$4_4_5_1_1_0_1_1_0_4_4_5_4_4_5"
); } while (0)
;
3432#endif
3433 if (client->index < nextFreeClientID)
3434 nextFreeClientID = client->index;
3435 clients[client->index] = NullClient((ClientPtr) 0);
3436 SmartLastClient = NullClient((ClientPtr) 0);
3437 dixFreeObjectWithPrivates(client, PRIVATE_CLIENT)_dixFreeObjectWithPrivates(client, (client)->devPrivates, PRIVATE_CLIENT
)
;
3438
3439 while (!clients[currentMaxClients - 1])
3440 currentMaxClients--;
3441 }
3442}
3443
3444static void
3445KillAllClients(void)
3446{
3447 int i;
3448
3449 for (i = 1; i < currentMaxClients; i++)
3450 if (clients[i]) {
3451 /* Make sure Retained clients are released. */
3452 clients[i]->closeDownMode = DestroyAll0;
3453 CloseDownClient(clients[i]);
3454 }
3455}
3456
3457void
3458InitClient(ClientPtr client, int i, void *ospriv)
3459{
3460 client->index = i;
3461 client->clientAsMask = ((Mask) i) << CLIENTOFFSET(29 - 8);
3462 client->closeDownMode = i ? DestroyAll0 : RetainPermanent1;
3463 client->requestVector = InitialVector;
3464 client->osPrivate = ospriv;
3465 QueryMinMaxKeyCodes(&client->minKC, &client->maxKC);
3466 client->smart_start_tick = SmartScheduleTime;
3467 client->smart_stop_tick = SmartScheduleTime;
3468 client->clientIds = NULL((void*)0);
3469}
3470
3471/************************
3472 * int NextAvailableClient(ospriv)
3473 *
3474 * OS dependent portion can't assign client id's because of CloseDownModes.
3475 * Returns NULL if there are no free clients.
3476 *************************/
3477
3478ClientPtr
3479NextAvailableClient(void *ospriv)
3480{
3481 int i;
3482 ClientPtr client;
3483 xReq data;
3484
3485 i = nextFreeClientID;
3486 if (i == MAXCLIENTS256)
3487 return (ClientPtr) NULL((void*)0);
3488 clients[i] = client =
3489 dixAllocateObjectWithPrivates(ClientRec, PRIVATE_CLIENT)(ClientRec *) _dixAllocateObjectWithPrivates(sizeof(ClientRec
), sizeof(ClientRec), __builtin_offsetof(ClientRec, devPrivates
), PRIVATE_CLIENT)
;
3490 if (!client)
3491 return (ClientPtr) NULL((void*)0);
3492 InitClient(client, i, ospriv);
3493 if (!InitClientResources(client)) {
3494 dixFreeObjectWithPrivates(client, PRIVATE_CLIENT)_dixFreeObjectWithPrivates(client, (client)->devPrivates, PRIVATE_CLIENT
)
;
3495 return (ClientPtr) NULL((void*)0);
3496 }
3497 data.reqType = 1;
3498 data.length = bytes_to_int32(sz_xReq4 + sz_xConnClientPrefix12);
3499 if (!InsertFakeRequest(client, (char *) &data, sz_xReq4)) {
3500 FreeClientResources(client);
3501 dixFreeObjectWithPrivates(client, PRIVATE_CLIENT)_dixFreeObjectWithPrivates(client, (client)->devPrivates, PRIVATE_CLIENT
)
;
3502 return (ClientPtr) NULL((void*)0);
3503 }
3504 if (i == currentMaxClients)
3505 currentMaxClients++;
3506 while ((nextFreeClientID < MAXCLIENTS256) && clients[nextFreeClientID])
3507 nextFreeClientID++;
3508
3509 /* Enable client ID tracking. This must be done before
3510 * ClientStateCallback. */
3511 ReserveClientIds(client);
3512
3513 if (ClientStateCallback) {
3514 NewClientInfoRec clientinfo;
3515
3516 clientinfo.client = client;
3517 clientinfo.prefix = (xConnSetupPrefix *) NULL((void*)0);
3518 clientinfo.setup = (xConnSetup *) NULL((void*)0);
3519 CallCallbacks((&ClientStateCallback), (void *) &clientinfo);
3520 }
3521 return client;
3522}
3523
3524int
3525ProcInitialConnection(ClientPtr client)
3526{
3527 REQUEST(xReq)xReq *stuff = (xReq *)client->requestBuffer;
3528 xConnClientPrefix *prefix;
3529 int whichbyte = 1;
3530 char order;
3531
3532 prefix = (xConnClientPrefix *) ((char *)stuff + sz_xReq4);
3533 order = prefix->byteOrder;
3534 if (order != 'l' && order != 'B' && order != 'r' && order != 'R')
3535 return client->noClientException = -1;
3536 if (((*(char *) &whichbyte) && (order == 'B' || order == 'R')) ||
3537 (!(*(char *) &whichbyte) && (order == 'l' || order == 'r'))) {
3538 client->swapped = TRUE1;
3539 SwapConnClientPrefix(prefix);
3540 }
3541 stuff->reqType = 2;
3542 stuff->length += bytes_to_int32(prefix->nbytesAuthProto) +
3543 bytes_to_int32(prefix->nbytesAuthString);
3544 if (client->swapped) {
3545 swaps(&stuff->length)do { if (sizeof(*(&stuff->length)) != 2) wrong_size();
if (__builtin_constant_p((uintptr_t)(&stuff->length) &
1) && ((uintptr_t)(&stuff->length) & 1) ==
0) *(&stuff->length) = lswaps(*(&stuff->length
)); else swap_uint16((uint16_t *)(&stuff->length)); } while
(0)
;
3546 }
3547 if (order == 'r' || order == 'R') {
3548 client->local = FALSE0;
3549 }
3550 ResetCurrentRequest(client);
3551 return Success0;
3552}
3553
3554static int
3555SendConnSetup(ClientPtr client, const char *reason)
3556{
3557 xWindowRoot *root;
3558 int i;
3559 int numScreens;
3560 char *lConnectionInfo;
3561 xConnSetupPrefix *lconnSetupPrefix;
3562
3563 if (reason) {
3564 xConnSetupPrefix csp;
3565
3566 csp.success = xFalse0;
3567 csp.lengthReason = strlen(reason);
3568 csp.length = bytes_to_int32(csp.lengthReason);
3569 csp.majorVersion = X_PROTOCOL11;
3570 csp.minorVersion = X_PROTOCOL_REVISION0;
3571 if (client->swapped)
3572 WriteSConnSetupPrefix(client, &csp);
3573 else
3574 WriteToClient(client, sz_xConnSetupPrefix8, &csp);
3575 WriteToClient(client, (int) csp.lengthReason, reason);
3576 return client->noClientException = -1;
3577 }
3578
3579 numScreens = screenInfo.numScreens;
Value stored to 'numScreens' is never read
3580 lConnectionInfo = ConnectionInfo;
3581 lconnSetupPrefix = &connSetupPrefix;
3582
3583 /* We're about to start speaking X protocol back to the client by
3584 * sending the connection setup info. This means the authorization
3585 * step is complete, and we can count the client as an
3586 * authorized one.
3587 */
3588 nClients++;
3589
3590 client->requestVector = client->swapped ? SwappedProcVector : ProcVector;
3591 client->sequence = 0;
3592 ((xConnSetup *) lConnectionInfo)->ridBase = client->clientAsMask;
3593 ((xConnSetup *) lConnectionInfo)->ridMask = RESOURCE_ID_MASK((1 << (29 - 8)) - 1);
3594#ifdef MATCH_CLIENT_ENDIAN
3595 ((xConnSetup *) lConnectionInfo)->imageByteOrder = ClientOrder(client);
3596 ((xConnSetup *) lConnectionInfo)->bitmapBitOrder = ClientOrder(client);
3597#endif
3598 /* fill in the "currentInputMask" */
3599 root = (xWindowRoot *) (lConnectionInfo + connBlockScreenStart);
3600#ifdef PANORAMIX1
3601 if (noPanoramiXExtension)
3602 numScreens = screenInfo.numScreens;
3603 else
3604 numScreens = ((xConnSetup *) ConnectionInfo)->numRoots;
3605#endif
3606
3607 for (i = 0; i < numScreens; i++) {
3608 unsigned int j;
3609 xDepth *pDepth;
3610 WindowPtr pRoot = screenInfo.screens[i]->root;
3611
3612 root->currentInputMask = pRoot->eventMask | wOtherEventMasks(pRoot)((pRoot)->optional ? (pRoot)->optional->otherEventMasks
: 0)
;
3613 pDepth = (xDepth *) (root + 1);
3614 for (j = 0; j < root->nDepths; j++) {
3615 pDepth = (xDepth *) (((char *) (pDepth + 1)) +
3616 pDepth->nVisuals * sizeof(xVisualType));
3617 }
3618 root = (xWindowRoot *) pDepth;
3619 }
3620
3621 if (client->swapped) {
3622 WriteSConnSetupPrefix(client, lconnSetupPrefix);
3623 WriteSConnectionInfo(client,
3624 (unsigned long) (lconnSetupPrefix->length << 2),
3625 lConnectionInfo);
3626 }
3627 else {
3628 WriteToClient(client, sizeof(xConnSetupPrefix), lconnSetupPrefix);
3629 WriteToClient(client, (int) (lconnSetupPrefix->length << 2),
3630 lConnectionInfo);
3631 }
3632 client->clientState = ClientStateRunning;
3633 if (ClientStateCallback) {
3634 NewClientInfoRec clientinfo;
3635
3636 clientinfo.client = client;
3637 clientinfo.prefix = lconnSetupPrefix;
3638 clientinfo.setup = (xConnSetup *) lConnectionInfo;
3639 CallCallbacks((&ClientStateCallback), (void *) &clientinfo);
3640 }
3641 return Success0;
3642}
3643
3644int
3645ProcEstablishConnection(ClientPtr client)
3646{
3647 const char *reason;
3648 char *auth_proto, *auth_string;
3649 xConnClientPrefix *prefix;
3650
3651 REQUEST(xReq)xReq *stuff = (xReq *)client->requestBuffer;
3652
3653 prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq4);
3654 auth_proto = (char *) prefix + sz_xConnClientPrefix12;
3655 auth_string = auth_proto + pad_to_int32(prefix->nbytesAuthProto);
3656 if ((prefix->majorVersion != X_PROTOCOL11) ||
3657 (prefix->minorVersion != X_PROTOCOL_REVISION0))
3658 reason = "Protocol version mismatch";
3659 else
3660 reason = ClientAuthorized(client,
3661 (unsigned short) prefix->nbytesAuthProto,
3662 auth_proto,
3663 (unsigned short) prefix->nbytesAuthString,
3664 auth_string);
3665
3666 return (SendConnSetup(client, reason));
3667}
3668
3669void
3670SendErrorToClient(ClientPtr client, unsigned majorCode, unsigned minorCode,
3671 XID resId, int errorCode)
3672{
3673 xError rep = {
3674 .type = X_Error0,
3675 .errorCode = errorCode,
3676 .resourceID = resId,
3677 .minorCode = minorCode,
3678 .majorCode = majorCode
3679 };
3680
3681 WriteEventsToClient(client, 1, (xEvent *) &rep);
3682}
3683
3684void
3685MarkClientException(ClientPtr client)
3686{
3687 client->noClientException = -1;
3688}
3689
3690/*
3691 * This array encodes the answer to the question "what is the log base 2
3692 * of the number of pixels that fit in a scanline pad unit?"
3693 * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
3694 */
3695static int answer[6][4] = {
3696 /* pad pad pad pad */
3697 /* 8 16 32 64 */
3698
3699 {3, 4, 5, 6}, /* 1 bit per pixel */
3700 {1, 2, 3, 4}, /* 4 bits per pixel */
3701 {0, 1, 2, 3}, /* 8 bits per pixel */
3702 {~0, 0, 1, 2}, /* 16 bits per pixel */
3703 {~0, ~0, 0, 1}, /* 24 bits per pixel */
3704 {~0, ~0, 0, 1} /* 32 bits per pixel */
3705};
3706
3707/*
3708 * This array gives the answer to the question "what is the first index for
3709 * the answer array above given the number of bits per pixel?"
3710 * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
3711 */
3712static int indexForBitsPerPixel[33] = {
3713 ~0, 0, ~0, ~0, /* 1 bit per pixel */
3714 1, ~0, ~0, ~0, /* 4 bits per pixel */
3715 2, ~0, ~0, ~0, /* 8 bits per pixel */
3716 ~0, ~0, ~0, ~0,
3717 3, ~0, ~0, ~0, /* 16 bits per pixel */
3718 ~0, ~0, ~0, ~0,
3719 4, ~0, ~0, ~0, /* 24 bits per pixel */
3720 ~0, ~0, ~0, ~0,
3721 5 /* 32 bits per pixel */
3722};
3723
3724/*
3725 * This array gives the bytesperPixel value for cases where the number
3726 * of bits per pixel is a multiple of 8 but not a power of 2.
3727 */
3728static int answerBytesPerPixel[33] = {
3729 ~0, 0, ~0, ~0, /* 1 bit per pixel */
3730 0, ~0, ~0, ~0, /* 4 bits per pixel */
3731 0, ~0, ~0, ~0, /* 8 bits per pixel */
3732 ~0, ~0, ~0, ~0,
3733 0, ~0, ~0, ~0, /* 16 bits per pixel */
3734 ~0, ~0, ~0, ~0,
3735 3, ~0, ~0, ~0, /* 24 bits per pixel */
3736 ~0, ~0, ~0, ~0,
3737 0 /* 32 bits per pixel */
3738};
3739
3740/*
3741 * This array gives the answer to the question "what is the second index for
3742 * the answer array above given the number of bits per scanline pad unit?"
3743 * Note that ~0 is an invalid entry (mostly for the benefit of the reader).
3744 */
3745static int indexForScanlinePad[65] = {
3746 ~0, ~0, ~0, ~0,
3747 ~0, ~0, ~0, ~0,
3748 0, ~0, ~0, ~0, /* 8 bits per scanline pad unit */
3749 ~0, ~0, ~0, ~0,
3750 1, ~0, ~0, ~0, /* 16 bits per scanline pad unit */
3751 ~0, ~0, ~0, ~0,
3752 ~0, ~0, ~0, ~0,
3753 ~0, ~0, ~0, ~0,
3754 2, ~0, ~0, ~0, /* 32 bits per scanline pad unit */
3755 ~0, ~0, ~0, ~0,
3756 ~0, ~0, ~0, ~0,
3757 ~0, ~0, ~0, ~0,
3758 ~0, ~0, ~0, ~0,
3759 ~0, ~0, ~0, ~0,
3760 ~0, ~0, ~0, ~0,
3761 ~0, ~0, ~0, ~0,
3762 3 /* 64 bits per scanline pad unit */
3763};
3764
3765/*
3766 grow the array of screenRecs if necessary.
3767 call the device-supplied initialization procedure
3768with its screen number, a pointer to its ScreenRec, argc, and argv.
3769 return the number of successfully installed screens.
3770
3771*/
3772
3773static int init_screen(ScreenPtr pScreen, int i, Bool gpu)
3774{
3775 int scanlinepad, format, depth, bitsPerPixel, j, k;
3776
3777 dixInitScreenSpecificPrivates(pScreen);
3778
3779 if (!dixAllocatePrivates(&pScreen->devPrivates, PRIVATE_SCREEN)) {
3780 return -1;
3781 }
3782 pScreen->myNum = i;
3783 if (gpu) {
3784 pScreen->myNum += GPU_SCREEN_OFFSET256;
3785 pScreen->isGPU = TRUE1;
3786 }
3787 pScreen->totalPixmapSize = 0; /* computed in CreateScratchPixmapForScreen */
3788 pScreen->ClipNotify = 0; /* for R4 ddx compatibility */
3789 pScreen->CreateScreenResources = 0;
3790
3791 xorg_list_init(&pScreen->pixmap_dirty_list);
3792 xorg_list_init(&pScreen->unattached_list);
3793 xorg_list_init(&pScreen->output_slave_list);
3794 xorg_list_init(&pScreen->offload_slave_list);
3795
3796 /*
3797 * This loop gets run once for every Screen that gets added,
3798 * but thats ok. If the ddx layer initializes the formats
3799 * one at a time calling AddScreen() after each, then each
3800 * iteration will make it a little more accurate. Worst case
3801 * we do this loop N * numPixmapFormats where N is # of screens.
3802 * Anyway, this must be called after InitOutput and before the
3803 * screen init routine is called.
3804 */
3805 for (format = 0; format < screenInfo.numPixmapFormats; format++) {
3806 depth = screenInfo.formats[format].depth;
3807 bitsPerPixel = screenInfo.formats[format].bitsPerPixel;
3808 scanlinepad = screenInfo.formats[format].scanlinePad;
3809 j = indexForBitsPerPixel[bitsPerPixel];
3810 k = indexForScanlinePad[scanlinepad];
3811 PixmapWidthPaddingInfo[depth].padPixelsLog2 = answer[j][k];
3812 PixmapWidthPaddingInfo[depth].padRoundUp =
3813 (scanlinepad / bitsPerPixel) - 1;
3814 j = indexForBitsPerPixel[8]; /* bits per byte */
3815 PixmapWidthPaddingInfo[depth].padBytesLog2 = answer[j][k];
3816 PixmapWidthPaddingInfo[depth].bitsPerPixel = bitsPerPixel;
3817 if (answerBytesPerPixel[bitsPerPixel]) {
3818 PixmapWidthPaddingInfo[depth].notPower2 = 1;
3819 PixmapWidthPaddingInfo[depth].bytesPerPixel =
3820 answerBytesPerPixel[bitsPerPixel];
3821 }
3822 else {
3823 PixmapWidthPaddingInfo[depth].notPower2 = 0;
3824 }
3825 }
3826 return 0;
3827}
3828
3829int
3830AddScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
3831 int /*argc */ ,
3832 char ** /*argv */
3833 ), int argc, char **argv)
3834{
3835
3836 int i;
3837 ScreenPtr pScreen;
3838 Bool ret;
3839
3840 i = screenInfo.numScreens;
3841 if (i == MAXSCREENS16)
3842 return -1;
3843
3844 pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
3845 if (!pScreen)
3846 return -1;
3847
3848 ret = init_screen(pScreen, i, FALSE0);
3849 if (ret != 0) {
3850 free(pScreen);
3851 return ret;
3852 }
3853 /* This is where screen specific stuff gets initialized. Load the
3854 screen structure, call the hardware, whatever.
3855 This is also where the default colormap should be allocated and
3856 also pixel values for blackPixel, whitePixel, and the cursor
3857 Note that InitScreen is NOT allowed to modify argc, argv, or
3858 any of the strings pointed to by argv. They may be passed to
3859 multiple screens.
3860 */
3861 screenInfo.screens[i] = pScreen;
3862 screenInfo.numScreens++;
3863 if (!(*pfnInit) (pScreen, argc, argv)) {
3864 dixFreeScreenSpecificPrivates(pScreen);
3865 dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
3866 free(pScreen);
3867 screenInfo.numScreens--;
3868 return -1;
3869 }
3870
3871 update_desktop_dimensions();
3872
3873 dixRegisterScreenPrivateKey(&cursorScreenDevPriv, pScreen, PRIVATE_CURSOR,
3874 0);
3875
3876 return i;
3877}
3878
3879int
3880AddGPUScreen(Bool (*pfnInit) (ScreenPtr /*pScreen */ ,
3881 int /*argc */ ,
3882 char ** /*argv */
3883 ),
3884 int argc, char **argv)
3885{
3886 int i;
3887 ScreenPtr pScreen;
3888 Bool ret;
3889
3890 i = screenInfo.numGPUScreens;
3891 if (i == MAXGPUSCREENS16)
3892 return -1;
3893
3894 pScreen = (ScreenPtr) calloc(1, sizeof(ScreenRec));
3895 if (!pScreen)
3896 return -1;
3897
3898 ret = init_screen(pScreen, i, TRUE1);
3899 if (ret != 0) {
3900 free(pScreen);
3901 return ret;
3902 }
3903
3904 /* This is where screen specific stuff gets initialized. Load the
3905 screen structure, call the hardware, whatever.
3906 This is also where the default colormap should be allocated and
3907 also pixel values for blackPixel, whitePixel, and the cursor
3908 Note that InitScreen is NOT allowed to modify argc, argv, or
3909 any of the strings pointed to by argv. They may be passed to
3910 multiple screens.
3911 */
3912 screenInfo.gpuscreens[i] = pScreen;
3913 screenInfo.numGPUScreens++;
3914 if (!(*pfnInit) (pScreen, argc, argv)) {
3915 dixFreePrivates(pScreen->devPrivates, PRIVATE_SCREEN);
3916 free(pScreen);
3917 screenInfo.numGPUScreens--;
3918 return -1;
3919 }
3920
3921 update_desktop_dimensions();
3922
3923 return i;
3924}
3925
3926void
3927RemoveGPUScreen(ScreenPtr pScreen)
3928{
3929 int idx, j;
3930 if (!pScreen->isGPU)
3931 return;
3932
3933 idx = pScreen->myNum - GPU_SCREEN_OFFSET256;
3934 for (j = idx; j < screenInfo.numGPUScreens - 1; j++) {
3935 screenInfo.gpuscreens[j] = screenInfo.gpuscreens[j + 1];
3936 screenInfo.gpuscreens[j]->myNum = j + GPU_SCREEN_OFFSET256;
3937 }
3938 screenInfo.numGPUScreens--;
3939
3940 /* this gets freed later in the resource list, but without
3941 * the screen existing it causes crashes - so remove it here */
3942 if (pScreen->defColormap)
3943 FreeResource(pScreen->defColormap, RT_COLORMAP((RESTYPE)6));
3944 free(pScreen);
3945
3946}
3947
3948void
3949AttachUnboundGPU(ScreenPtr pScreen, ScreenPtr new)
3950{
3951 assert(new->isGPU)(__builtin_expect(!(new->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3951, "new->isGPU") : (void)0)
;
3952 assert(!new->current_master)(__builtin_expect(!(!new->current_master), 0) ? __assert_rtn
(__func__, "dispatch.c", 3952, "!new->current_master") : (
void)0)
;
3953 xorg_list_add(&new->unattached_head, &pScreen->unattached_list);
3954 new->current_master = pScreen;
3955}
3956
3957void
3958DetachUnboundGPU(ScreenPtr slave)
3959{
3960 assert(slave->isGPU)(__builtin_expect(!(slave->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3960, "slave->isGPU") : (void)0)
;
3961 xorg_list_del(&slave->unattached_head);
3962 slave->current_master = NULL((void*)0);
3963}
3964
3965void
3966AttachOutputGPU(ScreenPtr pScreen, ScreenPtr new)
3967{
3968 assert(new->isGPU)(__builtin_expect(!(new->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3968, "new->isGPU") : (void)0)
;
3969 xorg_list_add(&new->output_head, &pScreen->output_slave_list);
3970 new->current_master = pScreen;
3971}
3972
3973void
3974DetachOutputGPU(ScreenPtr slave)
3975{
3976 assert(slave->isGPU)(__builtin_expect(!(slave->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3976, "slave->isGPU") : (void)0)
;
3977 xorg_list_del(&slave->output_head);
3978 slave->current_master = NULL((void*)0);
3979}
3980
3981void
3982AttachOffloadGPU(ScreenPtr pScreen, ScreenPtr new)
3983{
3984 assert(new->isGPU)(__builtin_expect(!(new->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3984, "new->isGPU") : (void)0)
;
3985 xorg_list_add(&new->offload_head, &pScreen->offload_slave_list);
3986 new->current_master = pScreen;
3987}
3988
3989void
3990DetachOffloadGPU(ScreenPtr slave)
3991{
3992 assert(slave->isGPU)(__builtin_expect(!(slave->isGPU), 0) ? __assert_rtn(__func__
, "dispatch.c", 3992, "slave->isGPU") : (void)0)
;
3993 xorg_list_del(&slave->offload_head);
3994 slave->current_master = NULL((void*)0);
3995}
3996