Skip to content
Snippets Groups Projects
Commit aaaef59c authored by Brian Carrier's avatar Brian Carrier
Browse files

Merge pull request #285 from antonkukoba/patch-3

Fixed Tls initialization problem
parents 4bbb5ec9 1e07be4d
Branches
Tags
No related merge requests found
...@@ -15,22 +15,26 @@ ...@@ -15,22 +15,26 @@
#include <windows.h> #include <windows.h>
static DWORD tlsIndex;
namespace tsk { namespace tsk {
static DWORD tlsIndex;
class GetTlsIndex { class GetTlsIndex {
public: public:
GetTlsIndex() { GetTlsIndex() {
tlsIndex = TlsAlloc(); tlsIndex = TlsAlloc();
} }
~GetTlsIndex() { ~GetTlsIndex() {
TlsFree(tlsIndex); TlsFree(tlsIndex);
} }
DWORD GetIndex() {
return tlsIndex;
}
private:
static DWORD tlsIndex;
}; };
DWORD GetTlsIndex::tlsIndex;
static GetTlsIndex getTlsIndex; static GetTlsIndex getTlsIndex;
} }
...@@ -40,11 +44,13 @@ namespace tsk { ...@@ -40,11 +44,13 @@ namespace tsk {
*/ */
extern "C" extern "C"
void *tsk_error_win32_get_per_thread_(unsigned struct_size) { void *tsk_error_win32_get_per_thread_(unsigned struct_size) {
void *ptr = TlsGetValue(tlsIndex);
DWORD index = tsk::getTlsIndex.GetIndex();
void *ptr = TlsGetValue( index );
if (ptr == 0) { if (ptr == 0) {
ptr = malloc(struct_size); ptr = malloc(struct_size);
memset(ptr, 0, struct_size); memset(ptr, 0, struct_size);
TlsSetValue(tlsIndex, ptr); TlsSetValue(index, ptr);
} }
return ptr; return ptr;
} }
...@@ -54,10 +60,12 @@ void *tsk_error_win32_get_per_thread_(unsigned struct_size) { ...@@ -54,10 +60,12 @@ void *tsk_error_win32_get_per_thread_(unsigned struct_size) {
*/ */
extern "C" extern "C"
void tsk_error_win32_thread_cleanup() { void tsk_error_win32_thread_cleanup() {
void *ptr = TlsGetValue(tlsIndex);
DWORD index = tsk::getTlsIndex.GetIndex();
void *ptr = TlsGetValue(index);
if (ptr != 0) { if (ptr != 0) {
free(ptr); free(ptr);
TlsSetValue(tlsIndex, 0); TlsSetValue(index, 0);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment