Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

531 lines
18 KiB

  1. /*
  2. ** Copyright 1995-2095, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. */
  17. /******************************************************************************
  18. AIX
  19. ******************************************************************************/
  20. #if __GLS_PLATFORM_AIX
  21. #pragma alloca
  22. #define __GL_LIB_NAME "libGL.a"
  23. #define __GLS_FAKE_THREAD_LOCAL_STORAGE 1
  24. #define __GLS_GL_DISPATCH 1
  25. #define __GLS_MAX_ALLOCA_BYTES 65536
  26. #define __GLS_PLATFORM "AIX"
  27. #if !__GLS_FAKE_FINITE_FUNC
  28. extern int finite(double);
  29. #define __GLS_FINITE(inDouble) finite(inDouble)
  30. #endif /* !__GLS_FAKE_FINITE_FUNC */
  31. #if !__GLS_FAKE_TRUNCATE_FUNC
  32. #include <unistd.h>
  33. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  34. ftruncate(fileno(inChannel), inByteCount)
  35. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  36. #endif /* __GLS_PLATFORM_AIX */
  37. /******************************************************************************
  38. DECUNIX
  39. ******************************************************************************/
  40. #if __GLS_PLATFORM_DECUNIX
  41. #include <alloca.h>
  42. #include <errno.h>
  43. #define __GL_LIB_NAME "libGL.so"
  44. #define __GLS_GL_DISPATCH 1
  45. #define __GLS_GL_DISPATCH_DSO 1
  46. #define __GLS_INT64 1
  47. #define __GLS_MAX_ALLOCA_BYTES 65536
  48. #define __GLS_OUT_FORMAT_INT64 "%ld"
  49. #define __GLS_OUT_FORMAT_INT64HEX "0x%.16lx"
  50. #define __GLS_OUT_FORMAT_INT64U "%lu"
  51. #define __GLS_PLATFORM "Digital UNIX"
  52. #define __GLS_SPRINTF_INT64 1
  53. #define __GLS_STR_TO_INT64 strtol
  54. #define __GLS_STR_TO_INT64U strtoul
  55. #if !__GLS_FAKE_FINITE_FUNC
  56. #include <math.h>
  57. #define __GLS_FINITE(inDouble) finite(inDouble)
  58. #endif /* !__GLS_FAKE_FINITE_FUNC */
  59. #if !__GLS_FAKE_THREAD_LOCAL_STORAGE
  60. #include <pthread.h>
  61. extern pthread_key_t __gls_contextTLS;
  62. extern __GLScontext* __glsGetContext(void);
  63. #define __GLS_CONTEXT __glsGetContext()
  64. #define __GLS_PUT_CONTEXT(inContext) \
  65. pthread_setspecific(__gls_contextTLS, (pthread_addr_t)inContext)
  66. extern pthread_key_t __gls_errorTLS;
  67. extern GLSenum __glsGetError(void);
  68. #define __GLS_ERROR __glsGetError()
  69. #define __GLS_PUT_ERROR(inError) \
  70. pthread_setspecific(__gls_errorTLS, (pthread_addr_t)inError)
  71. #endif /* !__GLS_FAKE_THREAD_LOCAL_STORAGE */
  72. #if !__GLS_FAKE_TRUNCATE_FUNC
  73. #include <unistd.h>
  74. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  75. ftruncate(fileno(inChannel), inByteCount)
  76. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  77. #define __GLS_ERRNO _Geterrno()
  78. #define __GLS_PUT_ERRNO(inError) _Seterrno(inError)
  79. #endif /* __GLS_PLATFORM_DECUNIX */
  80. /******************************************************************************
  81. HPUX
  82. ******************************************************************************/
  83. #if __GLS_PLATFORM_HPUX
  84. #define __GL_LIB_NAME "libGL.sl"
  85. #define __GLS_FAKE_MUTEX 1
  86. #define __GLS_FAKE_THREAD_LOCAL_STORAGE 1
  87. #define __GLS_GL_DISPATCH 1
  88. #define __GLS_INT64 1
  89. #define __GLS_PLATFORM "HP-UX"
  90. #if !__GLS_FAKE_FINITE_FUNC
  91. extern int finite(double);
  92. #define __GLS_FINITE(inDouble) finite(inDouble)
  93. #endif /* !__GLS_FAKE_FINITE_FUNC */
  94. #if !__GLS_FAKE_TRUNCATE_FUNC
  95. #include <unistd.h>
  96. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  97. ftruncate(fileno(inChannel), inByteCount)
  98. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  99. #endif /* __GLS_PLATFORM_HPUX */
  100. /******************************************************************************
  101. IRIX
  102. ******************************************************************************/
  103. #if __GLS_PLATFORM_IRIX
  104. #include <alloca.h>
  105. #define __GL_LIB_NAME "libGL.so"
  106. #define __GLS_INT64 1
  107. #define __GLS_MAX_ALLOCA_BYTES 65536
  108. #define __GLS_OUT_FORMAT_INT64 "%lld"
  109. #define __GLS_OUT_FORMAT_INT64HEX "0x%.16llx"
  110. #define __GLS_OUT_FORMAT_INT64U "%llu"
  111. #define __GLS_PLATFORM "IRIX"
  112. #define __GLS_SPRINTF_INT64 1
  113. #define __GLS_STR_TO_INT64 strtoll
  114. #define __GLS_STR_TO_INT64U strtoull
  115. extern GLlong strtoll(const char *, char **, int);
  116. extern GLulong strtoull(const char *, char **, int);
  117. #if !__GLS_FAKE_FINITE_FUNC
  118. #include <ieeefp.h>
  119. #define __GLS_FINITE(inDouble) finite(inDouble)
  120. #endif /* !__GLS_FAKE_FINITE_FUNC */
  121. #if !__GLS_FAKE_THREAD_LOCAL_STORAGE
  122. #include "os.h"
  123. #define __GLS_CONTEXT \
  124. (PAGE_ONE->glsContext)
  125. #define __GLS_PUT_CONTEXT(inContext) \
  126. __GLS_CONTEXT = inContext
  127. #define __GLS_ERROR \
  128. (PAGE_ONE->glsError)
  129. #define __GLS_PUT_ERROR(inError) \
  130. __GLS_ERROR = inError
  131. #endif /* !__GLS_FAKE_THREAD_LOCAL_STORAGE */
  132. #if !__GLS_FAKE_TRUNCATE_FUNC
  133. #include <sys/types.h>
  134. extern int fileno(FILE *inChannel);
  135. extern int ftruncate(int, off_t);
  136. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  137. ftruncate(fileno(inChannel), (off_t)inByteCount)
  138. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  139. extern GLint oserror(void);
  140. #define __GLS_ERRNO oserror()
  141. extern GLint setoserror(GLint inError);
  142. #define __GLS_PUT_ERRNO(inError) setoserror(inError)
  143. #endif /* __GLS_PLATFORM_IRIX */
  144. /******************************************************************************
  145. LINUX
  146. ******************************************************************************/
  147. #if __GLS_PLATFORM_LINUX
  148. #include <alloca.h>
  149. #define __GL_LIB_NAME "libGL.so"
  150. #define __GLS_GL_DISPATCH 1
  151. #define __GLS_GL_DISPATCH_DSO 1
  152. #define __GLS_INT64 1
  153. #define __GLS_OUT_FORMAT_INT64 "%qd"
  154. #define __GLS_OUT_FORMAT_INT64HEX "0x%.16qx"
  155. #define __GLS_OUT_FORMAT_INT64U "%qu"
  156. #define __GLS_MAX_ALLOCA_BYTES 65536
  157. #define __GLS_PLATFORM "Linux"
  158. #define __GLS_POSIX_THREADS 0
  159. #define __GLS_SPRINTF_INT64 1
  160. #define __GLS_STR_TO_INT64 strtoq
  161. #define __GLS_STR_TO_INT64U strtouq
  162. extern GLlong strtoq(const char *, char **, int);
  163. extern GLulong strtouq(const char *, char **, int);
  164. #if !__GLS_FAKE_FINITE_FUNC
  165. #include <math.h>
  166. #define __GLS_FINITE(inDouble) __finite(inDouble)
  167. #endif /* !__GLS_FAKE_FINITE_FUNC */
  168. #if !__GLS_FAKE_TRUNCATE_FUNC
  169. extern int fileno(FILE *inChannel);
  170. extern int ftruncate(int, size_t);
  171. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  172. ftruncate(fileno(inChannel), inByteCount)
  173. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  174. #if !__GLS_POSIX_THREADS
  175. #define __GLS_FAKE_MUTEX 1
  176. #define __GLS_FAKE_THREAD_LOCAL_STORAGE 1
  177. #endif /* !__GLS_POSIX_THREADS */
  178. #endif /* __GLS_PLATFORM_LINUX */
  179. /******************************************************************************
  180. SOLARIS
  181. ******************************************************************************/
  182. #if __GLS_PLATFORM_SOLARIS
  183. #include <errno.h>
  184. #define __GL_LIB_NAME "libGL.so"
  185. #define __GLS_GL_DISPATCH 1
  186. #define __GLS_GL_DISPATCH_DSO 1
  187. #define __GLS_INT64 1
  188. #define __GLS_INT64_TO_STR lltostr
  189. #define __GLS_INT64U_TO_STR ulltostr
  190. #define __GLS_PLATFORM "Solaris"
  191. #define __GLS_STR_TO_INT64 strtoll
  192. #define __GLS_STR_TO_INT64U strtoull
  193. extern char *lltostr(GLlong, char *);
  194. extern char *ulltostr(GLulong, char *);
  195. extern GLlong strtoll(const char *, char **, int);
  196. extern GLulong strtoull(const char *, char **, int);
  197. #if !__GLS_FAKE_FINITE_FUNC
  198. extern int finite(double);
  199. #define __GLS_FINITE(inDouble) finite(inDouble)
  200. #endif /* !__GLS_FAKE_FINITE_FUNC */
  201. #if !__GLS_FAKE_THREAD_LOCAL_STORAGE
  202. #include <thread.h>
  203. extern thread_key_t __gls_contextTLS;
  204. extern __GLScontext* __glsGetContext(void);
  205. #define __GLS_CONTEXT __glsGetContext()
  206. #define __GLS_PUT_CONTEXT(inContext) \
  207. thr_setspecific(__gls_contextTLS, inContext)
  208. extern thread_key_t __gls_errorTLS;
  209. extern GLSenum __glsGetError(void);
  210. #define __GLS_ERROR __glsGetError()
  211. #define __GLS_PUT_ERROR(inError) \
  212. thr_setspecific(__gls_errorTLS, (void *)inError)
  213. #endif /* !__GLS_FAKE_THREAD_LOCAL_STORAGE */
  214. #if !__GLS_FAKE_TRUNCATE_FUNC
  215. #include <unistd.h>
  216. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  217. ftruncate(fileno(inChannel), inByteCount)
  218. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  219. #endif /* __GLS_PLATFORM_SOLARIS */
  220. /******************************************************************************
  221. WIN32
  222. ******************************************************************************/
  223. #if __GLS_PLATFORM_WIN32
  224. #pragma warning(disable:4769)
  225. #include <excpt.h>
  226. #include <malloc.h>
  227. #include <winbase.h>
  228. #define __GL_LIB_NAME "opengl32.dll"
  229. #define __GLS_GL_DISPATCH 1
  230. #define __GLS_INT64 1
  231. #define __GLS_MAX_ALLOCA_BYTES 65536
  232. #define __GLS_OUT_FORMAT_INT64 "%I64d"
  233. #define __GLS_OUT_FORMAT_INT64HEX "0x%.16I64x"
  234. #define __GLS_OUT_FORMAT_INT64U "%I64u"
  235. #define __GLS_PLATFORM "Win32"
  236. #define __GLS_SINGLE_NULL_COMMAND_FUNC 0
  237. #define __GLS_SPRINTF_INT64 1
  238. #define __GLS_STR_TO_INT64 __gls_strtoi64
  239. #define __GLS_STR_TO_INT64U __gls_strtoui64
  240. #define __GLS_DEC_ALLOC_BIN(inParam, inType, inByteCount) \
  241. if (inByteCount <= __GLS_MAX_ALLOCA_BYTES) __try { \
  242. inParam = (inType *)_alloca(inByteCount); \
  243. } __except(EXCEPTION_CONTINUE_EXECUTION) {} \
  244. if (!inParam) { \
  245. inParam = (inType *)__glsMalloc(inByteCount); \
  246. inParam##_malloc = GL_TRUE; \
  247. }
  248. #define __GLS_DEC_ALLOC_TEXT(inoutReader, inParam, inType, inByteCount) \
  249. if (inByteCount <= __GLS_MAX_ALLOCA_BYTES) __try { \
  250. inParam = (inType *)_alloca(inByteCount); \
  251. } __except(EXCEPTION_CONTINUE_EXECUTION) {} \
  252. if (!inParam) { \
  253. inParam = (inType *)__glsReader_allocCallBuf( \
  254. inoutReader, inByteCount \
  255. ); \
  256. inParam##_malloc = GL_TRUE; \
  257. }
  258. extern GLlong __gls_strtoi64(const char *, char **, int);
  259. extern GLulong __gls_strtoui64(const char *, char **, int);
  260. #if !__GLS_FAKE_FINITE_FUNC
  261. #include <float.h>
  262. #define __GLS_FINITE(inDouble) _finite(inDouble)
  263. #endif /* !__GLS_FAKE_FINITE_FUNC */
  264. #if !__GLS_FAKE_THREAD_LOCAL_STORAGE
  265. extern GLint __gls_contextTLS;
  266. #define __GLS_CONTEXT \
  267. ((__GLScontext *)TlsGetValue(__gls_contextTLS))
  268. #define __GLS_PUT_CONTEXT(inContext) \
  269. TlsSetValue(__gls_contextTLS, inContext)
  270. extern GLint __gls_errorTLS;
  271. #define __GLS_ERROR \
  272. ((GLSenum)((ULONG_PTR)TlsGetValue(__gls_errorTLS)))
  273. #define __GLS_PUT_ERROR(inError) \
  274. TlsSetValue(__gls_errorTLS, (GLvoid *)inError)
  275. #endif /* !__GLS_FAKE_THREAD_LOCAL_STORAGE */
  276. #if !__GLS_FAKE_TRUNCATE_FUNC
  277. #include <io.h>
  278. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) \
  279. _chsize(_fileno(inChannel), inByteCount)
  280. #endif /* !__GLS_FAKE_TRUNCATE_FUNC */
  281. #endif /* __GLS_PLATFORM_WIN32 */
  282. /******************************************************************************
  283. Default definitions
  284. ******************************************************************************/
  285. #if !defined(__GLS_CHECKSUM_BUF_BYTES)
  286. #define __GLS_CHECKSUM_BUF_BYTES 4096
  287. #endif /* !defined(__GLS_CHECKSUM_BUF_BYTES) */
  288. #if !defined(__GLS_CONTEXT_STREAM_BLOCK_BYTES)
  289. #define __GLS_CONTEXT_STREAM_BLOCK_BYTES 65536
  290. #endif /* !defined(__GLS_CONTEXT_STREAM_BLOCK_BYTES) */
  291. #if !defined(__GLS_READER_BUF_BYTES)
  292. #define __GLS_READER_BUF_BYTES 16384
  293. #endif /* !defined(__GLS_READER_BUF_BYTES) */
  294. #if !defined(__GLS_PLATFORM)
  295. #define __GLS_PLATFORM "Unknown"
  296. #endif /* !defined(__GLS_PLATFORM) */
  297. #if !defined(__GLS_RELEASE)
  298. #define __GLS_RELEASE "Unknown"
  299. #endif /* !defined(__GLS_RELEASE) */
  300. #if !defined(__GLS_SINGLE_NULL_COMMAND_FUNC)
  301. #define __GLS_SINGLE_NULL_COMMAND_FUNC 1
  302. #endif /* !defined(__GLS_SINGLE_NULL_COMMAND_FUNC) */
  303. #if !defined(__GLS_VENDOR)
  304. #define __GLS_VENDOR "ARB"
  305. #endif /* !defined(__GLS_VENDOR) */
  306. #if !defined(__GLS_WRITER_EXTERN_BUF_BYTES)
  307. #define __GLS_WRITER_EXTERN_BUF_BYTES 16384
  308. #endif /* !defined(__GLS_WRIER_EXTERN_BUF_BYTES) */
  309. #if !defined(__GLS_WRITER_EXTERN_BUF_SLOP)
  310. #define __GLS_WRITER_EXTERN_BUF_SLOP 256
  311. #endif /* !defined(__GLS_WRITER_EXTERN_BUF_SLOP) */
  312. #if !defined(__GLS_ERRNO)
  313. #define __GLS_ERRNO errno
  314. #endif /* !defined(__GLS_ERRNO) */
  315. #if !defined(__GLS_PUT_ERRNO)
  316. #define __GLS_PUT_ERRNO(inError) errno = inError
  317. #endif /* !defined(__GLS_PUT_ERRNO) */
  318. /******************************************************************************
  319. Required platform-specific functions
  320. ******************************************************************************/
  321. extern void __glsBeginCriticalSection(void);
  322. extern void __glsEndCriticalSection(void);
  323. extern void __glsUpdateDispatchTables(void);
  324. #ifndef __GLS_PLATFORM_WIN32
  325. // DrewB
  326. extern void __glsBeginCaptureExec(GLSopcode inOpcode);
  327. extern void __glsEndCaptureExec(GLSopcode inOpcode);
  328. #define __GLS_BEGIN_CAPTURE_EXEC(ctx, op) __glsBeginCaptureExec(op)
  329. #define __GLS_END_CAPTURE_EXEC(ctx, op) __glsEndCaptureExec(op)
  330. #else
  331. extern void __glsBeginCaptureExec(__GLScontext *ctx, GLSopcode inOpcode);
  332. extern void __glsEndCaptureExec(__GLScontext *ctx, GLSopcode inOpcode);
  333. #define __GLS_BEGIN_CAPTURE_EXEC(ctx, op) __glsBeginCaptureExec(ctx, op)
  334. #define __GLS_END_CAPTURE_EXEC(ctx, op) __glsEndCaptureExec(ctx, op)
  335. #endif
  336. /******************************************************************************
  337. Alloca
  338. ******************************************************************************/
  339. #if defined(__GLS_MAX_ALLOCA_BYTES)
  340. #define __GLS_DEC_ALLOC_DECLARE(inParam) \
  341. GLboolean inParam##_malloc = GL_FALSE;
  342. #if !defined(__GLS_DEC_ALLOC_BIN)
  343. #define __GLS_DEC_ALLOC_BIN(inParam, inType, inByteCount) \
  344. if (inByteCount <= __GLS_MAX_ALLOCA_BYTES) { \
  345. inParam = (inType *)alloca(inByteCount); \
  346. } \
  347. if (!inParam) { \
  348. inParam = (inType *)__glsMalloc(inByteCount); \
  349. inParam##_malloc = GL_TRUE; \
  350. }
  351. #endif /* !defined(__GLS_DEC_ALLOC_BIN) */
  352. #if !defined(__GLS_DEC_ALLOC_TEXT)
  353. #define __GLS_DEC_ALLOC_TEXT( \
  354. inoutReader, inParam, inType, inByteCount \
  355. ) \
  356. if (inByteCount <= __GLS_MAX_ALLOCA_BYTES) { \
  357. inParam = (inType *)alloca(inByteCount); \
  358. } \
  359. if (!inParam) { \
  360. inParam = (inType *)__glsReader_allocCallBuf( \
  361. inoutReader, inByteCount \
  362. ); \
  363. inParam##_malloc = GL_TRUE; \
  364. }
  365. #endif /* !defined(__GLS_DEC_ALLOC_TEXT) */
  366. #define __GLS_DEC_FREE(inParam) \
  367. if (inParam##_malloc) free(inParam)
  368. #else /* !defined(__GLS_MAX_ALLOCA_BYTES) */
  369. #define __GLS_DEC_ALLOC_DECLARE(inParam)
  370. #define __GLS_DEC_ALLOC_BIN(inParam, inType, inByteCount) \
  371. inParam = (inType *)__glsMalloc(inByteCount)
  372. #define __GLS_DEC_ALLOC_TEXT(inoutReader, inParam, inType, inByteCount) \
  373. inParam = (inType *)__glsReader_allocCallBuf(inoutReader, inByteCount)
  374. #define __GLS_DEC_FREE(inParam) \
  375. free(inParam)
  376. #endif /* defined(__GLS_MAX_ALLOCA_BYTES) */
  377. /******************************************************************************
  378. POSIX threads
  379. ******************************************************************************/
  380. #if __GLS_POSIX_THREADS
  381. #if !__GLS_FAKE_THREAD_LOCAL_STORAGE
  382. #include <pthread.h>
  383. extern pthread_key_t __gls_contextTLS;
  384. extern __GLScontext* __glsGetContext(void);
  385. #define __GLS_CONTEXT __glsGetContext()
  386. #define __GLS_PUT_CONTEXT(inContext) \
  387. pthread_setspecific(__gls_contextTLS, inContext)
  388. extern pthread_key_t __gls_errorTLS;
  389. extern GLSenum __glsGetError(void);
  390. #define __GLS_ERROR __glsGetError()
  391. #define __GLS_PUT_ERROR(inError) \
  392. pthread_setspecific(__gls_errorTLS, (GLvoid *)inError)
  393. #endif /* !__GLS_FAKE_THREAD_LOCAL_STORAGE */
  394. #endif /* __GLS_POSIX_THREADS */
  395. /******************************************************************************
  396. Fake finite function
  397. ******************************************************************************/
  398. #if __GLS_FAKE_FINITE_FUNC
  399. #define __GLS_FINITE(inDouble) GL_TRUE
  400. #endif /* __GLS_FAKE_FINITE_FUNC */
  401. /******************************************************************************
  402. Fake thread-local storage
  403. ******************************************************************************/
  404. #if __GLS_FAKE_THREAD_LOCAL_STORAGE
  405. extern __GLScontext *__gls_context;
  406. #define __GLS_CONTEXT \
  407. __gls_context
  408. #define __GLS_PUT_CONTEXT(inContext) \
  409. __gls_context = inContext
  410. extern GLSenum __gls_error;
  411. #define __GLS_ERROR \
  412. __gls_error
  413. #define __GLS_PUT_ERROR(inError) \
  414. __gls_error = inError
  415. #endif /* __GLS_FAKE_THREAD_LOCAL_STORAGE */
  416. /******************************************************************************
  417. Fake truncate function
  418. ******************************************************************************/
  419. #if __GLS_FAKE_TRUNCATE_FUNC
  420. #define __GLS_TRUNCATE_EXTERN(inChannel, inByteCount) -1
  421. #endif /* __GLS_FAKE_TRUNCATE_FUNC */
  422. /*****************************************************************************/