mirror of
https://github.com/ivellioscolin/pykd.git
synced 2025-04-19 19: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;
|
||||
|
||||
// контескт исполнения нити питона
|
||||
__declspec( thread ) PyThreadStatePtr ptrPyThreadState = NULL;
|
||||
PyThreadStateSaver g_pyThreadState;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
53
pykd/pyaux.h
53
pykd/pyaux.h
@ -1,9 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef PyThreadState *PyThreadStatePtr;
|
||||
extern __declspec( thread ) PyThreadStatePtr ptrPyThreadState;
|
||||
class PyThreadStateSaver {
|
||||
|
||||
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
|
||||
// { PyThread_StateSave state( winext->getThreadState() );
|
||||
@ -19,22 +51,13 @@ class PyThread_StateSave {
|
||||
public:
|
||||
|
||||
PyThread_StateSave()
|
||||
: m_bRestored(false)
|
||||
{
|
||||
if (ptrPyThreadState)
|
||||
{
|
||||
PyEval_RestoreThread( ptrPyThreadState );
|
||||
m_bRestored = true;
|
||||
}
|
||||
g_pyThreadState.restoreState();
|
||||
}
|
||||
|
||||
~PyThread_StateSave() {
|
||||
if ( m_bRestored )
|
||||
ptrPyThreadState = PyEval_SaveThread();
|
||||
g_pyThreadState.saveState();
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_bRestored;
|
||||
};
|
||||
|
||||
// { PyThread_StateRestore state;
|
||||
@ -46,11 +69,11 @@ class PyThread_StateRestore
|
||||
public:
|
||||
|
||||
PyThread_StateRestore() {
|
||||
ptrPyThreadState = PyEval_SaveThread();
|
||||
g_pyThreadState.saveState();
|
||||
}
|
||||
|
||||
~PyThread_StateRestore() {
|
||||
PyEval_RestoreThread( ptrPyThreadState );
|
||||
g_pyThreadState.restoreState();
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user