source: trunk/src/kernel32/wintls.cpp@ 2007

Last change on this file since 2007 was 1898, checked in by sandervl, 26 years ago

compilation fixes

File size: 5.4 KB
Line 
1/* $Id: wintls.cpp,v 1.8 1999-11-30 20:19:34 sandervl Exp $ */
2/*
3 * Win32 TLS API functions
4 *
5 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
6 *
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11#include <os2win.h>
12#include <string.h>
13#include <winimagebase.h>
14#include <thread.h>
15#include <wprocess.h>
16#include "exceptutil.h"
17
18//******************************************************************************
19//******************************************************************************
20void Win32ImageBase::tlsAlloc() //Allocate TLS index for this module
21{
22 if(!tlsAddress)
23 return;
24
25 tlsIndex = TlsAlloc();
26 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
27 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
28 DebugInt3();
29 return;
30 }
31 dprintf(("Win32ImageBase::tlsAlloc (%d) for module %x", tlsIndex, hinstance));
32}
33//******************************************************************************
34//******************************************************************************
35void Win32ImageBase::tlsDelete() //Free TLS index for this module
36{
37 if(!tlsAddress)
38 return;
39
40 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
41 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
42 DebugInt3();
43 return;
44 }
45 dprintf(("Win32ImageBase::tlsDestroy (%d) for module %x", tlsIndex, hinstance));
46 TlsFree(tlsIndex);
47 tlsIndex = -1;
48}
49//******************************************************************************
50//******************************************************************************
51void Win32ImageBase::tlsAttachThread() //setup TLS structures for new thread
52{
53 EXCEPTION_FRAME exceptFrame;
54 PIMAGE_TLS_CALLBACK *pCallback;
55 TEB *winteb;
56 char *tibmem;
57
58 if(!tlsAddress)
59 return;
60
61 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
62 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
63 DebugInt3();
64 return;
65 }
66
67 dprintf(("Win32ImageBase::tlsAttachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
68 dprintf(("tlsAddress: %x", tlsAddress));
69 dprintf(("tlsInitSize: %x", tlsInitSize));
70 dprintf(("tlsTotalSize %x", tlsTotalSize));
71 dprintf(("tlsIndexAddr %x", tlsIndexAddr));
72 dprintf(("tlsCallbackAddr %x", tlsCallBackAddr));
73 dprintf(("*tlsCallbackAddr %x", (tlsCallBackAddr) ? *tlsCallBackAddr : 0));
74 tibmem = (char *)VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
75 if(tibmem == NULL) {
76 dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
77 DebugInt3();
78 return;
79 }
80 memset(tibmem, 0, tlsTotalSize);
81 memcpy(tibmem, tlsAddress, tlsInitSize);
82
83 winteb = (TEB *)*TIBFlatPtr;
84 winteb->tls_ptr[tlsIndex] = tibmem;
85 *tlsIndexAddr = tlsIndex;
86
87 if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
88 pCallback = tlsCallBackAddr;
89 while(*pCallback) {
90 dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
91
92 (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
93
94 dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
95 *pCallback++;
96 }
97 }
98 return;
99}
100//******************************************************************************
101//******************************************************************************
102void Win32ImageBase::tlsDetachThread() //destroy TLS structures
103{
104 EXCEPTION_FRAME exceptFrame;
105 PIMAGE_TLS_CALLBACK *pCallback;
106 TEB *winteb;
107
108 if(!tlsAddress)
109 return;
110
111 dprintf(("Win32ImageBase::tlsDetachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
112
113 if(tlsCallBackAddr && (ULONG)*tlsCallBackAddr != 0) {
114 pCallback = tlsCallBackAddr;
115 while(*pCallback) {
116 dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
117
118 (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
119
120 dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
121 *pCallback++;
122 }
123 }
124 winteb = (TEB *)*TIBFlatPtr;
125 VirtualFree(winteb->tls_ptr[tlsIndex], tlsTotalSize, MEM_RELEASE);
126 winteb->tls_ptr[tlsIndex] = 0;
127}
128//******************************************************************************
129//******************************************************************************
130
131//******************************************************************************
132//******************************************************************************
133DWORD WIN32API TlsAlloc()
134{
135 dprintf(("KERNEL32: TlsAlloc\n"));
136 return(O32_TlsAlloc());
137}
138//******************************************************************************
139//******************************************************************************
140BOOL WIN32API TlsFree(DWORD index)
141{
142 dprintf(("KERNEL32: TlsFree\n"));
143 return(O32_TlsFree(index));
144}
145//******************************************************************************
146//******************************************************************************
147LPVOID WIN32API TlsGetValue(DWORD index)
148{
149 LPVOID rc;
150
151 rc = O32_TlsGetValue(index);
152// dprintf(("KERNEL32: TlsGetValue %d returned %X\n", index, rc));
153 return(rc);
154}
155//******************************************************************************
156//******************************************************************************
157BOOL WIN32API TlsSetValue(DWORD index, LPVOID val)
158{
159// dprintf(("KERNEL32: TlsSetValue\n"));
160 return(O32_TlsSetValue(index, val));
161}
162//******************************************************************************
163//******************************************************************************
Note: See TracBrowser for help on using the repository browser.