mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-21 04:13:22 +08:00
[pykd] fixed: TLS problem
git-svn-id: https://pykd.svn.codeplex.com/svn@69886 9b283d60-5439-405e-af05-b73fd8c4d996
This commit is contained in:
parent
549cb797c1
commit
9603376e29
@ -39,7 +39,7 @@ DbgExt *dbgExt = NULL;
|
|||||||
dbgClient g_dbgClient;
|
dbgClient g_dbgClient;
|
||||||
|
|
||||||
// контескт исполнения нити питона
|
// контескт исполнения нити питона
|
||||||
__declspec( thread ) PyThreadStatePtr ptrPyThreadState = NULL;
|
PyThreadStateSaver g_pyThreadState;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
53
pykd/pyaux.h
53
pykd/pyaux.h
@ -1,9 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
typedef PyThreadState *PyThreadStatePtr;
|
class PyThreadStateSaver {
|
||||||
extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
PyThreadStateSaver() {
|
||||||
|
m_index = TlsAlloc();
|
||||||
|
}
|
||||||
|
|
||||||
|
~PyThreadStateSaver() {
|
||||||
|
TlsFree( m_index );
|
||||||
|
}
|
||||||
|
|
||||||
|
void saveState() {
|
||||||
|
TlsSetValue( m_index, PyEval_SaveThread() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void restoreState() {
|
||||||
|
PyThreadState* state = (PyThreadState*)TlsGetValue( m_index );
|
||||||
|
if ( state )
|
||||||
|
PyEval_RestoreThread( state );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
DWORD m_index;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern PyThreadStateSaver g_pyThreadState;
|
||||||
|
|
||||||
|
|
||||||
|
//typedef PyThreadState *PyThreadStatePtr;
|
||||||
|
//extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
|
||||||
|
|
||||||
// --> call back
|
// --> call back
|
||||||
// { PyThread_StateSave state( winext->getThreadState() );
|
// { PyThread_StateSave state( winext->getThreadState() );
|
||||||
@ -19,22 +51,13 @@ class PyThread_StateSave {
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
PyThread_StateSave()
|
PyThread_StateSave()
|
||||||
: m_bRestored(false)
|
|
||||||
{
|
{
|
||||||
if (ptrPyThreadState)
|
g_pyThreadState.restoreState();
|
||||||
{
|
|
||||||
PyEval_RestoreThread( ptrPyThreadState );
|
|
||||||
m_bRestored = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~PyThread_StateSave() {
|
~PyThread_StateSave() {
|
||||||
if ( m_bRestored )
|
g_pyThreadState.saveState();
|
||||||
ptrPyThreadState = PyEval_SaveThread();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_bRestored;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// { PyThread_StateRestore state;
|
// { PyThread_StateRestore state;
|
||||||
@ -46,11 +69,11 @@ class PyThread_StateRestore
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
PyThread_StateRestore() {
|
PyThread_StateRestore() {
|
||||||
ptrPyThreadState = PyEval_SaveThread();
|
g_pyThreadState.saveState();
|
||||||
}
|
}
|
||||||
|
|
||||||
~PyThread_StateRestore() {
|
~PyThread_StateRestore() {
|
||||||
PyEval_RestoreThread( ptrPyThreadState );
|
g_pyThreadState.restoreState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user