1/*********************************************************** 2 3Copyright 1987, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts. 26 27 All Rights Reserved 28 29Permission to use, copy, modify, and distribute this software and its 30documentation for any purpose and without fee is hereby granted, 31provided that the above copyright notice appear in all copies and that 32both that copyright notice and this permission notice appear in 33supporting documentation, and that the name of Digital not be 34used in advertising or publicity pertaining to distribution of the 35software without specific, written prior permission. 36 37DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 38ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 39DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 40ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 41WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 42ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 43SOFTWARE. 44 45******************************************************************/ 46 47/* 48 * Copyright (c) 2000 by The XFree86 Project, Inc. 49 * 50 * Permission is hereby granted, free of charge, to any person obtaining a 51 * copy of this software and associated documentation files (the "Software"), 52 * to deal in the Software without restriction, including without limitation 53 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 54 * and/or sell copies of the Software, and to permit persons to whom the 55 * Software is furnished to do so, subject to the following conditions: 56 * 57 * The above copyright notice and this permission notice shall be included in 58 * all copies or substantial portions of the Software. 59 * 60 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 61 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 62 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 63 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 64 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 65 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 66 * OTHER DEALINGS IN THE SOFTWARE. 67 * 68 * Except as contained in this notice, the name of the copyright holder(s) 69 * and author(s) shall not be used in advertising or otherwise to promote 70 * the sale, use or other dealings in this Software without prior written 71 * authorization from the copyright holder(s) and author(s). 72 */ 73 74#ifdef HAVE_DIX_CONFIG_H 75#include <dix-config.h> 76#endif 77 78#ifdef HAVE_XORG_CONFIG_H 79#include <xorg-config.h> 80#include "xf86Extensions.h" 81#endif 82 83#ifdef HAVE_DMX_CONFIG_H 84#include <dmx-config.h> 85#undef XV 86#undef DBE 87#undef SCREENSAVER 88#undef RANDR 89#undef DAMAGE 90#undef COMPOSITE 91#undef MITSHM 92#endif 93 94#ifdef HAVE_XNEST_CONFIG_H 95#include <xnest-config.h> 96#undef COMPOSITE 97#undef DPMSExtension 98#endif 99 100#include "misc.h" 101#include "extension.h" 102#include "extinit.h" 103#include "micmap.h" 104#include "os.h" 105#include "globals.h" 106 107#include "miinitext.h" 108 109/* List of built-in (statically linked) extensions */ 110static const ExtensionModule staticExtensions[] = { 111 {GEExtensionInit, "Generic Event Extension", &noGEExtension}, 112 {ShapeExtensionInit, "SHAPE", NULL}, 113#ifdef MITSHM 114 {ShmExtensionInit, "MIT-SHM", &noMITShmExtension}, 115#endif 116 {XInputExtensionInit, "XInputExtension", NULL}, 117#ifdef XTEST 118 {XTestExtensionInit, "XTEST", &noTestExtensions}, 119#endif 120 {BigReqExtensionInit, "BIG-REQUESTS", NULL}, 121 {SyncExtensionInit, "SYNC", NULL}, 122 {XkbExtensionInit, "XKEYBOARD", NULL}, 123 {XCMiscExtensionInit, "XC-MISC", NULL}, 124#ifdef XCSECURITY 125 {SecurityExtensionInit, "SECURITY", &noSecurityExtension}, 126#endif 127#ifdef PANORAMIX 128 {PanoramiXExtensionInit, "XINERAMA", &noPanoramiXExtension}, 129#endif 130 /* must be before Render to layer DisplayCursor correctly */ 131 {XFixesExtensionInit, "XFIXES", &noXFixesExtension}, 132#ifdef XF86BIGFONT 133 {XFree86BigfontExtensionInit, "XFree86-Bigfont", &noXFree86BigfontExtension}, 134#endif 135 {RenderExtensionInit, "RENDER", &noRenderExtension}, 136#ifdef RANDR 137 {RRExtensionInit, "RANDR", &noRRExtension}, 138#endif 139#ifdef COMPOSITE 140 {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension}, 141#endif 142#ifdef DAMAGE 143 {DamageExtensionInit, "DAMAGE", &noDamageExtension}, 144#endif 145#ifdef SCREENSAVER 146 {ScreenSaverExtensionInit, "MIT-SCREEN-SAVER", &noScreenSaverExtension}, 147#endif 148#ifdef DBE 149 {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension}, 150#endif 151#ifdef XRECORD 152 {RecordExtensionInit, "RECORD", &noTestExtensions}, 153#endif 154#ifdef DPMSExtension 155 {DPMSExtensionInit, "DPMS", &noDPMSExtension}, 156#endif 157#ifdef PRESENT 158 {present_extension_init, "Present", NULL}, 159#endif 160#ifdef DRI3 161 {dri3_extension_init, "DRI3", NULL}, 162#endif 163#ifdef RES 164 {ResExtensionInit, "X-Resource", &noResExtension}, 165#endif 166#ifdef XV 167 {XvExtensionInit, "XVideo", &noXvExtension}, 168 {XvMCExtensionInit, "XVideo-MotionCompensation", &noXvExtension}, 169#endif 170#ifdef XSELINUX 171 {SELinuxExtensionInit, "SELinux", &noSELinuxExtension}, 172#endif 173#ifdef GLXEXT 174 {GlxExtensionInit, "GLX", &noGlxExtension}, 175#endif 176}; 177 178void 179ListStaticExtensions(void) 180{ 181 const ExtensionModule *ext; 182 int i; 183 184 ErrorF(" Only the following extensions can be run-time enabled/disabled:\n"); 185 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) { 186 ext = &staticExtensions[i]; 187 if (ext->disablePtr != NULL) { 188 ErrorF("\t%s\n", ext->name); 189 } 190 } 191} 192 193Bool 194EnableDisableExtension(const char *name, Bool enable) 195{ 196 const ExtensionModule *ext; 197 int i; 198 199 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) { 200 ext = &staticExtensions[i]; 201 if (strcasecmp(name, ext->name) == 0) { 202 if (ext->disablePtr != NULL) { 203 *ext->disablePtr = !enable; 204 return TRUE; 205 } 206 else { 207 /* Extension is always on, impossible to disable */ 208 return enable; /* okay if they wanted to enable, 209 fail if they tried to disable */ 210 } 211 } 212 } 213 214 return FALSE; 215} 216 217void 218EnableDisableExtensionError(const char *name, Bool enable) 219{ 220 const ExtensionModule *ext; 221 int i; 222 Bool found = FALSE; 223 224 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) { 225 ext = &staticExtensions[i]; 226 if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) { 227 ErrorF("[mi] Extension \"%s\" can not be disabled\n", name); 228 found = TRUE; 229 break; 230 } 231 } 232 if (found == FALSE) { 233 ErrorF("[mi] Extension \"%s\" is not recognized\n", name); 234 /* Disabling a non-existing extension is a no-op anyway */ 235 if (enable == FALSE) 236 return; 237 } 238 ListStaticExtensions(); 239} 240 241static ExtensionModule *ExtensionModuleList = NULL; 242static int numExtensionModules = 0; 243 244static void 245AddStaticExtensions(void) 246{ 247 static Bool listInitialised = FALSE; 248 249 if (listInitialised) 250 return; 251 listInitialised = TRUE; 252 253 /* Add built-in extensions to the list. */ 254 LoadExtensionList(staticExtensions, ARRAY_SIZE(staticExtensions), TRUE); 255} 256 257void 258InitExtensions(int argc, char *argv[]) 259{ 260 int i; 261 ExtensionModule *ext; 262 263 AddStaticExtensions(); 264 265 for (i = 0; i < numExtensionModules; i++) { 266 ext = &ExtensionModuleList[i]; 267 if (ext->initFunc != NULL && 268 (ext->disablePtr == NULL || !*ext->disablePtr)) { 269 LogMessageVerb(X_INFO, 3, "Initializing extension %s\n", 270 ext->name); 271 272 (ext->initFunc) (); 273 } 274 } 275} 276 277static ExtensionModule * 278NewExtensionModuleList(int size) 279{ 280 ExtensionModule *save = ExtensionModuleList; 281 int n; 282 283 /* Sanity check */ 284 if (!ExtensionModuleList) 285 numExtensionModules = 0; 286 287 n = numExtensionModules + size; 288 ExtensionModuleList = reallocarray(ExtensionModuleList, n, 289 sizeof(ExtensionModule)); 290 if (ExtensionModuleList == NULL) { 291 ExtensionModuleList = save; 292 return NULL; 293 } 294 else { 295 numExtensionModules += size; 296 return ExtensionModuleList + (numExtensionModules - size); 297 } 298} 299 300void 301LoadExtensionList(const ExtensionModule ext[], int size, Bool builtin) 302{ 303 ExtensionModule *newext; 304 int i; 305 306 /* Make sure built-in extensions get added to the list before those 307 * in modules. */ 308 AddStaticExtensions(); 309 310 if (!(newext = NewExtensionModuleList(size))) 311 return; 312 313 for (i = 0; i < size; i++, newext++) { 314 newext->name = ext[i].name; 315 newext->initFunc = ext[i].initFunc; 316 newext->disablePtr = ext[i].disablePtr; 317 } 318} 319