1 // Copyright (C)2004 Landmark Graphics Corporation
2 // Copyright (C)2005, 2006 Sun Microsystems, Inc.
3 // Copyright (C)2009, 2011, 2013-2016, 2018-2021 D. R. Commander
4 //
5 // This library is free software and may be redistributed and/or modified under
6 // the terms of the wxWindows Library License, Version 3.1 or (at your option)
7 // any later version.  The full license is in the LICENSE.txt file included
8 // with this distribution.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // wxWindows Library License for more details.
14 
15 #ifndef __FAKER_SYM_H__
16 #define __FAKER_SYM_H__
17 
18 #include <stdio.h>
19 #define GL_GLEXT_PROTOTYPES
20 #define GLX_GLXEXT_PROTOTYPES
21 #include <GL/glx.h>
22 #ifdef EGLBACKEND
23 #include <EGL/egl.h>
24 #define EGL_EGLEXT_PROTOTYPES
25 #include <EGL/eglext.h>
26 #endif
27 #ifdef FAKEOPENCL
28 #include <CL/opencl.h>
29 #endif
30 #include "Log.h"
31 #include "GlobalCriticalSection.h"
32 #include "vglinline.h"
33 #ifdef FAKEXCB
34 extern "C" {
35 	#include <xcb/xcb.h>
36 	#include <xcb/xcbext.h>
37 	#include <xcb/xcb_keysyms.h>
38 	#include <xcb/glx.h>
39 	#include <X11/Xlib-xcb.h>
40 }
41 #endif
42 #include "faker.h"
43 #include <X11/XKBlib.h>
44 #ifdef USEHELGRIND
45 	#include <valgrind/helgrind.h>
46 #else
47 	#define ANNOTATE_BENIGN_RACE_SIZED(a, b, c) {}
48 #endif
49 
50 
51 #define CHECKSYM_NONFATAL(s) \
52 { \
53 	ANNOTATE_BENIGN_RACE_SIZED(&__##s, sizeof(_##s##Type), ); \
54 	if(!__##s) \
55 	{ \
56 		vglfaker::init(); \
57 		vglfaker::GlobalCriticalSection::SafeLock l(globalMutex); \
58 		if(!__##s) __##s = (_##s##Type)vglfaker::loadSymbol(#s, true); \
59 	} \
60 }
61 
62 #define CHECKSYM(s, fake_s) \
63 { \
64 	ANNOTATE_BENIGN_RACE_SIZED(&__##s, sizeof(_##s##Type), ); \
65 	if(!__##s) \
66 	{ \
67 		vglfaker::init(); \
68 		vglfaker::GlobalCriticalSection::SafeLock l(globalMutex); \
69 		if(!__##s) __##s = (_##s##Type)vglfaker::loadSymbol(#s); \
70 	} \
71 	if(!__##s) vglfaker::safeExit(1); \
72 	if(__##s == fake_s) \
73 	{ \
74 		vglout.print("[VGL] ERROR: VirtualGL attempted to load the real\n"); \
75 		vglout.print("[VGL]   " #s " function and got the fake one instead.\n"); \
76 		vglout.print("[VGL]   Something is terribly wrong.  Aborting before chaos ensues.\n"); \
77 		vglfaker::safeExit(1); \
78 	} \
79 }
80 
81 #ifdef __LOCALSYM__
82 #define SYMDEF(f)  _##f##Type __##f = NULL
83 #else
84 #define SYMDEF(f)  extern _##f##Type __##f
85 #endif
86 
87 
88 #define DISABLE_FAKER() \
89 	vglfaker::setFakerLevel(vglfaker::getFakerLevel() + 1);
90 #define ENABLE_FAKER() \
91 	vglfaker::setFakerLevel(vglfaker::getFakerLevel() - 1);
92 
93 
94 #define FUNCDEF0(RetType, f, fake_f) \
95 	typedef RetType (*_##f##Type)(void); \
96 	SYMDEF(f); \
97 	static INLINE RetType _##f(void) \
98 	{ \
99 		RetType retval; \
100 		CHECKSYM(f, fake_f); \
101 		DISABLE_FAKER(); \
102 		retval = __##f(); \
103 		ENABLE_FAKER(); \
104 		return retval; \
105 	}
106 
107 #define VFUNCDEF0(f, fake_f) \
108 	typedef void (*_##f##Type)(void); \
109 	SYMDEF(f); \
110 	static INLINE void _##f(void) \
111 	{ \
112 		CHECKSYM(f, fake_f); \
113 		DISABLE_FAKER(); \
114 		__##f(); \
115 		ENABLE_FAKER(); \
116 	}
117 
118 #define FUNCDEF1(RetType, f, at1, a1, fake_f) \
119 	typedef RetType (*_##f##Type)(at1); \
120 	SYMDEF(f); \
121 	static INLINE RetType _##f(at1 a1) \
122 	{ \
123 		RetType retval; \
124 		CHECKSYM(f, fake_f); \
125 		DISABLE_FAKER(); \
126 		retval = __##f(a1); \
127 		ENABLE_FAKER(); \
128 		return retval; \
129 	}
130 
131 #define VFUNCDEF1(f, at1, a1, fake_f) \
132 	typedef void (*_##f##Type)(at1); \
133 	SYMDEF(f); \
134 	static INLINE void _##f(at1 a1) \
135 	{ \
136 		CHECKSYM(f, fake_f); \
137 		DISABLE_FAKER(); \
138 		__##f(a1); \
139 		ENABLE_FAKER(); \
140 	}
141 
142 #define FUNCDEF2(RetType, f, at1, a1, at2, a2, fake_f) \
143 	typedef RetType (*_##f##Type)(at1, at2); \
144 	SYMDEF(f); \
145 	static INLINE RetType _##f(at1 a1, at2 a2) \
146 	{ \
147 		RetType retval; \
148 		CHECKSYM(f, fake_f); \
149 		DISABLE_FAKER(); \
150 		retval = __##f(a1, a2); \
151 		ENABLE_FAKER(); \
152 		return retval; \
153 	}
154 
155 #define VFUNCDEF2(f, at1, a1, at2, a2, fake_f) \
156 	typedef void (*_##f##Type)(at1, at2); \
157 	SYMDEF(f); \
158 	static INLINE void _##f(at1 a1, at2 a2) \
159 	{ \
160 		CHECKSYM(f, fake_f); \
161 		DISABLE_FAKER(); \
162 		__##f(a1, a2); \
163 		ENABLE_FAKER(); \
164 	}
165 
166 #define FUNCDEF3(RetType, f, at1, a1, at2, a2, at3, a3, fake_f) \
167 	typedef RetType (*_##f##Type)(at1, at2, at3); \
168 	SYMDEF(f); \
169 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3) \
170 	{ \
171 		RetType retval; \
172 		CHECKSYM(f, fake_f); \
173 		DISABLE_FAKER(); \
174 		retval = __##f(a1, a2, a3); \
175 		ENABLE_FAKER(); \
176 		return retval; \
177 	}
178 
179 #define VFUNCDEF3(f, at1, a1, at2, a2, at3, a3, fake_f) \
180 	typedef void (*_##f##Type)(at1, at2, at3); \
181 	SYMDEF(f); \
182 	static INLINE void _##f(at1 a1, at2 a2, at3 a3) \
183 	{ \
184 		CHECKSYM(f, fake_f); \
185 		DISABLE_FAKER(); \
186 		__##f(a1, a2, a3); \
187 		ENABLE_FAKER(); \
188 	}
189 
190 #define FUNCDEF4(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, fake_f) \
191 	typedef RetType (*_##f##Type)(at1, at2, at3, at4); \
192 	SYMDEF(f); \
193 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4) \
194 	{ \
195 		RetType retval; \
196 		CHECKSYM(f, fake_f); \
197 		DISABLE_FAKER(); \
198 		retval = __##f(a1, a2, a3, a4); \
199 		ENABLE_FAKER(); \
200 		return retval; \
201 	}
202 
203 #define VFUNCDEF4(f, at1, a1, at2, a2, at3, a3, at4, a4, fake_f) \
204 	typedef void (*_##f##Type)(at1, at2, at3, at4); \
205 	SYMDEF(f); \
206 	static INLINE void _##f(at1 a1, at2 a2, at3 a3, at4 a4) \
207 	{ \
208 		CHECKSYM(f, fake_f); \
209 		DISABLE_FAKER(); \
210 		__##f(a1, a2, a3, a4); \
211 		ENABLE_FAKER(); \
212 	}
213 
214 #define FUNCDEF5(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
215 	fake_f) \
216 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5); \
217 	SYMDEF(f); \
218 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5) \
219 	{ \
220 		RetType retval; \
221 		CHECKSYM(f, fake_f); \
222 		DISABLE_FAKER(); \
223 		retval = __##f(a1, a2, a3, a4, a5); \
224 		ENABLE_FAKER(); \
225 		return retval; \
226 	}
227 
228 #define VFUNCDEF5(f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, fake_f) \
229 	typedef void (*_##f##Type)(at1, at2, at3, at4, at5); \
230 	SYMDEF(f); \
231 	static INLINE void _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5) \
232 	{ \
233 		CHECKSYM(f, fake_f); \
234 		DISABLE_FAKER(); \
235 		__##f(a1, a2, a3, a4, a5); \
236 		ENABLE_FAKER(); \
237 	}
238 
239 #define VFUNCDEF6(f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, at6, a6, \
240 	fake_f) \
241 	typedef void (*_##f##Type)(at1, at2, at3, at4, at5, at6); \
242 	SYMDEF(f); \
243 	static INLINE void _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6) \
244 	{ \
245 		CHECKSYM(f, fake_f); \
246 		DISABLE_FAKER(); \
247 		__##f(a1, a2, a3, a4, a5, a6); \
248 		ENABLE_FAKER(); \
249 	}
250 
251 #define FUNCDEF6(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
252 	at6, a6, fake_f) \
253 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5, at6); \
254 	SYMDEF(f); \
255 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6) \
256 	{ \
257 		RetType retval; \
258 		CHECKSYM(f, fake_f); \
259 		DISABLE_FAKER(); \
260 		retval = __##f(a1, a2, a3, a4, a5, a6); \
261 		ENABLE_FAKER(); \
262 		return retval; \
263 	}
264 
265 #define VFUNCDEF7(f, at1, a1, at2, a2, at3, a3, at4, a4, at5, at, at6, a6, \
266 	at7, a7, fake_f) \
267 	typedef void (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7); \
268 	SYMDEF(f); \
269 	static INLINE void _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
270 		at7 a7) \
271 	{ \
272 		CHECKSYM(f, fake_f); \
273 		DISABLE_FAKER(); \
274 		__##f(a1, a2, a3, a4, a5, a6, a7); \
275 		ENABLE_FAKER(); \
276 	}
277 
278 #define FUNCDEF8(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
279 	at6, a6, at7, a7, at8, a8, fake_f) \
280 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7, at8); \
281 	SYMDEF(f); \
282 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
283 		at7 a7, at8 a8) \
284 	{ \
285 		RetType retval; \
286 		CHECKSYM(f, fake_f); \
287 		DISABLE_FAKER(); \
288 		retval = __##f(a1, a2, a3, a4, a5, a6, a7, a8); \
289 		ENABLE_FAKER(); \
290 		return retval; \
291 	}
292 
293 #define FUNCDEF9(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
294 	at6, a6, at7, a7, at8, a8, at9, a9, fake_f) \
295 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7, at8, at9); \
296 	SYMDEF(f); \
297 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
298 		at7 a7, at8 a8, at9 a9) \
299 	{ \
300 		RetType retval; \
301 		CHECKSYM(f, fake_f); \
302 		DISABLE_FAKER(); \
303 		retval = __##f(a1, a2, a3, a4, a5, a6, a7, a8, a9); \
304 		ENABLE_FAKER(); \
305 		return retval; \
306 	}
307 
308 #define FUNCDEF10(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
309 	at6, a6, at7, a7, at8, a8, at9, a9, at10, a10, fake_f) \
310 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7, at8, at9, \
311 		at10); \
312 	SYMDEF(f); \
313 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
314 		at7 a7, at8 a8, at9 a9, at10 a10) \
315 	{ \
316 		RetType retval; \
317 		CHECKSYM(f, fake_f); \
318 		DISABLE_FAKER(); \
319 		retval = __##f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
320 		ENABLE_FAKER(); \
321 		return retval; \
322 	}
323 
324 #define VFUNCDEF10(f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, at6, a6, \
325 	at7, a7, at8, a8, at9, a9, at10, a10, fake_f) \
326 	typedef void (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7, at8, at9, \
327 		at10); \
328 	SYMDEF(f); \
329 	static INLINE void _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
330 		at7 a7, at8 a8, at9 a9, at10 a10) \
331 	{ \
332 		CHECKSYM(f, fake_f); \
333 		DISABLE_FAKER(); \
334 		__##f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10); \
335 		ENABLE_FAKER(); \
336 	}
337 
338 #define FUNCDEF12(RetType, f, at1, a1, at2, a2, at3, a3, at4, a4, at5, a5, \
339 	at6, a6, at7, a7, at8, a8, at9, a9, at10, a10, at11, a11, at12, a12, \
340 	fake_f) \
341 	typedef RetType (*_##f##Type)(at1, at2, at3, at4, at5, at6, at7, at8, at9, \
342 		at10, at11, at12); \
343 	SYMDEF(f); \
344 	static INLINE RetType _##f(at1 a1, at2 a2, at3 a3, at4 a4, at5 a5, at6 a6, \
345 		at7 a7, at8 a8, at9 a9, at10 a10, at11 a11, at12 a12) \
346 	{ \
347 		RetType retval; \
348 		CHECKSYM(f, fake_f); \
349 		DISABLE_FAKER(); \
350 		retval = __##f(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12); \
351 		ENABLE_FAKER(); \
352 		return retval; \
353 	}
354 
355 
356 #ifdef __cplusplus
357 extern "C" {
358 #endif
359 
360 
361 // GLX 1.0 functions
362 
363 FUNCDEF3(XVisualInfo *, glXChooseVisual, Display *, dpy, int, screen,
364 	int *, attrib_list, glXChooseVisual)
365 
366 VFUNCDEF4(glXCopyContext, Display *, dpy, GLXContext, src, GLXContext, dst,
367 	unsigned long, mask, glXCopyContext)
368 
369 FUNCDEF4(GLXContext, glXCreateContext, Display *, dpy, XVisualInfo *, vis,
370 	GLXContext, share_list, Bool, direct, glXCreateContext)
371 
372 FUNCDEF3(GLXPixmap, glXCreateGLXPixmap, Display *, dpy, XVisualInfo *, vis,
373 	Pixmap, pixmap, glXCreateGLXPixmap)
374 
375 VFUNCDEF2(glXDestroyContext, Display *, dpy, GLXContext, ctx,
376 	glXDestroyContext)
377 
378 VFUNCDEF2(glXDestroyGLXPixmap, Display *, dpy, GLXPixmap, pix,
379 	glXDestroyGLXPixmap)
380 
381 FUNCDEF4(int, glXGetConfig, Display *, dpy, XVisualInfo *, vis, int, attrib,
382 	int *, value, glXGetConfig)
383 
384 FUNCDEF0(GLXContext, glXGetCurrentContext, glXGetCurrentContext)
385 
386 FUNCDEF0(GLXDrawable, glXGetCurrentDrawable, glXGetCurrentDrawable)
387 
388 FUNCDEF2(Bool, glXIsDirect, Display *, dpy, GLXContext, ctx, glXIsDirect)
389 
390 FUNCDEF3(Bool, glXMakeCurrent, Display *, dpy, GLXDrawable, drawable,
391 	GLXContext, ctx, glXMakeCurrent)
392 
393 FUNCDEF3(Bool, glXQueryExtension, Display *, dpy, int *, error_base,
394 	int *, event_base, glXQueryExtension)
395 
396 FUNCDEF3(Bool, glXQueryVersion, Display *, dpy, int *, major, int *, minor,
397 	glXQueryVersion)
398 
399 VFUNCDEF2(glXSwapBuffers, Display *, dpy, GLXDrawable, drawable,
400 	glXSwapBuffers)
401 
402 VFUNCDEF4(glXUseXFont, Font, font, int, first, int, count, int, list_base,
403 	glXUseXFont)
404 
405 VFUNCDEF0(glXWaitGL, glXWaitGL)
406 
407 
408 // GLX 1.1 functions
409 
410 FUNCDEF2(const char *, glXGetClientString, Display *, dpy, int, name,
411 	glXGetClientString)
412 
413 FUNCDEF3(const char *, glXQueryServerString, Display *, dpy, int, screen, int,
414 	name, glXQueryServerString)
415 
416 FUNCDEF2(const char *, glXQueryExtensionsString, Display *, dpy, int, screen,
417 	glXQueryExtensionsString)
418 
419 
420 // GLX 1.2 functions
421 
422 FUNCDEF0(Display *, glXGetCurrentDisplay, glXGetCurrentDisplay)
423 
424 
425 // GLX 1.3 functions
426 
427 FUNCDEF4(GLXFBConfig *, glXChooseFBConfig, Display *, dpy, int, screen,
428 	const int *, attrib_list, int *, nelements, glXChooseFBConfig)
429 
430 FUNCDEF5(GLXContext, glXCreateNewContext, Display *, dpy, GLXFBConfig, config,
431 	int, render_type, GLXContext, share_list, Bool, direct, glXCreateNewContext)
432 
433 FUNCDEF3(GLXPbuffer, glXCreatePbuffer, Display *, dpy, GLXFBConfig, config,
434 	const int *, attrib_list, glXCreatePbuffer)
435 
436 FUNCDEF4(GLXPixmap, glXCreatePixmap, Display *, dpy, GLXFBConfig, config,
437 	Pixmap, pixmap, const int *, attrib_list, glXCreatePixmap)
438 
439 FUNCDEF4(GLXWindow, glXCreateWindow, Display *, dpy, GLXFBConfig, config,
440 	Window, win, const int *, attrib_list, glXCreateWindow)
441 
442 VFUNCDEF2(glXDestroyPbuffer, Display *, dpy, GLXPbuffer, pbuf,
443 	glXDestroyPbuffer)
444 
445 VFUNCDEF2(glXDestroyPixmap, Display *, dpy, GLXPixmap, pixmap,
446 	glXDestroyPixmap)
447 
448 VFUNCDEF2(glXDestroyWindow, Display *, dpy, GLXWindow, win, glXDestroyWindow)
449 
450 FUNCDEF0(GLXDrawable, glXGetCurrentReadDrawable, glXGetCurrentReadDrawable)
451 
452 FUNCDEF4(int, glXGetFBConfigAttrib, Display *, dpy, GLXFBConfig, config,
453 	int, attribute, int *, value, glXGetFBConfigAttrib)
454 
455 FUNCDEF3(GLXFBConfig *, glXGetFBConfigs, Display *, dpy, int, screen,
456 	int *, nelements, glXGetFBConfigs)
457 
458 VFUNCDEF3(glXGetSelectedEvent, Display *, dpy, GLXDrawable, draw,
459 	unsigned long *, event_mask, glXGetSelectedEvent)
460 
461 FUNCDEF2(XVisualInfo *, glXGetVisualFromFBConfig, Display *, dpy,
462 	GLXFBConfig, config, glXGetVisualFromFBConfig)
463 
464 FUNCDEF4(Bool, glXMakeContextCurrent, Display *, display, GLXDrawable, draw,
465 	GLXDrawable, read, GLXContext, ctx, glXMakeContextCurrent)
466 
467 FUNCDEF4(int, glXQueryContext, Display *, dpy, GLXContext, ctx, int, attribute,
468 	int *, value, glXQueryContext)
469 
470 VFUNCDEF4(glXQueryDrawable, Display *, dpy, GLXDrawable, draw, int, attribute,
471 	unsigned int *, value, glXQueryDrawable)
472 
473 VFUNCDEF3(glXSelectEvent, Display *, dpy, GLXDrawable, draw,
474 	unsigned long, event_mask, glXSelectEvent)
475 
476 
477 // GLX 1.4 functions
478 
479 typedef void (*(*_glXGetProcAddressType)(const GLubyte *))(void);
480 SYMDEF(glXGetProcAddress);
_glXGetProcAddress(const GLubyte * procName)481 static INLINE void (*_glXGetProcAddress(const GLubyte *procName))(void)
482 {
483 	CHECKSYM(glXGetProcAddress, glXGetProcAddress);
484 	return __glXGetProcAddress(procName);
485 }
486 
487 
488 // GLX_ARB_create_context
489 
490 FUNCDEF5(GLXContext, glXCreateContextAttribsARB, Display *, dpy, GLXFBConfig,
491 	config, GLXContext, share_context, Bool, direct, const int *, attribs,
492 	glXCreateContextAttribsARB)
493 
494 
495 // GLX_ARB_get_proc_address
496 
497 typedef void (*(*_glXGetProcAddressARBType)(const GLubyte *))(void);
498 SYMDEF(glXGetProcAddressARB);
_glXGetProcAddressARB(const GLubyte * procName)499 static INLINE void (*_glXGetProcAddressARB(const GLubyte *procName))(void)
500 {
501 	CHECKSYM(glXGetProcAddressARB, glXGetProcAddressARB);
502 	return __glXGetProcAddressARB(procName);
503 }
504 
505 
506 // GLX_EXT_import_context
507 
508 VFUNCDEF2(glXFreeContextEXT, Display *, dpy, GLXContext, ctx,
509 	glXFreeContextEXT)
510 
511 FUNCDEF2(GLXContext, glXImportContextEXT, Display *, dpy,
512 	GLXContextID, contextID, glXImportContextEXT)
513 
514 FUNCDEF4(int, glXQueryContextInfoEXT, Display *, dpy, GLXContext, ctx,
515 	int, attribute, int *, value, glXQueryContextInfoEXT)
516 
517 
518 // GLX_EXT_swap_control
519 
520 VFUNCDEF3(glXSwapIntervalEXT, Display *, dpy, GLXDrawable, drawable, int,
521 	interval, glXSwapIntervalEXT)
522 
523 
524 // GLX_EXT_texture_from_pixmap
525 
526 VFUNCDEF4(glXBindTexImageEXT, Display *, dpy, GLXDrawable, drawable,
527 	int, buffer, const int *, attrib_list, glXBindTexImageEXT)
528 
529 VFUNCDEF3(glXReleaseTexImageEXT, Display *, dpy, GLXDrawable, drawable,
530 	int, buffer, glXReleaseTexImageEXT)
531 
532 
533 // GLX_SGI_swap_control
534 
535 FUNCDEF1(int, glXSwapIntervalSGI, int, interval, glXSwapIntervalSGI)
536 
537 
538 // GLX_SGIX_fbconfig
539 
540 FUNCDEF2(GLXFBConfigSGIX, glXGetFBConfigFromVisualSGIX, Display *, dpy,
541 	XVisualInfo *, vis, glXGetFBConfigFromVisualSGIX)
542 
543 
544 // GL functions
545 
546 VFUNCDEF2(glBindFramebuffer, GLenum, target, GLuint, framebuffer,
547 	glBindFramebuffer)
548 
549 VFUNCDEF2(glBindFramebufferEXT, GLenum, target, GLuint, framebuffer,
550 	glBindFramebufferEXT)
551 
552 VFUNCDEF2(glDeleteFramebuffers, GLsizei, n, const GLuint *, framebuffers,
553 	glDeleteFramebuffers)
554 
555 VFUNCDEF0(glFinish, glFinish)
556 
557 VFUNCDEF0(glFlush, glFlush)
558 
559 VFUNCDEF1(glDrawBuffer, GLenum, drawbuf, glDrawBuffer)
560 
561 VFUNCDEF2(glDrawBuffers, GLsizei, n, const GLenum *, bufs, glDrawBuffers)
562 
563 VFUNCDEF2(glFramebufferDrawBufferEXT, GLuint, framebuffer, GLenum, mode,
564 	glFramebufferDrawBufferEXT)
565 
566 VFUNCDEF3(glFramebufferDrawBuffersEXT, GLuint, framebuffer, GLsizei, n,
567 	const GLenum *, bufs, glFramebufferDrawBuffersEXT)
568 
569 VFUNCDEF2(glFramebufferReadBufferEXT, GLuint, framebuffer, GLenum, mode,
570 	glFramebufferReadBufferEXT)
571 
572 VFUNCDEF2(glGetBooleanv, GLenum, pname, GLboolean *, data, glGetBooleanv)
573 
574 VFUNCDEF2(glGetDoublev, GLenum, pname, GLdouble *, data, glGetDoublev)
575 
576 VFUNCDEF2(glGetFloatv, GLenum, pname, GLfloat *, data, glGetFloatv)
577 
578 VFUNCDEF4(glGetFramebufferAttachmentParameteriv, GLenum, target,
579 	GLenum, attachment, GLenum, pname, GLint *, params,
580 	glGetFramebufferAttachmentParameteriv)
581 
582 VFUNCDEF3(glGetFramebufferParameteriv, GLenum, target, GLenum, pname,
583 	GLint *, params, glGetFramebufferParameteriv)
584 
585 VFUNCDEF2(glGetIntegerv, GLenum, pname, GLint *, params, glGetIntegerv)
586 
587 VFUNCDEF2(glGetInteger64v, GLenum, pname, GLint64 *, data, glGetInteger64v)
588 
589 VFUNCDEF3(glGetNamedFramebufferParameteriv, GLuint, framebuffer,
590 	GLenum, pname, GLint *, param, glGetNamedFramebufferParameteriv)
591 
592 FUNCDEF1(const GLubyte *, glGetString, GLenum, name, glGetString)
593 
594 FUNCDEF2(const GLubyte *, glGetStringi, GLenum, name, GLuint, index,
595 	glGetStringi)
596 
597 VFUNCDEF2(glNamedFramebufferDrawBuffer, GLuint, framebuffer, GLenum, buf,
598 	glNamedFramebufferDrawBuffer)
599 
600 VFUNCDEF3(glNamedFramebufferDrawBuffers, GLuint, framebuffer, GLsizei, n,
601 	const GLenum *, bufs, glNamedFramebufferDrawBuffers)
602 
603 VFUNCDEF2(glNamedFramebufferReadBuffer, GLuint, framebuffer, GLenum, mode,
604 	glNamedFramebufferReadBuffer)
605 
606 VFUNCDEF0(glPopAttrib, glPopAttrib)
607 
608 VFUNCDEF1(glReadBuffer, GLenum, mode, glReadBuffer)
609 
610 VFUNCDEF7(glReadPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height,
611 	GLenum, format, GLenum, type, GLvoid *, pixels, glReadPixels)
612 
613 VFUNCDEF4(glViewport, GLint, x, GLint, y, GLsizei, width, GLsizei, height,
614 	glViewport)
615 
616 
617 #ifdef FAKEOPENCL
618 
619 // OpenCL functions
620 
621 typedef void (*pfn_notifyType)(const char *, const void *, size_t, void *);
622 FUNCDEF6(cl_context, clCreateContext,
623 	const cl_context_properties *, properties, cl_uint, num_devices,
624 	const cl_device_id *, devices, pfn_notifyType, pfn_notify, void *, user_data,
625 	cl_int *, errcode_ret, clCreateContext)
626 
627 #endif
628 
629 
630 // X11 functions
631 
632 FUNCDEF3(Bool, XCheckMaskEvent, Display *, dpy, long, event_mask, XEvent *, xe,
633 	XCheckMaskEvent)
634 
635 FUNCDEF3(Bool, XCheckTypedEvent, Display *, dpy, int, event_type, XEvent *, xe,
636 	XCheckTypedEvent)
637 
638 FUNCDEF4(Bool, XCheckTypedWindowEvent, Display *, dpy, Window, win,
639 	int, event_type, XEvent *, xe, XCheckTypedWindowEvent)
640 
641 FUNCDEF4(Bool, XCheckWindowEvent, Display *, dpy, Window, win, long,
642 	event_mask, XEvent *, xe, XCheckWindowEvent)
643 
644 FUNCDEF1(int, XCloseDisplay, Display *, dpy, XCloseDisplay)
645 
646 FUNCDEF4(int, XConfigureWindow, Display *, dpy, Window, win,
647 	unsigned int, value_mask, XWindowChanges *, values, XConfigureWindow)
648 
649 FUNCDEF10(int, XCopyArea, Display *, dpy, Drawable, src, Drawable, dst, GC, gc,
650 	int, src_x, int, src_y, unsigned int, w, unsigned int, h, int, dest_x,
651 	int, dest_y, XCopyArea)
652 
653 FUNCDEF9(Window, XCreateSimpleWindow, Display *, dpy, Window, parent, int, x,
654 	int, y, unsigned int, width, unsigned int, height, unsigned int,
655 	border_width, unsigned long, border, unsigned long, background,
656 	XCreateSimpleWindow)
657 
658 FUNCDEF12(Window, XCreateWindow, Display *, dpy, Window, parent, int, x,
659 	int, y, unsigned int, width, unsigned int, height,
660 	unsigned int, border_width, int, depth, unsigned int, c_class,
661 	Visual *, visual, unsigned long, value_mask,
662 	XSetWindowAttributes *, attributes, XCreateWindow)
663 
664 FUNCDEF2(int, XDestroySubwindows, Display *, dpy, Window, win,
665 	XDestroySubwindows)
666 
667 FUNCDEF2(int, XDestroyWindow, Display *, dpy, Window, win, XDestroyWindow)
668 
669 FUNCDEF1(int, XFree, void *, data, XFree)
670 
671 FUNCDEF9(Status, XGetGeometry, Display *, display, Drawable, d, Window *, root,
672 	int *, x, int *, y, unsigned int *, width, unsigned int *, height,
673 	unsigned int *, border_width, unsigned int *, depth, XGetGeometry)
674 
675 FUNCDEF8(XImage *, XGetImage, Display *, display, Drawable, d, int, x, int, y,
676 	unsigned int, width, unsigned int, height, unsigned long, plane_mask,
677 	int, format, XGetImage)
678 
679 FUNCDEF2(char **, XListExtensions, Display *, dpy, int *, next,
680 	XListExtensions)
681 
682 FUNCDEF3(int, XMaskEvent, Display *, dpy, long, event_mask, XEvent *, xe,
683 	XMaskEvent)
684 
685 FUNCDEF6(int, XMoveResizeWindow, Display *, dpy, Window, win, int, x, int, y,
686 	unsigned int, width, unsigned int, height, XMoveResizeWindow)
687 
688 FUNCDEF2(int, XNextEvent, Display *, dpy, XEvent *, xe, XNextEvent)
689 
690 FUNCDEF1(Display *, XOpenDisplay, _Xconst char *, name, XOpenDisplay)
691 
692 FUNCDEF6(Display *, XkbOpenDisplay, char *, display_name, int *, event_rtrn,
693 	int *, error_rtrn, int *, major_in_out, int *, minor_in_out,
694 	int *, reason_rtrn, XkbOpenDisplay)
695 
696 FUNCDEF5(Bool, XQueryExtension, Display *, dpy, _Xconst char *, name,
697 	int *, major_opcode, int *, first_event, int *, first_error,
698 	XQueryExtension)
699 
700 FUNCDEF4(int, XResizeWindow, Display *, dpy, Window, win, unsigned int, width,
701 	unsigned int, height, XResizeWindow)
702 
703 FUNCDEF1(char *, XServerVendor, Display *, dpy, XServerVendor)
704 
705 FUNCDEF4(int, XWindowEvent, Display *, dpy, Window, win, long, event_mask,
706 	XEvent *, xe, XWindowEvent)
707 
708 
709 // From dlfaker
710 
711 typedef void *(*_dlopenType)(const char *, int);
712 void *_vgl_dlopen(const char *, int);
713 SYMDEF(dlopen);
714 
715 
716 #ifdef FAKEXCB
717 
718 // XCB functions
719 
720 FUNCDEF2(const xcb_query_extension_reply_t *, xcb_get_extension_data,
721 	xcb_connection_t *, conn, xcb_extension_t *, ext, xcb_get_extension_data)
722 
723 FUNCDEF3(xcb_glx_query_version_cookie_t, xcb_glx_query_version,
724 	xcb_connection_t *, conn, uint32_t, major_version, uint32_t, minor_version,
725 	xcb_glx_query_version)
726 
727 FUNCDEF3(xcb_glx_query_version_reply_t *, xcb_glx_query_version_reply,
728 	xcb_connection_t *, conn, xcb_glx_query_version_cookie_t, cookie,
729 	xcb_generic_error_t **, error, xcb_glx_query_version_reply)
730 
731 FUNCDEF1(xcb_generic_event_t *, xcb_poll_for_event, xcb_connection_t *, conn,
732 	xcb_poll_for_event)
733 
734 FUNCDEF1(xcb_generic_event_t *, xcb_poll_for_queued_event, xcb_connection_t *,
735 	conn, xcb_poll_for_queued_event)
736 
737 FUNCDEF1(xcb_generic_event_t *, xcb_wait_for_event, xcb_connection_t *, conn,
738 	xcb_wait_for_event)
739 
740 #endif
741 
742 
743 // Functions used by the faker (but not interposed.)  We load the GLX/OpenGL
744 // functions dynamically to prevent the 3D application from overriding them, as
745 // well as to ensure that, with 'vglrun -nodl', libGL is not loaded into the
746 // process until the 3D application actually uses it.
747 
748 VFUNCDEF2(glBindBuffer, GLenum, target, GLuint, buffer, NULL)
749 
750 VFUNCDEF2(glBindRenderbuffer, GLenum, target, GLuint, renderbuffer, NULL)
751 
752 VFUNCDEF7(glBitmap, GLsizei, width, GLsizei, height, GLfloat, xorig,
753 	GLfloat, yorig, GLfloat, xmove, GLfloat, ymove, const GLubyte *, bitmap,
754 	NULL)
755 
756 VFUNCDEF10(glBlitFramebuffer, GLint, srcX0, GLint, srcY0, GLint, srcX1,
757 	GLint, srcY1, GLint, dstX0, GLint, dstY0, GLint, dstX1, GLint, dstY1,
758 	GLbitfield, mask, GLenum, filter, NULL)
759 
760 VFUNCDEF4(glBufferData, GLenum, target, GLsizeiptr, size, const GLvoid *, data,
761 	GLenum, usage, NULL)
762 
763 FUNCDEF1(GLenum, glCheckFramebufferStatus, GLenum, target, NULL)
764 
765 VFUNCDEF1(glClear, GLbitfield, mask, NULL)
766 
767 VFUNCDEF4(glClearColor, GLclampf, red, GLclampf, green, GLclampf, blue,
768 	GLclampf, alpha, NULL)
769 
770 VFUNCDEF5(glCopyPixels, GLint, x, GLint, y, GLsizei, width, GLsizei, height,
771 	GLenum, type, NULL)
772 
773 VFUNCDEF2(glDeleteRenderbuffers, GLsizei, n, const GLuint *, renderbuffers,
774 	NULL)
775 
776 VFUNCDEF0(glEndList, NULL)
777 
778 VFUNCDEF4(glFramebufferRenderbuffer, GLenum, target, GLenum, attachment,
779 	GLenum, renderbuffertarget, GLuint, renderbuffer, NULL)
780 
781 VFUNCDEF2(glGenBuffers, GLsizei, n, GLuint *, buffers, NULL)
782 
783 VFUNCDEF2(glGenFramebuffers, GLsizei, n, GLuint *, ids, NULL)
784 
785 VFUNCDEF2(glGenRenderbuffers, GLsizei, n, GLuint *, renderbuffers, NULL)
786 
787 VFUNCDEF3(glGetBufferParameteriv, GLenum, target, GLenum, value, GLint *, data,
788 	NULL)
789 
790 FUNCDEF0(GLenum, glGetError, NULL)
791 
792 VFUNCDEF0(glLoadIdentity, NULL)
793 
794 FUNCDEF2(void *, glMapBuffer, GLenum, target, GLenum, access, NULL)
795 
796 VFUNCDEF1(glMatrixMode, GLenum, mode, NULL)
797 
798 VFUNCDEF2(glNewList, GLuint, list, GLenum, mode, NULL)
799 
800 VFUNCDEF6(glOrtho, GLdouble, left, GLdouble, right, GLdouble, bottom,
801 	GLdouble, top, GLdouble, near_val, GLdouble, far_val, NULL)
802 
803 VFUNCDEF2(glPixelStorei, GLenum, pname, GLint, param, NULL)
804 
805 VFUNCDEF0(glPopMatrix, NULL)
806 
807 VFUNCDEF0(glPushMatrix, NULL)
808 
809 VFUNCDEF2(glRasterPos2i, GLint, x, GLint, y, NULL)
810 
811 VFUNCDEF4(glRenderbufferStorage, GLenum, target, GLenum, internalformat,
812 	GLsizei, width, GLsizei, height, NULL)
813 
814 VFUNCDEF5(glRenderbufferStorageMultisample, GLenum, target, GLsizei, samples,
815 	GLenum, internalformat, GLsizei, width, GLsizei, height, NULL)
816 
817 FUNCDEF1(GLboolean, glUnmapBuffer, GLenum, target, NULL)
818 
819 // EGL functions used by the faker (but not interposed.)
820 
821 #ifdef EGLBACKEND
822 
823 FUNCDEF1(EGLBoolean, eglBindAPI, EGLenum, api, NULL)
824 
825 FUNCDEF4(EGLContext, eglCreateContext, EGLDisplay, display, EGLConfig, config,
826 	EGLContext, share_context, EGLint const *, attrib_list, NULL)
827 
828 FUNCDEF2(EGLBoolean, eglDestroyContext, EGLDisplay, display,
829 	EGLContext, context, NULL)
830 
831 FUNCDEF0(EGLContext, eglGetCurrentContext, NULL)
832 
833 FUNCDEF0(EGLint, eglGetError, NULL)
834 
835 FUNCDEF3(EGLDisplay, eglGetPlatformDisplayEXT, EGLenum, platform, void *,
836 	native_display, const EGLint *, attrib_list, NULL)
837 
838 typedef void (*(*_eglGetProcAddressType)(const char *))(void);
839 SYMDEF(eglGetProcAddress);
_eglGetProcAddress(const char * procName)840 static INLINE void (*_eglGetProcAddress(const char *procName))(void)
841 {
842 	CHECKSYM(eglGetProcAddress, NULL);
843 	return __eglGetProcAddress(procName);
844 }
845 
846 FUNCDEF3(EGLBoolean, eglInitialize, EGLDisplay, display, EGLint *, major,
847 	EGLint *, minor, NULL)
848 
849 FUNCDEF4(EGLBoolean, eglMakeCurrent, EGLDisplay, display, EGLSurface, draw,
850 	EGLSurface, read, EGLContext, context, NULL)
851 
852 FUNCDEF3(EGLBoolean, eglQueryDevicesEXT, EGLint, max_devices, EGLDeviceEXT *,
853 	devices, EGLint *, num_devices, NULL)
854 
855 FUNCDEF2(const char *, eglQueryDeviceStringEXT, EGLDeviceEXT, device, EGLint,
856 	name, NULL)
857 
858 FUNCDEF2(char const *, eglQueryString, EGLDisplay, display, EGLint, name,
859 	NULL)
860 
861 FUNCDEF1(EGLBoolean, eglTerminate, EGLDisplay, display, NULL)
862 
863 #endif
864 
865 // We load all XCB functions dynamically, so that the same VirtualGL binary
866 // can be used to support systems with and without XCB libraries.
867 
868 #ifdef FAKEXCB
869 
870 FUNCDEF1(xcb_connection_t *, XGetXCBConnection, Display *, dpy, NULL)
871 
872 VFUNCDEF2(XSetEventQueueOwner, Display *, dpy, enum XEventQueueOwner, owner,
873 	XSetEventQueueOwner)
874 
875 typedef xcb_extension_t *_xcb_glx_idType;
876 SYMDEF(xcb_glx_id);
_xcb_glx_id(void)877 static INLINE xcb_extension_t *_xcb_glx_id(void)
878 {
879 	CHECKSYM(xcb_glx_id, NULL);
880 	return __xcb_glx_id;
881 }
882 
883 FUNCDEF4(xcb_intern_atom_cookie_t, xcb_intern_atom, xcb_connection_t *, conn,
884 	uint8_t, only_if_exists, uint16_t, name_len, const char *, name, NULL)
885 
886 FUNCDEF3(xcb_intern_atom_reply_t *, xcb_intern_atom_reply, xcb_connection_t *,
887 	conn, xcb_intern_atom_cookie_t, cookie, xcb_generic_error_t **, e, NULL)
888 
889 FUNCDEF1(xcb_key_symbols_t *, xcb_key_symbols_alloc, xcb_connection_t *, c,
890 	NULL)
891 
892 VFUNCDEF1(xcb_key_symbols_free, xcb_key_symbols_t *, syms, NULL)
893 
894 FUNCDEF3(xcb_keysym_t, xcb_key_symbols_get_keysym, xcb_key_symbols_t *, syms,
895 	xcb_keycode_t, keycode, int, col, NULL)
896 
897 #endif
898 
899 #ifdef __cplusplus
900 }
901 #endif
902 
903 
904 #endif  // __FAKER_SYM_H__
905