FreeRDP
nt.c
1 
22 #include <winpr/assert.h>
23 #include <winpr/config.h>
24 
25 #include <winpr/crt.h>
26 #include <winpr/library.h>
27 #include <winpr/wlog.h>
28 #include <winpr/nt.h>
29 #include <winpr/endian.h>
30 
31 #include "../log.h"
32 #define TAG WINPR_TAG("nt")
33 
34 #ifndef _WIN32
35 
36 #include <pthread.h>
37 #include <winpr/crt.h>
38 
39 #include "../handle/handle.h"
40 
41 static pthread_once_t sTebOnceControl = PTHREAD_ONCE_INIT;
42 static pthread_key_t sTebKey;
43 
44 static void sTebDestruct(void* teb)
45 {
46  free(teb);
47 }
48 
49 static void sTebInitOnce(void)
50 {
51  pthread_key_create(&sTebKey, sTebDestruct);
52 }
53 
54 PTEB NtCurrentTeb(void)
55 {
56  PTEB teb = NULL;
57 
58  if (pthread_once(&sTebOnceControl, sTebInitOnce) == 0)
59  {
60  if ((teb = pthread_getspecific(sTebKey)) == NULL)
61  {
62  teb = calloc(1, sizeof(TEB));
63  if (teb)
64  pthread_setspecific(sTebKey, teb);
65  }
66  }
67  return teb;
68 }
69 #endif