source: trunk/src/kernel32/old/wintls.cpp@ 2016

Last change on this file since 2016 was 955, checked in by sandervl, 26 years ago

Backup copy of old kernel32

File size: 5.6 KB
Line 
1/* $Id: wintls.cpp,v 1.1 1999-09-15 23:33:02 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 <winimage.h>
13#include <thread.h>
14#include <wprocess.h>
15#include <except.h>
16#include "exceptutil.h"
17
18//******************************************************************************
19//******************************************************************************
20void Win32Image::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(("Win32Image::tlsAlloc (%d) for module %x", tlsIndex, hinstance));
32}
33//******************************************************************************
34//******************************************************************************
35void Win32Image::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(("Win32Image::tlsDestroy (%d) for module %x", tlsIndex, hinstance));
46 TlsFree(tlsIndex);
47 tlsIndex = -1;
48}
49//******************************************************************************
50//******************************************************************************
51void Win32Image::tlsAttachThread() //setup TLS structures for new thread
52{
53 EXCEPTION_FRAME exceptFrame;
54 PIMAGE_TLS_CALLBACK *pCallback;
55 USHORT sel;
56 TEB *winteb;
57 char *tibmem;
58
59 if(!tlsAddress)
60 return;
61
62 if(tlsIndex >= TLS_MINIMUM_AVAILABLE) {
63 dprintf(("tlsAttachThread: invalid tlsIndex %x!!!!", tlsIndex));
64 DebugInt3();
65 return;
66 }
67
68 dprintf(("Win32Image::tlsAttachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
69 dprintf(("tlsAddress: %x", tlsAddress));
70 dprintf(("tlsInitSize: %x", tlsInitSize));
71 dprintf(("tlsTotalSize %x", tlsTotalSize));
72 dprintf(("tlsIndexAddr %x", tlsIndexAddr));
73 dprintf(("tlsCallbackAddr %x", tlsCallBackAddr));
74 dprintf(("*tlsCallbackAddr %x", *tlsCallBackAddr));
75 tibmem = (char *)VirtualAlloc(0, tlsTotalSize, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
76 if(tibmem == NULL) {
77 dprintf(("tlsAttachThread: tibmem == NULL!!!!"));
78 DebugInt3();
79 return;
80 }
81 memset(tibmem, 0, tlsTotalSize);
82 memcpy(tibmem, tlsAddress, tlsInitSize);
83
84 winteb = (TEB *)*TIBFlatPtr;
85 winteb->tls_ptr[tlsIndex] = tibmem;
86 *tlsIndexAddr = tlsIndex;
87
88 if((ULONG)*tlsCallBackAddr != 0) {
89 pCallback = tlsCallBackAddr;
90 while(*pCallback) {
91 dprintf(("tlsAttachThread: calling TLS Callback %x", *pCallback));
92
93 OS2SetExceptionHandler((void *)&exceptFrame);
94 sel = SetWin32TIB();
95 (*pCallback)((LPVOID)hinstance, DLL_THREAD_ATTACH, 0);
96 SetFS(sel);
97 OS2UnsetExceptionHandler((void *)&exceptFrame);
98
99 dprintf(("tlsAttachThread: finished calling TLS Callback %x", *pCallback));
100 *pCallback++;
101 }
102 }
103 return;
104}
105//******************************************************************************
106//******************************************************************************
107void Win32Image::tlsDetachThread() //destroy TLS structures
108{
109 EXCEPTION_FRAME exceptFrame;
110 PIMAGE_TLS_CALLBACK *pCallback;
111 USHORT sel;
112 TEB *winteb;
113
114 if(!tlsAddress)
115 return;
116
117 dprintf(("Win32Image::tlsDetachThread for module %x, thread id %x", hinstance, GetCurrentThreadId()));
118
119 if((ULONG)*tlsCallBackAddr != 0) {
120 pCallback = tlsCallBackAddr;
121 while(*pCallback) {
122 dprintf(("tlsDetachThread: calling TLS Callback %x", *pCallback));
123
124 OS2SetExceptionHandler((void *)&exceptFrame);
125 sel = SetWin32TIB();
126 (*pCallback)((LPVOID)hinstance, DLL_THREAD_DETACH, 0);
127 SetFS(sel);
128 OS2UnsetExceptionHandler((void *)&exceptFrame);
129
130 dprintf(("tlsDetachThread: finished calling TLS Callback %x", *pCallback));
131 *pCallback++;
132 }
133 }
134 winteb = (TEB *)*TIBFlatPtr;
135 VirtualFree(winteb->tls_ptr[tlsIndex], tlsTotalSize, MEM_RELEASE);
136 winteb->tls_ptr[tlsIndex] = 0;
137}
138//******************************************************************************
139//******************************************************************************
140
141//******************************************************************************
142//******************************************************************************
143DWORD WIN32API TlsAlloc()
144{
145 dprintf(("KERNEL32: TlsAlloc\n"));
146 return(O32_TlsAlloc());
147}
148//******************************************************************************
149//******************************************************************************
150BOOL WIN32API TlsFree(DWORD index)
151{
152 dprintf(("KERNEL32: TlsFree\n"));
153 return(O32_TlsFree(index));
154}
155//******************************************************************************
156//******************************************************************************
157LPVOID WIN32API TlsGetValue(DWORD index)
158{
159 LPVOID rc;
160
161 rc = O32_TlsGetValue(index);
162// dprintf(("KERNEL32: TlsGetValue %d returned %X\n", index, rc));
163 return(rc);
164}
165//******************************************************************************
166//******************************************************************************
167BOOL WIN32API TlsSetValue(DWORD index, LPVOID val)
168{
169// dprintf(("KERNEL32: TlsSetValue\n"));
170 return(O32_TlsSetValue(index, val));
171}
172//******************************************************************************
173//******************************************************************************
Note: See TracBrowser for help on using the repository browser.