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