1 /***********************************************************
2
3 Copyright 1987, 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 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 /*
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 #ifdef INXQUARTZ
104 #include "nonsdk_extinit.h"
105 #endif
106 #include "micmap.h"
107 #include "os.h"
108 #include "globals.h"
109
110 /* List of built-in (statically linked) extensions */
111 static const ExtensionModule staticExtensions[] = {
112 {GEExtensionInit, "Generic Event Extension", &noGEExtension},
113 {ShapeExtensionInit, "SHAPE", NULL},
114 #ifdef MITSHM
115 {ShmExtensionInit, "MIT-SHM", &noMITShmExtension},
116 #endif
117 {XInputExtensionInit, "XInputExtension", NULL},
118 #ifdef XTEST
119 {XTestExtensionInit, "XTEST", &noTestExtensions},
120 #endif
121 {BigReqExtensionInit, "BIG-REQUESTS", NULL},
122 {SyncExtensionInit, "SYNC", NULL},
123 {XkbExtensionInit, "XKEYBOARD", NULL},
124 {XCMiscExtensionInit, "XC-MISC", NULL},
125 #ifdef XCSECURITY
126 {SecurityExtensionInit, "SECURITY", &noSecurityExtension},
127 #endif
128 #ifdef PANORAMIX
129 {PanoramiXExtensionInit, "XINERAMA", &noPanoramiXExtension},
130 #endif
131 #ifdef INXQUARTZ
132 /* PseudoramiXExtensionInit must be done before RRExtensionInit, or
133 * XQuartz will render windows offscreen.
134 */
135 {PseudoramiXExtensionInit, "PseudoramiX", &noPseudoramiXExtension},
136 #endif
137 /* must be before Render to layer DisplayCursor correctly */
138 {XFixesExtensionInit, "XFIXES", &noXFixesExtension},
139 #ifdef XF86BIGFONT
140 {XFree86BigfontExtensionInit, "XFree86-Bigfont", &noXFree86BigfontExtension},
141 #endif
142 {RenderExtensionInit, "RENDER", &noRenderExtension},
143 #ifdef RANDR
144 {RRExtensionInit, "RANDR", &noRRExtension},
145 #endif
146 #ifdef COMPOSITE
147 {CompositeExtensionInit, "COMPOSITE", &noCompositeExtension},
148 #endif
149 #ifdef DAMAGE
150 {DamageExtensionInit, "DAMAGE", &noDamageExtension},
151 #endif
152 #ifdef SCREENSAVER
153 {ScreenSaverExtensionInit, "MIT-SCREEN-SAVER", &noScreenSaverExtension},
154 #endif
155 #ifdef DBE
156 {DbeExtensionInit, "DOUBLE-BUFFER", &noDbeExtension},
157 #endif
158 #ifdef XRECORD
159 {RecordExtensionInit, "RECORD", &noTestExtensions},
160 #endif
161 #ifdef DPMSExtension
162 {DPMSExtensionInit, "DPMS", &noDPMSExtension},
163 #endif
164 #ifdef PRESENT
165 {present_extension_init, "Present", NULL},
166 #endif
167 #ifdef DRI3
168 {dri3_extension_init, "DRI3", NULL},
169 #endif
170 #ifdef RES
171 {ResExtensionInit, "X-Resource", &noResExtension},
172 #endif
173 #ifdef XV
174 {XvExtensionInit, "XVideo", &noXvExtension},
175 {XvMCExtensionInit, "XVideo-MotionCompensation", &noXvExtension},
176 #endif
177 #ifdef XSELINUX
178 {SELinuxExtensionInit, "SELinux", &noSELinuxExtension},
179 #endif
180 #ifdef GLXEXT
181 {GlxExtensionInit, "GLX", &noGlxExtension},
182 #endif
183 };
184
185 Bool
EnableDisableExtension(const char * name,Bool enable)186 EnableDisableExtension(const char *name, Bool enable)
187 {
188 const ExtensionModule *ext;
189 int i;
190
191 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) {
192 ext = &staticExtensions[i];
193 if (strcasecmp(name, ext->name) == 0) {
194 if (ext->disablePtr != NULL) {
195 *ext->disablePtr = !enable;
196 return TRUE;
197 }
198 else {
199 /* Extension is always on, impossible to disable */
200 return enable; /* okay if they wanted to enable,
201 fail if they tried to disable */
202 }
203 }
204 }
205
206 return FALSE;
207 }
208
209 void
EnableDisableExtensionError(const char * name,Bool enable)210 EnableDisableExtensionError(const char *name, Bool enable)
211 {
212 const ExtensionModule *ext;
213 int i;
214 Bool found = FALSE;
215
216 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) {
217 ext = &staticExtensions[i];
218 if ((strcmp(name, ext->name) == 0) && (ext->disablePtr == NULL)) {
219 ErrorF("[mi] Extension \"%s\" can not be disabled\n", name);
220 found = TRUE;
221 break;
222 }
223 }
224 if (found == FALSE)
225 ErrorF("[mi] Extension \"%s\" is not recognized\n", name);
226 ErrorF("[mi] Only the following extensions can be run-time %s:\n",
227 enable ? "enabled" : "disabled");
228 for (i = 0; i < ARRAY_SIZE(staticExtensions); i++) {
229 ext = &staticExtensions[i];
230 if (ext->disablePtr != NULL) {
231 ErrorF("[mi] %s\n", ext->name);
232 }
233 }
234 }
235
236 static ExtensionModule *ExtensionModuleList = NULL;
237 static int numExtensionModules = 0;
238
239 static void
AddStaticExtensions(void)240 AddStaticExtensions(void)
241 {
242 static Bool listInitialised = FALSE;
243
244 if (listInitialised)
245 return;
246 listInitialised = TRUE;
247
248 /* Add built-in extensions to the list. */
249 LoadExtensionList(staticExtensions, ARRAY_SIZE(staticExtensions), TRUE);
250 }
251
252 void
InitExtensions(int argc,char * argv[])253 InitExtensions(int argc, char *argv[])
254 {
255 int i;
256 ExtensionModule *ext;
257
258 AddStaticExtensions();
259
260 for (i = 0; i < numExtensionModules; i++) {
261 ext = &ExtensionModuleList[i];
262 if (ext->initFunc != NULL &&
263 (ext->disablePtr == NULL || !*ext->disablePtr)) {
264 LogMessageVerb(X_INFO, 3, "Initializing extension %s\n",
265 ext->name);
266
267 (ext->initFunc) ();
268 }
269 }
270 }
271
272 static ExtensionModule *
NewExtensionModuleList(int size)273 NewExtensionModuleList(int size)
274 {
275 ExtensionModule *save = ExtensionModuleList;
276 int n;
277
278 /* Sanity check */
279 if (!ExtensionModuleList)
280 numExtensionModules = 0;
281
282 n = numExtensionModules + size;
283 ExtensionModuleList = reallocarray(ExtensionModuleList, n,
284 sizeof(ExtensionModule));
285 if (ExtensionModuleList == NULL) {
286 ExtensionModuleList = save;
287 return NULL;
288 }
289 else {
290 numExtensionModules += size;
291 return ExtensionModuleList + (numExtensionModules - size);
292 }
293 }
294
295 void
LoadExtensionList(const ExtensionModule ext[],int size,Bool builtin)296 LoadExtensionList(const ExtensionModule ext[], int size, Bool builtin)
297 {
298 ExtensionModule *newext;
299 int i;
300
301 /* Make sure built-in extensions get added to the list before those
302 * in modules. */
303 AddStaticExtensions();
304
305 if (!(newext = NewExtensionModuleList(size)))
306 return;
307
308 for (i = 0; i < size; i++, newext++) {
309 newext->name = ext[i].name;
310 newext->initFunc = ext[i].initFunc;
311 newext->disablePtr = ext[i].disablePtr;
312 }
313 }
314