summaryrefslogtreecommitdiff
path: root/src/inc/tls.h
blob: 94f5574905ed83227bedf1ee185902eb059cb6cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
// TLS.H -
//

//
// Encapsulates TLS access for maximum performance. 
//



#ifndef __tls_h__
#define __tls_h__

#ifdef FEATURE_IMPLICIT_TLS
#ifdef _WIN64
#define OFFSETOF__TLS__tls_CurrentThread            0x08
#define OFFSETOF__TLS__tls_EETlsData                0x18
#else
#define OFFSETOF__TLS__tls_CurrentThread            0x04
#define OFFSETOF__TLS__tls_EETlsData                0x0c
#endif // _WIN64

#ifdef _TARGET_WIN64_
#define WINNT_OFFSETOF__TEB__ThreadLocalStoragePointer  0x58
#else
#define WINNT_OFFSETOF__TEB__ThreadLocalStoragePointer  0x2c
#endif

#endif // FEATURE_IMPLICIT_TLS

// Pointer to a function that retrieves the TLS data for a specific index.
typedef LPVOID (*POPTIMIZEDTLSGETTER)();

//---------------------------------------------------------------------------
// Creates a platform-optimized version of TlsGetValue compiled
// for a particular index. Can return NULL - the caller should substitute
// a non-optimized getter in this case.
//---------------------------------------------------------------------------
POPTIMIZEDTLSGETTER MakeOptimizedTlsGetter(DWORD tlsIndex, LPVOID pBuffer = NULL, SIZE_T cbBuffer = 0, POPTIMIZEDTLSGETTER pGenericImpl = NULL, BOOL fForceGeneric = FALSE);


//---------------------------------------------------------------------------
// Frees a function created by MakeOptimizedTlsGetter().
//---------------------------------------------------------------------------
VOID FreeOptimizedTlsGetter(POPTIMIZEDTLSGETTER pOptimizedTlsGetter);



//---------------------------------------------------------------------------
// For ASM stub generators that want to inline Thread access for efficiency,
// the Thread manager uses these constants to define how to access the Thread.
//---------------------------------------------------------------------------
enum TLSACCESSMODE {
   TLSACCESS_GENERIC    = 1,   // Make no platform assumptions: use the API
   // TLS
   TLSACCESS_WNT        = 2,   // WinNT-style TLS
   TLSACCESS_WNT_HIGH   = 3,   // WinNT5-style TLS, slot > TLS_MINIMUM_AVAILABLE
};


//---------------------------------------------------------------------------
// WinNT store the TLS in different places relative to the
// fs:[0]. This api reveals which. Can also return TLSACCESS_GENERIC if
// no info is available about the Thread location (you have to use the TlsGetValue
// api.) This is intended for use by stub generators that want to inline TLS
// access.
//---------------------------------------------------------------------------
TLSACCESSMODE GetTLSAccessMode(DWORD tlsIndex);   

#endif // __tls_h__