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.

92 lines
2.9 KiB

  1. /***
  2. *tlssup.c - Thread Local Storage run-time support module
  3. *
  4. * Copyright (c) 1993-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *
  8. *Revision History:
  9. * 03-19-93 SKS Original Version from Chuck Mitchell
  10. * 11-16-93 GJF Enclosed in #ifdef _MSC_VER
  11. * 02-17-94 SKS Add "const" to declaration of _tls_used
  12. * to work around problems with MIPS compiler.
  13. * Also added a canonical file header comment.
  14. * 09-01-94 SKS Change include file from <nt.h> to <windows.h>
  15. * 03-04-98 JWM Modified for WIN64 - uses _IMAGE_TLS_DIRECTORY64
  16. * 04-03-98 JWM _tls_start & _tls_end are no longer initialized.
  17. * 01-21-99 GJF Added a couple ULONGLONG casts.
  18. * 04-28-99 PML Wrap __declspec(allocate()) in _CRTALLOC macro.
  19. * 09-06-00 PML _tls_start/_tls_end can be 1 byte long (vs7#154062)
  20. * 03-24-01 PML callback array starts at __xl_a+1, not __xl_a.
  21. * 07-15-01 PML Remove all ALPHA, MIPS, and PPC code
  22. *
  23. ****/
  24. #ifdef _MSC_VER
  25. #include <sect_attribs.h>
  26. #include <windows.h>
  27. /* Thread Local Storage index for this .EXE or .DLL */
  28. ULONG _tls_index = 0;
  29. /* Special symbols to mark start and end of Thread Local Storage area. */
  30. #pragma data_seg(".tls")
  31. _CRTALLOC(".tls") char _tls_start = 0;
  32. #pragma data_seg(".tls$ZZZ")
  33. _CRTALLOC(".tls$ZZZ") char _tls_end = 0;
  34. /* Start and end sections for Threadl Local Storage CallBack Array.
  35. * Actual array is constructed using .CRT$XLA, .CRT$XLC, .CRT$XLL,
  36. * .CRT$XLU, .CRT$XLZ similar to the way global
  37. * static initializers are done for C++.
  38. */
  39. #pragma data_seg(".CRT$XLA")
  40. _CRTALLOC(".CRT$XLA") PIMAGE_TLS_CALLBACK __xl_a = 0;
  41. #pragma data_seg(".CRT$XLZ")
  42. _CRTALLOC(".CRT$XLZ") PIMAGE_TLS_CALLBACK __xl_z = 0;
  43. #pragma data_seg(".rdata$T")
  44. #ifndef IMAGE_SCN_SCALE_INDEX
  45. #define IMAGE_SCN_SCALE_INDEX 0x00000001 // Tls index is scaled
  46. #endif
  47. #ifdef _WIN64
  48. __declspec(allocate(".rdata$T")) const IMAGE_TLS_DIRECTORY64 _tls_used =
  49. {
  50. (ULONGLONG) &_tls_start, // start of tls data
  51. (ULONGLONG) &_tls_end, // end of tls data
  52. (ULONGLONG) &_tls_index, // address of tls_index
  53. (ULONGLONG) (&__xl_a+1), // pointer to call back array
  54. (ULONG) 0, // size of tls zero fill
  55. (ULONG) 0 // characteristics
  56. };
  57. #else
  58. const IMAGE_TLS_DIRECTORY _tls_used =
  59. {
  60. (ULONG)(ULONG_PTR) &_tls_start, // start of tls data
  61. (ULONG)(ULONG_PTR) &_tls_end, // end of tls data
  62. (ULONG)(ULONG_PTR) &_tls_index, // address of tls_index
  63. (ULONG)(ULONG_PTR) (&__xl_a+1), // pointer to call back array
  64. (ULONG) 0, // size of tls zero fill
  65. (ULONG) 0 // characteristics
  66. };
  67. #endif
  68. #endif /* _MSC_VER */