diff options
author | Jason Madden <jamadden@gmail.com> | 2021-10-29 12:15:40 -0500 |
---|---|---|
committer | Jason Madden <jamadden@gmail.com> | 2021-10-29 12:19:39 -0500 |
commit | 8463692d77eeddf806415f587134a974e9bac40d (patch) | |
tree | 482c39460a435eabe315117838391b7f84f6e4bb | |
parent | 442f70cc84720b1cd82ca3a50992dc1711d84e4b (diff) | |
download | greenlet-8463692d77eeddf806415f587134a974e9bac40d.tar.gz |
We seem to need to keep the bottom three handlers around, perhaps?
-rw-r--r-- | src/greenlet/greenlet.cpp | 4 | ||||
-rw-r--r-- | src/greenlet/greenlet_thread_state.hpp | 3 | ||||
-rw-r--r-- | src/greenlet/platform/switch_x86_msvc.h | 19 |
3 files changed, 20 insertions, 6 deletions
diff --git a/src/greenlet/greenlet.cpp b/src/greenlet/greenlet.cpp index c211b18..c01a852 100644 --- a/src/greenlet/greenlet.cpp +++ b/src/greenlet/greenlet.cpp @@ -2256,7 +2256,7 @@ green_switch(PyGreenlet* self, PyObject* args, PyObject* kwargs) try { #if defined(MS_WIN32) && !defined(MS_WIN64) && defined(_M_IX86) && defined(_MSC_VER) - fprintf(stderr, "\tENTERING green_switch for %p at %p\n", self, &self); + fprintf(stderr, "ENTERING green_switch for %p at %p\n", self, &self); slp_show_seh_chain(); #endif OwnedObject result = single_result(self->switching_state->g_switch()); @@ -3035,7 +3035,7 @@ GreenletVectorHandler(PEXCEPTION_POINTERS ExceptionInfo) fprintf(stderr, "\t\tEH_COLLIDED_UNWIND\n" ); } fprintf(stderr, "\n"); - + fflush(NULL); for(DWORD i = 0; i < ExceptionRecord->NumberParameters; i++) { fprintf(stderr, "\t\t\tParam %ld: %lX\n", i, ExceptionRecord->ExceptionInformation[i]); } diff --git a/src/greenlet/greenlet_thread_state.hpp b/src/greenlet/greenlet_thread_state.hpp index 924b8dc..bc0c14b 100644 --- a/src/greenlet/greenlet_thread_state.hpp +++ b/src/greenlet/greenlet_thread_state.hpp @@ -154,7 +154,10 @@ public: ThreadState::get_referrers_name = Greenlet_Intern("get_referrers"); } #ifdef GREENLET_NEEDS_EXCEPTION_STATE_SAVED + fprintf(stderr, "Capturing exception state for new thread. Current chain:\n"); + slp_show_seh_chain(); this->exception_state = slp_get_exception_state(); + fprintf(stderr, "Saved exception state for new thread: %p\n", this->exception_state); #endif } diff --git a/src/greenlet/platform/switch_x86_msvc.h b/src/greenlet/platform/switch_x86_msvc.h index dfc0870..ddb5ded 100644 --- a/src/greenlet/platform/switch_x86_msvc.h +++ b/src/greenlet/platform/switch_x86_msvc.h @@ -105,10 +105,14 @@ typedef struct _GExceptionRegistration { void* handler_f; } GExceptionRegistration; -static void +static void* slp_show_seh_chain() { + GExceptionRegistration* a = NULL; /* Third most recent */ + GExceptionRegistration* b = NULL; /* second */ + GExceptionRegistration* c = NULL; GExceptionRegistration* seh_state = (GExceptionRegistration*)__readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)); + a = b = c = seh_state; while (seh_state && seh_state != (GExceptionRegistration*)0xFFFFFFFF) { fprintf(stderr, "\tSEH_chain addr: %p handler: %p prev: %p\n", seh_state, @@ -117,8 +121,15 @@ slp_show_seh_chain() fprintf(stderr, "\tERROR: Broken chain.\n"); break; } + + a = b; + b = c; + c = seh_state; + seh_state = seh_state->prev; } + fflush(NULL); + return a ? a : (b ? b : c); } static int @@ -130,7 +141,7 @@ slp_switch(void) int *stackref, stsizediff; /* store the structured exception state for this stack */ DWORD seh_state = __readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)); - fprintf(stderr, "\nslp_switch: Saving seh_state %p for %p\n", + fprintf(stderr, "\nslp_switch: Saving seh_state %p switching to %p\n", seh_state, switching_thread_state); slp_show_seh_chain(); __asm mov stackref, esp; @@ -146,7 +157,7 @@ slp_switch(void) } SLP_RESTORE_STATE(); } - fprintf(stderr, "slp_switch: Replacing seh_state %p with %p for %p\n", + fprintf(stderr, "slp_switch: Replacing seh_state %p with %p switching to %p\n", __readfsdword(FIELD_OFFSET(NT_TIB, ExceptionList)), seh_state, switching_thread_state); @@ -154,7 +165,7 @@ slp_switch(void) // it references things on the stack that have just moved. //fprintf(stderr, "slp_switch: Before replacement:\n"); //slp_show_seh_chain(); - fprintf(stderr, "slp_switch: After replacement for %p:\n", switching_thread_state); + fprintf(stderr, "slp_switch: After replacement switching to %p:\n", switching_thread_state); __writefsdword(FIELD_OFFSET(NT_TIB, ExceptionList), seh_state); slp_show_seh_chain(); return 0; |