Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report StackOverflowException on NativeAOT on Linux #93901

Closed
wants to merge 118 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
8260630
Report stack overflow in linux
jtschuster Oct 19, 2023
263262c
Set up signal alternate stack on all new threads
jtschuster Oct 23, 2023
adc342f
Merge branch 'main' of https://github.com/dotnet/runtime into StackOv…
jtschuster Oct 23, 2023
666d231
Add test to naot smoke tests
jtschuster Oct 24, 2023
c44e631
Only allocate sigaltstack in Thread::Construct
jtschuster Oct 24, 2023
1976a38
Remove other getpagesize calls and guard sigaltstack when using mach …
jtschuster Oct 24, 2023
fa0511c
Use CLR stackoverflow test for NAOT, don't use sigaltstack on tvos
jtschuster Oct 24, 2023
3f58039
Cast to size_t before comparison
jtschuster Oct 24, 2023
bda88cb
Uncomment code and fix for NAOT
jtschuster Oct 25, 2023
aa7354a
Merge stackoverflow tests into one assembly
jtschuster Oct 26, 2023
ceff368
Update src/tests/baseservices/exceptions/stackoverflow/stackoverflowt…
jtschuster Oct 27, 2023
3e0b99a
Revert msbuild change that's no longer needed
jtschuster Oct 27, 2023
7a4e6dc
Fix namespace changes
jtschuster Oct 27, 2023
07c98d1
Set DOTNET_DbgEnableMiniDump=0 on subprocesses to avoid dumps on expe…
jtschuster Oct 30, 2023
eb59bb7
Missed semicolon
jtschuster Oct 30, 2023
4a27f1e
Merge branch 'main' of https://github.com/dotnet/runtime into StackOv…
jtschuster Oct 31, 2023
966d861
Merge branch 'main' of https://github.com/dotnet/runtime into StackOv…
jtschuster Oct 31, 2023
a7b0249
JIT: make global morph its own phase (#94185)
AndyAyersMS Oct 31, 2023
d5435e4
Update dependencies from https://github.com/dotnet/source-build-exter…
dotnet-maestro[bot] Oct 31, 2023
748dd8e
make Http2_RequestFailsWithAppropriateHttpProtocolException test more…
wfurt Oct 31, 2023
abda008
Annotate projects that are XML source of truth (#94234)
ViktorHofer Oct 31, 2023
c11e684
[wasm] Bump chrome for testing - linux: 118.0.5993.117, windows: 119.…
github-actions[bot] Oct 31, 2023
f4ee321
Fix compilation of Synchronized method combined with generics (#94203)
MichalStrehovsky Oct 31, 2023
daf9cec
Convert generated xunit runner test to work with NAOT
jtschuster Oct 31, 2023
c88b783
Do some cleanup on TimeSpan to ensure better inlining and clearer sem…
tannergooding Nov 1, 2023
872b1fd
Fix class construction recursion issue in `Lock` on NativeAOT (#94241)
kouvel Nov 1, 2023
dd72781
[browser][MT] enable timer tests (#94217)
pavelsavara Nov 1, 2023
f1d73da
[RISC-V] Fix Microsoft.VisualBasic.Tests.ConversionTests (#94042)
yurai007 Nov 1, 2023
68dde19
[iOS][non-icu] Implement missing Locale and Casing functions (#94038)
mkhamoyan Nov 1, 2023
f5e6c01
Add AIA Limit (#94244)
liveans Nov 1, 2023
c5cb147
Trim analyzer: Implement intrinsics handling of object.GetType (#93732)
vitek-karas Nov 1, 2023
8bce5a8
[wasm] Interpreter automatic PGO (#92981)
kg Nov 1, 2023
7e316e2
[wasm] Fix AOT publish in paths with space on Windows (#94166)
ilonatommy Nov 1, 2023
163bc58
Optimize cancellation handling in Hosting (#93949)
pentp Nov 1, 2023
aa9e8eb
Disable for AOT. (#94259)
ilonatommy Nov 1, 2023
fc547ad
Add some sanity checking for SPMI JIT options arguments (#94248)
BruceForstall Nov 1, 2023
eb11cc3
[browser] logging and exit improvements (#93472)
pavelsavara Nov 1, 2023
6908be6
Update diasymreader version to 16.11.29-beta1.23404.4 (#93998)
hoyosjs Nov 1, 2023
e4fbdb9
Update SystemdHelpers.cs (#94191)
WeihanLi Nov 1, 2023
771a1ab
Fix WBT (#94265)
kg Nov 1, 2023
8eb9aff
Use Stopwatch in TotalProcessorTime_PerformLoop_TotalProcessorTimeVal…
jakobbotsch Nov 1, 2023
2cd655c
Update arm64 non-wasm (Mono) AOT runs to have the LLVM tag. (#94266)
LoopedBard3 Nov 1, 2023
61291be
[main] Update dependencies from dotnet/arcade dotnet/xharness dotnet/…
dotnet-maestro[bot] Nov 1, 2023
7580471
[main] Update dependencies from dotnet/installer (#94209)
dotnet-maestro[bot] Nov 1, 2023
03c30a7
swap loadvector* and loadvectorandunzip* (#94220)
kunalspathak Nov 1, 2023
194fc5f
Tests build fix with BuildAsStandalone (#94208)
gbalykov Nov 1, 2023
e69d338
[ILLink analyzer] Fix dataflow tracking for nested finally regions (#…
sbomer Nov 1, 2023
0052480
tests\Loader - use 3 stripes for gcstress (#94235)
markples Nov 1, 2023
655b177
JIT: morph blocks in RPO (#94247)
AndyAyersMS Nov 2, 2023
34bf55c
Improve and unify debug views of dictionaries. (#92534)
arturek Nov 2, 2023
b54e9d3
Use fully qualified names when referencing user types. (#94267)
eiriktsarpalis Nov 2, 2023
48f4d02
These fail as well. (#94297)
ilonatommy Nov 2, 2023
2406107
Fix interpreter pgo defaulting on in tests incorrectly (#94295)
kg Nov 2, 2023
98b7546
Fix parallel SuperPMI pass-through logging (#94284)
BruceForstall Nov 2, 2023
c5da1b1
[browser][MT] unify pthread pool size to 40 (#94204)
pavelsavara Nov 2, 2023
43d164d
[browser] improve promise resolve marshaling after exit (#94288)
pavelsavara Nov 2, 2023
13b4315
Small cleanup for Lock in Mono (#94275)
kouvel Nov 2, 2023
257b2df
Don't use xunit generator for stackoverflowtester
jtschuster Nov 2, 2023
f8dfd67
Update src/coreclr/nativeaot/Runtime/thread.h
jtschuster Nov 2, 2023
2c1e3b3
Remove Ubuntu 18.04 from libraries Helix queues (#94293)
CarnaViire Nov 2, 2023
aea45f7
[main] Update dependencies from dotnet/installer (#94294)
dotnet-maestro[bot] Nov 2, 2023
9d3f324
Re-enable S.T.Json with source generation tests (#94320)
MichalStrehovsky Nov 3, 2023
7d6b784
Update System.Diagnostics.Tracing.Tests.csproj (#94324)
davmason Nov 3, 2023
aac9923
Explicitly set intermediate directory path to avoid including it in t…
ivanpovazan Nov 3, 2023
80666e8
Remove [EditorBrowsable(Never)] from [InlineArray], add XML docs (#94…
Sergio0694 Nov 3, 2023
5becf0f
BigInteger constructor perf (#91176)
Rob-Hague Nov 3, 2023
ede2cb2
Fixing endianness issues on S390x (#94333)
giritrivedi Nov 3, 2023
3f70252
JIT: revise local assertion prop to use bit vectors for live assertio…
AndyAyersMS Nov 3, 2023
0cd9f44
Update dependencies from https://github.com/dotnet/installer build 20…
dotnet-maestro[bot] Nov 3, 2023
e2ce987
[main] Update dependencies from dotnet/roslyn (#93959)
dotnet-maestro[bot] Nov 3, 2023
61b0d35
[RISC-V] Clear build warnings in Mono (#94344)
tomeksowi Nov 3, 2023
9a33ac5
Add xcall opcodes to model methods returning simd values. (#94329)
vargaz Nov 3, 2023
df6fdef
Fix LONG constant case in assertion prop (#94331)
BruceForstall Nov 3, 2023
64bed68
Mono Interlocked fixes (#94274)
MichalPetryka Nov 3, 2023
76a995a
fix (#94249)
Maoni0 Nov 3, 2023
b9691b0
Additional Validation for PauseThresholdWriter and ResumeThresholdWri…
cdbullard Nov 4, 2023
626f324
reduce handle table lock contention (#94159)
Maoni0 Nov 4, 2023
b4823d0
Fix reundant conditional in OleDbDataReader.ProcessResults (#94360)
omajid Nov 4, 2023
26158bf
Fix redundant conditional in HttpConnection (#94278)
omajid Nov 4, 2023
18ee31d
[main] Update dependencies from dotnet/installer (#94368)
dotnet-maestro[bot] Nov 4, 2023
5c81a06
[main] Update dependencies from dotnet/roslyn (#94361)
dotnet-maestro[bot] Nov 4, 2023
764d3e0
[wasm] Bump chrome for testing - linux: 119.0.6045.105, windows: 119.…
github-actions[bot] Nov 5, 2023
9fdb6c7
Fixed xml-doc comments in OptionsServiceCollectionExtensions.AddOptio…
gfoidl Nov 5, 2023
7faabde
[RISC-V] Unblock building with UseLocalAppHostPack (#94340)
tomeksowi Nov 6, 2023
b4a8ddf
[mono][interp] When local space overflows, retry compilation with opt…
BrzVlad Nov 6, 2023
4f26ec9
Use BigMul for 32x32=64 in decimal (#93345)
lilinus Nov 6, 2023
7f7702e
add new IMemoryCache extensions (#94335)
WeihanLi Nov 6, 2023
e733539
Improve performance of BigInteger.Multiply(large, small) (#92208)
kzrnm Nov 6, 2023
f1871f3
Allow RyuJIT to refer to frozen RuntimeType instances (#94342)
MichalStrehovsky Nov 6, 2023
6d76479
Add timeouts to AcceptConnectionAsync_ThrowingCallbackOde_KeepRunning…
ManickaP Nov 6, 2023
6066de1
Convert DIV/MOD to UDIV/UMOD using assertions (#94347)
EgorBo Nov 6, 2023
9fe2228
Fix fgOptimizeAddition opt for AOT (#94350)
EgorBo Nov 6, 2023
73cb06e
[mono] Trying to fix performance regression. (#94358)
thaystg Nov 6, 2023
cf47d9f
Fix binding types with optional string parameters (#93563)
ericstj Nov 6, 2023
0fc6233
[RISC-V]Delete unused code in LowerConstIntDivOrMod (#94328)
MinxuanZ Nov 6, 2023
0421836
[main] Update dependencies from dotnet/installer (#94382)
dotnet-maestro[bot] Nov 6, 2023
69702c3
Clean up S.N.Tensors project in main (#94378)
stephentoub Nov 6, 2023
5184067
[ILLink analyzer] Move dynamic object logic into dataflow analysis (#…
sbomer Nov 6, 2023
67114e2
Disable the Jitted Methods Counting Test When SSE(2) is Disabled (#94…
ivdiazsa Nov 6, 2023
be45599
Root less stuff for reflectable method signatures (#92994)
MichalStrehovsky Nov 6, 2023
1ddb513
Restore EETypeNode to the state before we deleted reflection blocking…
MichalStrehovsky Nov 6, 2023
f609282
Avoid throwing when attempting to set IInternalModelingOnlyValue (#94…
MichalStrehovsky Nov 6, 2023
c4d5505
[browser][MT] enable MT PLINQ (#94214)
pavelsavara Nov 6, 2023
e61f45a
[ILLink analyzer] Add branch analysis (#94123)
sbomer Nov 7, 2023
bfca4c7
[wasm] WasmAppHost: Fix passing message as paramName (#94389)
carlreinke Nov 7, 2023
0ecd2f4
JIT: Fix `EvalHWIntrinsicFunBinary` for ARM64 `MultiplyByScalar` (#94…
jakobbotsch Nov 7, 2023
f39dae8
[browser] Fix HEAP* deprecation messages (#94442)
carlreinke Nov 7, 2023
bd27e27
[browser][MT] fix stale memory on suspended thread (#94299)
pavelsavara Nov 7, 2023
5de6ca4
[browser] allow zero as debug level (#94456)
pavelsavara Nov 7, 2023
85d3773
JIT: Remove dead GT_NOP code in LSRA (#94409)
jakobbotsch Nov 7, 2023
50d4a99
[main] Update dependencies from dotnet/installer (#94462)
dotnet-maestro[bot] Nov 7, 2023
b0e1627
Add file handle limit setting for Alpine (#94439)
DrewScoggins Nov 7, 2023
021ecb8
Do not release frozen segment if we failed extending it (#94450)
MichalStrehovsky Nov 7, 2023
4feec00
Use live M.Bcl.AsyncInterfaces dependency (#94451)
ViktorHofer Nov 7, 2023
2801995
Add option for R2R configured runs. (#94412)
cincuranet Nov 7, 2023
4d2ef11
Update dependencies from https://github.com/dotnet/source-build-exter…
dotnet-maestro[bot] Nov 7, 2023
8b6b9cd
Merge branch 'StackOverflowLinuxNAOT' of https://github.com/jtschuste…
jtschuster Nov 7, 2023
4aa9912
Use IsSingleFile and update Main signature
jtschuster Nov 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/nativeaot/Runtime/inc/CommonTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef __COMMON_TYPES_H__
#define __COMMON_TYPES_H__

#include <assert.h>
#include <cstddef>
#include <cstdint>
#include <stdlib.h>
Expand Down
101 changes: 97 additions & 4 deletions src/coreclr/nativeaot/Runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "CommonTypes.h"
#include "CommonMacros.h"
#include "daccess.h"
#include "CommonMacros.inl"
#include "PalRedhawkCommon.h"
#include "PalRedhawk.h"
#include "rhassert.h"
Expand All @@ -26,6 +27,8 @@
#include "stressLog.h"
#include "RhConfig.h"
#include "RhVolatile.h"
#include <signal.h>
#include <sys/mman.h>

#ifndef DACCESS_COMPILE

Expand Down Expand Up @@ -281,6 +284,9 @@ void Thread::Construct()
if (StressLog::StressLogOn(~0u, 0))
m_pThreadStressLog = StressLog::CreateThreadStressLog(this);
#endif // STRESS_LOG
#ifdef TARGET_UNIX
EnsureSignalAlternateStack();
#endif // TARGET_UNIX

// Everything else should be initialized to 0 via the static initialization of tls_CurrentThread.

Expand All @@ -297,6 +303,89 @@ void Thread::Construct()
ASSERT(m_interruptedContext == NULL);
}

#ifdef TARGET_UNIX
void Thread::FreeSignalAlternateStack()
{
void *altstack = m_alternateStack;
m_alternateStack = nullptr;

if (altstack != nullptr)
{
stack_t ss, oss;
// The man page for sigaltstack says that when the ss.ss_flags is set to SS_DISABLE,
// all other ss fields are ignored. However, MUSL implementation checks that the
// ss_size is >= MINSIGSTKSZ even in this case.
ss.ss_size = MINSIGSTKSZ;
ss.ss_flags = SS_DISABLE;
ss.ss_sp = NULL;
int st = sigaltstack(&ss, &oss);
if ((st == 0) && (oss.ss_flags != SS_DISABLE))
{
// Make sure this altstack is this PAL's before freeing.
if (oss.ss_sp == altstack)
{
int st = munmap(oss.ss_sp, oss.ss_size);
_ASSERTE(st == 0);
}
}
}
}

bool Thread::EnsureSignalAlternateStack()
{
int st = 0;

stack_t oss;

// Query the current alternate signal stack
st = sigaltstack(NULL, &oss);
if ((st == 0) && (oss.ss_flags == SS_DISABLE))
{
// There is no alternate stack for SIGSEGV handling installed yet so allocate one

// We include the size of the SignalHandlerWorkerReturnPoint in the alternate stack size since the
// context contained in it is large and the SIGSTKSZ was not sufficient on ARM64 during testing.
int altStackSize = SIGSTKSZ + ALIGN_UP(sizeof(CONTEXT), 16) + getpagesize();
#ifdef HAS_ADDRESS_SANITIZER
// Asan also uses alternate stack so we increase its size on the SIGSTKSZ * 4 that enough for asan
// (see kAltStackSize in compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cc)
altStackSize += SIGSTKSZ * 4;
#endif
altStackSize = ALIGN_UP(altStackSize, getpagesize());
int flags = MAP_ANONYMOUS | MAP_PRIVATE;
#ifdef MAP_STACK
flags |= MAP_STACK;
#endif
void* altStack = mmap(NULL, altStackSize, PROT_READ | PROT_WRITE, flags, -1, 0);
if (altStack != MAP_FAILED)
{
// create a guard page for the alternate stack
st = mprotect(altStack, getpagesize(), PROT_NONE);
if (st == 0)
{
stack_t ss;
ss.ss_sp = (char*)altStack;
ss.ss_size = altStackSize;
ss.ss_flags = 0;
st = sigaltstack(&ss, NULL);
}

if (st == 0)
{
m_alternateStack = altStack;
}
else
{
int st2 = munmap(altStack, altStackSize);
_ASSERTE(st2 == 0);
}
}
}

return (st == 0);
}
#endif // TARGET_UNIX

bool Thread::IsInitialized()
{
return (m_ThreadStateFlags != TSF_Unknown);
Expand Down Expand Up @@ -361,6 +450,10 @@ void Thread::Destroy()
}
#endif //FEATURE_SUSPEND_REDIRECTION

#ifdef TARGET_UNIX
FreeSignalAlternateStack();
#endif

ASSERT(m_pGCFrameRegistrations == NULL);
}

Expand Down Expand Up @@ -866,19 +959,19 @@ void Thread::Unhijack()
}

// This unhijack routine is called to undo a hijack, that is potentially on a different thread.
//
//
// Although there are many code sequences (here and in asm) to
// perform an unhijack operation, they will never execute concurrently:
//
//
// - A thread may unhijack itself at any time so long as it does that from unmanaged code while in coop mode.
// This ensures that coop thread can access its stack synchronously.
// Unhijacking from unmanaged code ensures that another thread will not attempt to hijack it,
// since we only hijack threads that are executing managed code.
//
//
// - A GC thread may access a thread asynchronously, including unhijacking it.
// Asynchronously accessed thread must be in preemptive mode and should not
// access the managed portion of its stack.
//
//
// - A thread that owns the suspension can access another thread as long as the other thread is
// in preemptive mode or suspended in managed code.
// Either way the other thread cannot be accessing its hijack.
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/nativeaot/Runtime/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ struct ThreadBuffer
HANDLE m_hPalThread; // WARNING: this may legitimately be INVALID_HANDLE_VALUE
void ** m_ppvHijackedReturnAddressLocation;
void * m_pvHijackedReturnAddress;
uintptr_t m_uHijackedReturnValueFlags;
uintptr_t m_uHijackedReturnValueFlags;
PTR_ExInfo m_pExInfoStackHead;
Object* m_threadAbortException; // ThreadAbortException instance -set only during thread abort
Object* m_pThreadLocalStatics;
Expand All @@ -112,6 +112,9 @@ struct ThreadBuffer
#ifdef FEATURE_GC_STRESS
uint32_t m_uRand; // current per-thread random number
#endif // FEATURE_GC_STRESS
#ifdef TARGET_UNIX
void * m_alternateStack; // ptr to alternate signal stack
jtschuster marked this conversation as resolved.
Show resolved Hide resolved
#endif // UNIX
};

struct ReversePInvokeFrame
Expand Down Expand Up @@ -152,7 +155,7 @@ class Thread : private ThreadBuffer
// For suspension APCs it is mostly harmless, but wasteful and in extreme
// cases may force the target thread into stack oveflow.
// We use this flag to avoid sending another APC when one is still going through.
//
//
// On Unix this is an optimization to not queue up more signals when one is
// still being processed.
};
Expand Down Expand Up @@ -312,6 +315,11 @@ class Thread : private ThreadBuffer

bool IsActivationPending();
void SetActivationPending(bool isPending);

#ifdef TARGET_UNIX
bool EnsureSignalAlternateStack();
void FreeSignalAlternateStack();
#endif // TARGET_UNIX
};

#ifndef __GCENV_BASE_INCLUDED__
Expand Down
47 changes: 33 additions & 14 deletions src/coreclr/nativeaot/Runtime/unix/HardwareExceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "HardwareExceptions.h"
#include "UnixSignals.h"
#include "PalCreateDump.h"
#include "thread.h"
#include "threadstore.h"
#include <sys/mman.h>

#if defined(HOST_APPLE)
#include <mach/mach.h>
Expand Down Expand Up @@ -545,6 +548,17 @@ bool HardwareExceptionHandler(int code, siginfo_t *siginfo, void *context, void*
// Handler for the SIGSEGV signal
void SIGSEGVHandler(int code, siginfo_t *siginfo, void *context)
{
// First check if we have a stack overflow
size_t sp = ((UNIX_CONTEXT *)context)->GetSp();
size_t failureAddress = (size_t)siginfo->si_addr;

// If the failure address is at most one page above or below the stack pointer,
// we have a stack overflow.
if ((failureAddress - (sp - getpagesize())) < 2 * getpagesize())
{
PalPrintFatalError("\nProcess is terminating due to StackOverflowException.\n");
RhFailFast();
}
bool isHandled = HardwareExceptionHandler(code, siginfo, context, siginfo->si_addr);
if (isHandled)
{
Expand Down Expand Up @@ -589,7 +603,8 @@ void SIGFPEHandler(int code, siginfo_t *siginfo, void *context)
// Initialize hardware exception handling
bool InitializeHardwareExceptionHandling()
{
if (!AddSignalHandler(SIGSEGV, SIGSEGVHandler, &g_previousSIGSEGV))
// Run SIGSEGV handler on separate stack so we can handle stack overflow. Otherwise, the current (invalid) stack is used and another segfault is raised.
if (!AddSignalHandler(SIGSEGV, SIGSEGVHandler, &g_previousSIGSEGV, SA_ONSTACK))
{
return false;
}
Expand All @@ -598,26 +613,30 @@ bool InitializeHardwareExceptionHandling()
{
return false;
}
#ifdef TARGET_UNIX
Thread* curThread = ThreadStore::RawGetCurrentThread();
curThread->EnsureSignalAlternateStack();
jtschuster marked this conversation as resolved.
Show resolved Hide resolved
#endif // TARGET_UNIX

#if defined(HOST_APPLE)
#ifndef HOST_TVOS // task_set_exception_ports is not supported on tvOS
// LLDB installs task-wide Mach exception handlers. XNU dispatches Mach
// exceptions first to any registered "activation" handler and then to
// any registered task handler before dispatching the exception to a
// host-wide Mach exception handler that does translation to POSIX
// signals. This makes it impossible to use LLDB with implicit null
// LLDB installs task-wide Mach exception handlers. XNU dispatches Mach
// exceptions first to any registered "activation" handler and then to
// any registered task handler before dispatching the exception to a
// host-wide Mach exception handler that does translation to POSIX
// signals. This makes it impossible to use LLDB with implicit null
// checks in NativeAOT; continuing execution after LLDB traps an
// EXC_BAD_ACCESS will result in LLDB's EXC_BAD_ACCESS handler being
// invoked again. This also interferes with the translation of SIGFPEs
// to .NET-level ArithmeticExceptions. Work around this here by
// installing a no-op task-wide Mach exception handler for
// EXC_BAD_ACCESS and EXC_ARITHMETIC.
kern_return_t kr = task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC, /* SIGSEGV, SIGFPE */
MACH_PORT_NULL,
EXCEPTION_STATE_IDENTITY,
MACHINE_THREAD_STATE);
// installing a no-op task-wide Mach exception handler for
// EXC_BAD_ACCESS and EXC_ARITHMETIC.
kern_return_t kr = task_set_exception_ports(
mach_task_self(),
EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC, /* SIGSEGV, SIGFPE */
MACH_PORT_NULL,
EXCEPTION_STATE_IDENTITY,
MACHINE_THREAD_STATE);
ASSERT(kr == KERN_SUCCESS);
#endif
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/nativeaot/Runtime/unix/UnixSignals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#include "UnixSignals.h"

// Add handler for hardware exception signal
bool AddSignalHandler(int signal, SignalHandler handler, struct sigaction* previousAction)
bool AddSignalHandler(int signal, SignalHandler handler, struct sigaction* previousAction, int additionalFlags)
{
struct sigaction newAction;

newAction.sa_flags = SA_RESTART;
newAction.sa_flags = SA_RESTART | additionalFlags;
newAction.sa_handler = NULL;
newAction.sa_sigaction = handler;
newAction.sa_flags |= SA_SIGINFO;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/unix/UnixSignals.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

typedef void (*SignalHandler)(int code, siginfo_t* siginfo, void* context);

bool AddSignalHandler(int signal, SignalHandler handler, struct sigaction* previousAction);
bool AddSignalHandler(int signal, SignalHandler handler, struct sigaction* previousAction, int additionalFlags = 0);
void RestoreSignalHandler(int signal_id, struct sigaction* previousAction);

#endif // __UNIX_SIGNALS_H__
50 changes: 50 additions & 0 deletions src/tests/nativeaot/SmokeTests/StackOverflowReporting/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

public static class StackOverflowReporting
{
public static int Main(string[] args)
jkotas marked this conversation as resolved.
Show resolved Hide resolved
{
if (args.Length == 1 && args[0].ToLowerInvariant() == "recurse")
{
Recursion(0);
return 0;
}
else
{
var directory = System.AppContext.BaseDirectory;
var exe = System.IO.Path.Combine(directory, "StackOverflowReporting");
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
exe += ".exe";
}
exe = Process.GetCurrentProcess().MainModule.FileName;
using (Process p = new Process())
{
p.StartInfo.FileName = exe;
p.StartInfo.Arguments = "recurse";
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.Start();
p.WaitForExit();
var output = p.StandardOutput.ReadToEnd();
var error = p.StandardError.ReadToEnd();
if (output.Contains("StackOverflowException") || error.Contains("StackOverflowException"))
{
return 100;
}
else
{
return 1;
}
}
}
}

public static void Recursion(int i)
{
Recursion(i + 1);
Recursion(i + 1);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<CLRTestPriority>0</CLRTestPriority>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.cs" />
</ItemGroup>

</Project>
Loading