/src/FreeRDP/winpr/libwinpr/nt/nt.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /**  | 
2  |  |  * WinPR: Windows Portable Runtime  | 
3  |  |  * Windows Native System Services  | 
4  |  |  *  | 
5  |  |  * Copyright 2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>  | 
6  |  |  * Copyright 2013 Thincast Technologies GmbH  | 
7  |  |  * Copyright 2013 Norbert Federa <norbert.federa@thincast.com>  | 
8  |  |  *  | 
9  |  |  * Licensed under the Apache License, Version 2.0 (the "License");  | 
10  |  |  * you may not use this file except in compliance with the License.  | 
11  |  |  * You may obtain a copy of the License at  | 
12  |  |  *  | 
13  |  |  *     http://www.apache.org/licenses/LICENSE-2.0  | 
14  |  |  *  | 
15  |  |  * Unless required by applicable law or agreed to in writing, software  | 
16  |  |  * distributed under the License is distributed on an "AS IS" BASIS,  | 
17  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
18  |  |  * See the License for the specific language governing permissions and  | 
19  |  |  * limitations under the License.  | 
20  |  |  */  | 
21  |  |  | 
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  | 0  | { | 
46  | 0  |   free(teb);  | 
47  | 0  | }  | 
48  |  |  | 
49  |  | static void sTebInitOnce(void)  | 
50  | 5  | { | 
51  | 5  |   pthread_key_create(&sTebKey, sTebDestruct);  | 
52  | 5  | }  | 
53  |  |  | 
54  |  | PTEB NtCurrentTeb(void)  | 
55  | 135k  | { | 
56  | 135k  |   PTEB teb = NULL;  | 
57  |  |  | 
58  | 135k  |   if (pthread_once(&sTebOnceControl, sTebInitOnce) == 0)  | 
59  | 135k  |   { | 
60  | 135k  |     if ((teb = pthread_getspecific(sTebKey)) == NULL)  | 
61  | 5  |     { | 
62  | 5  |       teb = calloc(1, sizeof(TEB));  | 
63  | 5  |       if (teb)  | 
64  | 5  |         pthread_setspecific(sTebKey, teb);  | 
65  | 5  |     }  | 
66  | 135k  |   }  | 
67  | 135k  |   return teb;  | 
68  | 135k  | }  | 
69  |  | #endif  |