Skip to content

Commit

Permalink
WIP: more accurately detect running on alternate stack
Browse files Browse the repository at this point in the history
Probably the correct thing to do is either:
* don't try to use an alternate stack at all
* change the way we switch back to the regular stack from alternate stack handler to go through the signal return path. This would clear the SS_ONSTACK bit for the lwp, allowing it to use the alternate stack again in the future.
  • Loading branch information
AustinWise committed Jul 7, 2024
1 parent f6e5d3b commit 6417f82
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/coreclr/pal/src/exception/signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,19 @@ bool IsRunningOnAlternateStack(void *context)
bool isRunningOnAlternateStack;
if (g_enable_alternate_stack_check)
{
#if defined(__sun)
ucontext_t currentThreadContext;
memset(&currentThreadContext, 0, sizeof(currentThreadContext));
if (getcontext(&currentThreadContext))
{
abort();
}
stack_t *signalStack = &currentThreadContext.uc_stack;
#else
// Note: WSL doesn't return the alternate signal ranges in the uc_stack (the whole structure is zeroed no
// matter whether the code is running on an alternate stack or not). So the check would always fail on WSL.
stack_t *signalStack = &((native_context_t *)context)->uc_stack;
#endif
// Check if the signalStack local variable address is within the alternate stack range. If it is not,
// then either the alternate stack was not installed at all or the current method is not running on it.
void* alternateStackEnd = (char *)signalStack->ss_sp + signalStack->ss_size;
Expand Down

0 comments on commit 6417f82

Please sign in to comment.