Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Implement stack probing using helpers #26807

Merged
merged 9 commits into from
Oct 7, 2019
Merged

Implement stack probing using helpers #26807

merged 9 commits into from
Oct 7, 2019

Conversation

echesakov
Copy link

@echesakov echesakov commented Sep 21, 2019

Fixes #21061

This adds implementation of stack probing via helpers (similar to VC++ _chkstk() function) on win-x86, win-x64, linux-x64 and linux-x86.

The following are the stack traces collected on different OS and under different debuggers:

linux-x86 gdb

Thread 1 "corerun" received signal SIGSEGV, Segmentation fault.
JIT_StackProbe () at /home/echesako/git/coreclr/src/vm/i386/jithelp.S:639
639     /home/echesako/git/coreclr/src/vm/i386/jithelp.S: No such file or directory.
(gdb) bt
#0  JIT_StackProbe () at /home/echesako/git/coreclr/src/vm/i386/jithelp.S:639
#1  0xf05b3c60 in ?? ()
#2  0xf1e58ffa in ?? ()
#3  0xf7478d25 in CallDescrWorkerInternal () at /home/echesako/git/coreclr/src/vm/i386/asmhelpers.S:304
#4  0xf73056a5 in CallDescrWorker (pCallDescrData=<optimized out>) at /home/echesako/git/coreclr/src/vm/callhelpers.cpp:126
#5  0xf7305542 in CallDescrWorkerWithHandler (pCallDescrData=<optimized out>, fCriticalCall=<optimized out>) at /home/echesako/git/coreclr/src/vm/callhelpers.cpp:70
#6  0xf7305e61 in MethodDescCallSite::CallTargetWorker (this=<optimized out>, pArguments=<optimized out>, pReturnValue=<optimized out>, cbReturnValue=<optimized out>) at /home/echesako/git/coreclr/src/vm/callhelpers.cpp:546
#7  0xf749726f in MethodDescCallSite::Call (this=<optimized out>, pArguments=0xff7fdad0) at /home/echesako/git/coreclr/src/vm/callhelpers.h:459
#8  RunMainInternal (pParam=0xffffd070) at /home/echesako/git/coreclr/src/vm/assembly.cpp:1505
#9  RunMain(MethodDesc*, short, int*, REF<PtrArray>*)::$_1::operator()(Param*) const::{lambda(Param*)#1}::operator()(Param*) const (this=<optimized out>, pParam=<optimized out>) at /home/echesako/git/coreclr/src/vm/assembly.cpp:1577
#10 RunMain(MethodDesc*, short, int*, REF<PtrArray>*)::$_1::operator()(Param*) const (this=<optimized out>, __EXparam=<optimized out>) at /home/echesako/git/coreclr/src/vm/assembly.cpp:1579
#11 RunMain (pFD=<optimized out>, numSkipArgs=<optimized out>, piRetVal=<optimized out>, stringArgs=<optimized out>) at /home/echesako/git/coreclr/src/vm/assembly.cpp:1579
#12 0xf74976ec in Assembly::ExecuteMainMethod (this=<optimized out>, stringArgs=<optimized out>, waitForOtherThreads=-222690992) at /home/echesako/git/coreclr/src/vm/assembly.cpp:1689
#13 0xf71ce5bc in CorHost2::ExecuteAssembly (this=0x56565f98, dwAppDomainId=1, pwzAssemblyPath=<optimized out>, argc=<optimized out>, argv=<optimized out>, pReturnValue=0xffffd644) at /home/echesako/git/coreclr/src/vm/corhost.cpp:460
#14 0xf71939f8 in coreclr_execute_assembly (hostHandle=<optimized out>, domainId=<optimized out>, argc=<optimized out>, argv=<optimized out>, managedAssemblyPath=<optimized out>, exitCode=<optimized out>) at /home/echesako/git/coreclr/src/dlls/mscoree/unixinterface.cpp:407
#15 0x565574e6 in ExecuteManagedAssembly (currentExeAbsolutePath=<optimized out>, clrFilesAbsolutePath=<optimized out>, managedAssemblyAbsolutePath=<optimized out>, managedAssemblyArgc=0, managedAssemblyArgv=0xff7fdad0) at /home/echesako/git/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp:476
#16 0x5655656c in corerun (argc=2, argv=0xffffd7e4) at /home/echesako/git/coreclr/src/coreclr/hosts/unixcorerun/corerun.cpp:149
#17 0xf7b3ce81 in __libc_start_main (main=0x56556800 <main(int, char const**)>, argc=2, argv=0xffffd7e4, init=0x56557e40 <__libc_csu_init>, fini=0x56557eb0 <__libc_csu_fini>, rtld_fini=0xf7fe59b0 <_dl_fini>, stack_end=0xffffd7dc) at ../csu/libc-start.c:310
#18 0x56556141 in _start ()

linux-x64 lldb

* thread #1, name = 'corerun', stop reason = signal SIGSEGV: invalid address (fault address: 0x7fffff7fefff)
    frame #0: 0x00007ffff639a0d1 libcoreclr.so`JIT_StackProbe at jithelpers_fast.S:562
   559          or      rsp, (PAGE_SIZE - 1) // rsp points to the last byte on the first unprobed page
   560
   561  LOCAL_LABEL(ProbeLoop):
-> 562          test    dword ptr [rsp], eax
   563          sub     rsp, PAGE_SIZE
   564          cmp     rsp, r11
   565          jge     LOCAL_LABEL(ProbeLoop)
(lldb) bt
* thread #1, name = 'corerun', stop reason = signal SIGSEGV: invalid address (fault address: 0x7fffff7fefff)
  * frame #0: 0x00007ffff639a0d1 libcoreclr.so`JIT_StackProbe at jithelpers_fast.S:562
    frame #1: 0x00007fff7d34860e
    frame #2: 0x00007ffff63998fb libcoreclr.so`CallDescrWorkerInternal at unixasmmacrosamd64.inc:866
    frame #3: 0x00007ffff6232139 libcoreclr.so`CallDescrWorkerWithHandler(pCallDescrData=0x00007fffffffd990, fCriticalCall=NO) at callhelpers.cpp:70:5
    frame #4: 0x00007ffff6232b99 libcoreclr.so`MethodDescCallSite::CallTargetWorker(this=<unavailable>, pArguments=0x00007fffffffda98, pReturnValue=<unavailable>, cbReturnValue=<unavailable>) at callhelpers.cpp:546:9
    frame #5: 0x00007ffff63b63cb libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) [inlined] MethodDescCallSite::Call(this=<unavailable>, pArguments=<unavailable>) at callhelpers.h:459:9
    frame #6: 0x00007ffff63b63b4 libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) at assembly.cpp:1505
    frame #7: 0x00007ffff63b619a libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) [inlined] RunMain(MethodDesc*, short, int*, REF<PtrArray>*)::$_1::operator()(Param*) const::'lambda'(Param*)::operator()(Param*) const at assembly.cpp:1577
    frame #8: 0x00007ffff63b619a libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) at assembly.cpp:1579
    frame #9: 0x00007ffff63b611b libcoreclr.so`RunMain(pFD=<unavailable>, numSkipArgs=<unavailable>, piRetVal=<unavailable>, stringArgs=<unavailable>) at assembly.cpp:1579
    frame #10: 0x00007ffff63b6812 libcoreclr.so`Assembly::ExecuteMainMethod(this=<unavailable>, stringArgs=0x00007fffffffe048, waitForOtherThreads=YES) at assembly.cpp:1689:18
    frame #11: 0x00007ffff6111108 libcoreclr.so`CorHost2::ExecuteAssembly(this=<unavailable>, dwAppDomainId=<unavailable>, pwzAssemblyPath=<unavailable>, argc=<unavailable>, argv=0x0000000000000000, pReturnValue=<unavailable>) at corhost.cpp:460:39
    frame #12: 0x00007ffff60d823c libcoreclr.so`::coreclr_execute_assembly(hostHandle=<unavailable>, domainId=<unavailable>, argc=<unavailable>, argv=<unavailable>, managedAssemblyPath=<unavailable>, exitCode=<unavailable>) at unixinterface.cpp:407:24
    frame #13: 0x000055555555693e corerun`ExecuteManagedAssembly(currentExeAbsolutePath=<unavailable>, clrFilesAbsolutePath=<unavailable>, managedAssemblyAbsolutePath=<unavailable>, managedAssemblyArgc=<unavailable>, managedAssemblyArgv=0x0000000000000000) at coreruncommon.cpp:476:22
    frame #14: 0x0000555555555a3c corerun`corerun(argc=<unavailable>, argv=<unavailable>) at corerun.cpp:149:20
    frame #15: 0x00007ffff6ca3b97 libc.so.6`__libc_start_main(main=(corerun`main at corerun.cpp:161:12), argc=2, argv=0x00007fffffffe4b8, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe4a8) at libc-start.c:310
    frame #16: 0x0000555555555679 corerun`_start + 41

linux-x64 gdb - can not unwind the stack beyond CallDescrWorkerInternal

Thread 1 "corerun" received signal SIGSEGV, Segmentation fault.
JIT_StackProbe () at /opt/code/src/vm/amd64/jithelpers_fast.S:562
562     /opt/code/src/vm/amd64/jithelpers_fast.S: No such file or directory.
(gdb) bt
#0  JIT_StackProbe () at /opt/code/src/vm/amd64/jithelpers_fast.S:562
#1  0x00007fff7d3689ce in ?? ()
#2  0x00007fffffffd780 in ?? ()
#3  0x00007fff7cee064f in ?? ()
#4  0x00007fffffffd970 in ?? ()
#5  0x00007fff58000658 in ?? ()
#6  0x00007fffffffd7a0 in ?? ()
#7  0x00007ffff63998fb in CallDescrWorkerInternal () at /opt/code/src/pal/inc/unixasmmacrosamd64.inc:866
Backtrace stopped: frame did not save the PC

win-x86 Visual Studio

coreclr.dll!_JIT_StackProbe@0() Line 1481
	at D:\git\coreclr1\src\vm\i386\jithelp.asm(1481)
088687f0()
[Frames below may be incorrect and/or missing]
08430f06()
coreclr.dll!CallDescrWorkerInternal(unsigned long pParams) Line 607
	at D:\git\coreclr1\src\vm\i386\asmhelpers.asm(607)
coreclr.dll!CallDescrWorker(CallDescrData * pCallDescrData) Line 129
	at D:\git\coreclr1\src\vm\callhelpers.cpp(129)
coreclr.dll!CallDescrWorkerWithHandler(CallDescrData * pCallDescrData, int fCriticalCall) Line 72
	at D:\git\coreclr1\src\vm\callhelpers.cpp(72)
coreclr.dll!MethodDescCallSite::CallTargetWorker(const unsigned __int64 * pArguments, unsigned __int64 * pReturnValue, int cbReturnValue) Line 554
	at D:\git\coreclr1\src\vm\callhelpers.cpp(554)
[Inline Frame] coreclr.dll!MethodDescCallSite::Call(const unsigned __int64 *) Line 459
	at D:\git\coreclr1\src\vm\callhelpers.h(459)
coreclr.dll!RunMainInternal(Param * pParam) Line 1506
	at D:\git\coreclr1\src\vm\assembly.cpp(1506)
coreclr.dll!``RunMain'::`29'::__Body::Run'::`5'::__Body::Run(Param * pParam) Line 1579
	at D:\git\coreclr1\src\vm\assembly.cpp(1579)
coreclr.dll!`RunMain'::`29'::__Body::Run(Param * __EXparam) Line 1579
	at D:\git\coreclr1\src\vm\assembly.cpp(1579)
coreclr.dll!RunMain(MethodDesc * pFD, short numSkipArgs, int * piRetVal, REF<PtrArray> * stringArgs) Line 1579
	at D:\git\coreclr1\src\vm\assembly.cpp(1579)
coreclr.dll!Assembly::ExecuteMainMethod(REF<PtrArray> * stringArgs, int waitForOtherThreads) Line 1689
	at D:\git\coreclr1\src\vm\assembly.cpp(1689)
coreclr.dll!CorHost2::ExecuteAssembly(unsigned long dwAppDomainId, const wchar_t * pwzAssemblyPath, int argc, const wchar_t * * argv, unsigned long * pReturnValue) Line 461
	at D:\git\coreclr1\src\vm\corhost.cpp(461)
CoreRun.exe!TryRun(const int argc, const wchar_t * * argv, Logger & log, const bool verbose, const bool waitForDebugger, unsigned long & exitCode) Line 698
	at D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp(698)
CoreRun.exe!wmain(const int argc, const wchar_t * * argv) Line 815
	at D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp(815)
CoreRun.exe!invoke_main() Line 90
	at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(90)
CoreRun.exe!__scrt_common_main_seh() Line 288
	at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288)
CoreRun.exe!__scrt_common_main() Line 331
	at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(331)
CoreRun.exe!wmainCRTStartup() Line 17
	at d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_wmain.cpp(17)

win-x86 WinDbg

(1cce4.1cbcc): Stack overflow - code c00000fd (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for D:\git\coreclr1\bin\tests\Windows_NT.x86.Checked\Tests\Core_Root\CoreCLR.dll
eax=03003b74 ebx=0317e268 ecx=00000000 edx=00000342 esi=031fa990 edi=031d6600
eip=798be4cb esp=03003fff ebp=0317db70 iopl=0         nv up ei pl nz na pe nc
cs=0023  ss=002b  ds=002b  es=002b  fs=0053  gs=002b             efl=00010206
CoreCLR!JIT_StackProbe+0xf:
798be4cb 850424          test    dword ptr [esp],eax  ss:002b:03003fff=00000000
0:000> k
 # ChildEBP RetAddr  
00 0317db70 085e87f0 CoreCLR!JIT_StackProbe+0xf [D:\git\coreclr1\src\vm\i386\jithelp.asm @ 1481] 
*** WARNING: Unable to verify checksum for D:\GitHub_21061\GitHub_21061.dll
*** ERROR: Module load completed but symbols could not be loaded for D:\GitHub_21061\GitHub_21061.dll
01 0317db7c 081b0f06 GitHub_21061!GitHub_21061.Program.Run_0017A000()+0x10
02 0317db88 796082f1 GitHub_21061!GitHub_21061.Program.Main(System.String[])+0xec6
03 0317db94 797e514e CoreCLR!CallDescrWorkerInternal+0x34 [D:\git\coreclr1\src\vm\i386\asmhelpers.asm @ 607] 
04 0317dfb4 797e52cb CoreCLR!CallDescrWorker+0xd7 [D:\git\coreclr1\src\vm\callhelpers.cpp @ 129] 
05 0317e030 797e58fa CoreCLR!CallDescrWorkerWithHandler+0x11b [D:\git\coreclr1\src\vm\callhelpers.cpp @ 72] 
06 0317e298 797df2a4 CoreCLR!MethodDescCallSite::CallTargetWorker+0x5f9 [D:\git\coreclr1\src\vm\callhelpers.cpp @ 554] 
07 (Inline) -------- CoreCLR!MethodDescCallSite::Call+0x11 [D:\git\coreclr1\src\vm\callhelpers.h @ 459] 
08 0317e3dc 797def17 CoreCLR!RunMainInternal+0x121 [D:\git\coreclr1\src\vm\assembly.cpp @ 1506] 
09 0317e418 797defc9 CoreCLR!``RunMain'::`29'::__Body::Run'::`5'::__Body::Run+0x42 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
0a 0317e46c 797df101 CoreCLR!`RunMain'::`29'::__Body::Run+0x5f [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
0b 0317e4cc 797dc36b CoreCLR!RunMain+0xd1 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
0c 0317e824 79595721 CoreCLR!Assembly::ExecuteMainMethod+0x1a0 [D:\git\coreclr1\src\vm\assembly.cpp @ 1689] 
*** WARNING: Unable to verify checksum for CoreRun.exe
0d 0317e9a0 00d1d0dd CoreCLR!CorHost2::ExecuteAssembly+0x421 [D:\git\coreclr1\src\vm\corhost.cpp @ 461] 
0e 0317fca0 00d1dd06 CoreRun!TryRun+0x6c1 [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 698] 
0f 0317fcf0 00d3adc3 CoreRun!wmain+0x98 [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 815] 
10 0317fd10 00d3ac97 CoreRun!invoke_main+0x33 [d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 90] 
11 0317fd6c 00d3ab3d CoreRun!__scrt_common_main_seh+0x157 [d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
12 0317fd74 00d3ae28 CoreRun!__scrt_common_main+0xd [d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331] 
13 0317fd7c 76e96359 CoreRun!wmainCRTStartup+0x8 [d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_wmain.cpp @ 17] 

win-x64 Visual Studio

coreclr.dll!JIT_StackProbe() Line 974
	at D:\git\coreclr1\src\vm\amd64\JitHelpers_Fast.asm(974)
00007ff8f2a704cf()
00007ff8f2a4d83f()
coreclr.dll!CallDescrWorkerInternal() Line 101
	at D:\git\coreclr1\src\vm\amd64\CallDescrWorkerAMD64.asm(101)
coreclr.dll!MethodDescCallSite::CallTargetWorker(const unsigned __int64 * pArguments, unsigned __int64 * pReturnValue, int cbReturnValue) Line 554
	at D:\git\coreclr1\src\vm\callhelpers.cpp(554)
[Inline Frame] coreclr.dll!MethodDescCallSite::Call(const unsigned __int64 *) Line 459
	at D:\git\coreclr1\src\vm\callhelpers.h(459)
coreclr.dll!RunMainInternal(Param * pParam) Line 1506
	at D:\git\coreclr1\src\vm\assembly.cpp(1506)
coreclr.dll!``RunMain'::`30'::__Body::Run'::`5'::__Body::Run(Param * pParam) Line 1577
	at D:\git\coreclr1\src\vm\assembly.cpp(1577)
coreclr.dll!`RunMain'::`30'::__Body::Run(Param * __EXparam) Line 1579
	at D:\git\coreclr1\src\vm\assembly.cpp(1579)
coreclr.dll!RunMain(MethodDesc * pFD, short numSkipArgs, int * piRetVal, REF<PtrArray> * stringArgs) Line 1579
	at D:\git\coreclr1\src\vm\assembly.cpp(1579)
coreclr.dll!Assembly::ExecuteMainMethod(REF<PtrArray> * stringArgs, int waitForOtherThreads) Line 1689
	at D:\git\coreclr1\src\vm\assembly.cpp(1689)
coreclr.dll!CorHost2::ExecuteAssembly(unsigned long dwAppDomainId, const wchar_t * pwzAssemblyPath, int argc, const wchar_t * * argv, unsigned long * pReturnValue) Line 461
	at D:\git\coreclr1\src\vm\corhost.cpp(461)
CoreRun.exe!TryRun(const int argc, const wchar_t * * argv, Logger & log, const bool verbose, const bool waitForDebugger, unsigned long & exitCode) Line 697
	at D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp(697)
CoreRun.exe!wmain(const int argc, const wchar_t * * argv) Line 815
	at D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp(815)
CoreRun.exe!invoke_main() Line 91
	at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(91)
CoreRun.exe!__scrt_common_main_seh() Line 288
	at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(288)
CoreRun.exe!__scrt_common_main() Line 331
	at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl(331)
CoreRun.exe!wmainCRTStartup() Line 17
	at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_wmain.cpp(17)

win-x64 WinDbg

(1be30.1cda4): Stack overflow - code c00000fd (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for D:\git\coreclr1\bin\tests\Windows_NT.x64.Checked\Tests\Core_Root\CoreCLR.dll
CoreCLR!JIT_StackProbe+0xe:
00007ff9`522885ae 8500            test    dword ptr [rax],eax ds:0000003a`27006fff=00000000
0:000> k
 # Child-SP          RetAddr           Call Site
00 0000003a`2717d250 00007ff8`f2a904cf CoreCLR!JIT_StackProbe+0xe [D:\git\coreclr1\src\vm\amd64\JitHelpers_Fast.asm @ 974] 
01 0000003a`2717d258 00007ff8`f2a6d83f GitHub_21061!GitHub_21061.Program.Run_00177000()+0xf*** WARNING: Unable to verify checksum for D:\GitHub_21061\GitHub_21061.dll
*** ERROR: Module load completed but symbols could not be loaded for D:\GitHub_21061\GitHub_21061.dll

02 0000003a`2717d270 00007ff9`523a7503 GitHub_21061!GitHub_21061.Program.Main(System.String[])+0xeaf
03 0000003a`2717d2a0 00007ff9`5208ded8 CoreCLR!CallDescrWorkerInternal+0x83 [D:\git\coreclr1\src\vm\amd64\CallDescrWorkerAMD64.asm @ 101] 
04 0000003a`2717d2e0 00007ff9`52083466 CoreCLR!MethodDescCallSite::CallTargetWorker+0x9a8 [D:\git\coreclr1\src\vm\callhelpers.cpp @ 554] 
05 (Inline Function) --------`-------- CoreCLR!MethodDescCallSite::Call+0x16 [D:\git\coreclr1\src\vm\callhelpers.h @ 459] 
06 0000003a`2717d780 00007ff9`52083016 CoreCLR!RunMainInternal+0x16e [D:\git\coreclr1\src\vm\assembly.cpp @ 1506] 
07 0000003a`2717d9a0 00007ff9`52083119 CoreCLR!``RunMain'::`30'::__Body::Run'::`5'::__Body::Run+0x76 [D:\git\coreclr1\src\vm\assembly.cpp @ 1577] 
08 0000003a`2717d9e0 00007ff9`52083291 CoreCLR!`RunMain'::`30'::__Body::Run+0x89 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
09 0000003a`2717da40 00007ff9`5207edfc CoreCLR!RunMain+0xf5 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
0a 0000003a`2717dac0 00007ff9`51cfa245 CoreCLR!Assembly::ExecuteMainMethod+0x208 [D:\git\coreclr1\src\vm\assembly.cpp @ 1689] 
*** WARNING: Unable to verify checksum for CoreRun.exe
0b 0000003a`2717df20 00007ff6`9c785f6f CoreCLR!CorHost2::ExecuteAssembly+0x505 [D:\git\coreclr1\src\vm\corhost.cpp @ 461] 
0c 0000003a`2717e1e0 00007ff6`9c78748a CoreRun!TryRun+0x73b [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 697] 
0d 0000003a`2717f660 00007ff6`9c7afc79 CoreRun!wmain+0x146 [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 815] 
0e 0000003a`2717f6c0 00007ff6`9c7afb9e CoreRun!invoke_main+0x39 [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 91] 
0f 0000003a`2717f710 00007ff6`9c7afa5e CoreRun!__scrt_common_main_seh+0x12e [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 288] 
10 0000003a`2717f780 00007ff6`9c7afce9 CoreRun!__scrt_common_main+0xe [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl @ 331] 
11 0000003a`2717f7b0 00007ff9`dd1e7bd4 CoreRun!wmainCRTStartup+0x9 [d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_wmain.cpp @ 17] 

@dotnet dotnet deleted a comment from azure-pipelines bot Sep 25, 2019
@dotnet dotnet deleted a comment from azure-pipelines bot Sep 25, 2019
@dotnet dotnet deleted a comment from azure-pipelines bot Sep 27, 2019
@echesakov echesakov added os-linux Linux OS (any supported distro) os-windows labels Sep 27, 2019
@echesakov
Copy link
Author

/azp run coreclr-outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dotnet dotnet deleted a comment from azure-pipelines bot Sep 28, 2019
@echesakov echesakov marked this pull request as ready for review September 30, 2019 19:08
@echesakov
Copy link
Author

@dotnet/jit-contrib @janvorli PTAL

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@echesakov
Copy link
Author

@BruceForstall These are stack traces when StackOverflow happens in a funclet:

win-x64

(3f9a0.5a370): Stack overflow - code c00000fd (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
*** WARNING: Unable to verify checksum for D:\git\coreclr1\bin\Product\Windows_NT.x64.Checked\CoreCLR.dll
CoreCLR!JIT_StackProbe+0xe:
00007ff9`514b85ae 8500            test    dword ptr [rax],eax ds:000000a1`cdc06fff=00000000
0:000> k
 # Child-SP          RetAddr           Call Site
00 000000a1`cdc0a5b0 00007ff8`f25e8a8a CoreCLR!JIT_StackProbe+0xe [D:\git\coreclr1\src\vm\amd64\JitHelpers_Fast.asm @ 974] 
01 000000a1`cdc0a5b8 00007ff9`5104667b GitHub_21061_Funclets!GitHub_21061.Program.Run_0016C000()+0x8a
02 000000a1`cdc0a5d0 00007ff9`5104646b CoreCLR!ExceptionTracker::CallHandler+0x16f [D:\git\coreclr1\src\vm\exceptionhandling.cpp @ 3424] 
03 000000a1`cdc0a650 00007ff9`51055fc9 CoreCLR!ExceptionTracker::CallCatchHandler+0x427 [D:\git\coreclr1\src\vm\exceptionhandling.cpp @ 656] 
04 000000a1`cdc0a7b0 00007ff9`de28128f CoreCLR!ProcessCLRException+0xb49 [D:\git\coreclr1\src\vm\exceptionhandling.cpp @ 1192] 
05 000000a1`cdc0ac30 00007ff9`de1fda32 ntdll!RtlpExecuteHandlerForUnwind+0xf [minkernel\ntos\rtl\amd64\xcptmisc.asm @ 254] 
06 000000a1`cdc0ac60 00007ff9`51046a49 ntdll!RtlUnwindEx+0x522 [minkernel\ntos\rtl\amd64\exdsptch.c @ 1484] 
07 000000a1`cdc0b370 00007ff9`51055f5a CoreCLR!ClrUnwindEx+0x41 [D:\git\coreclr1\src\vm\exceptionhandling.cpp @ 5340] 
08 000000a1`cdc0b8c0 00007ff9`de28120f CoreCLR!ProcessCLRException+0xada [D:\git\coreclr1\src\vm\exceptionhandling.cpp @ 1147] 
09 000000a1`cdc0bd40 00007ff9`de24a299 ntdll!RtlpExecuteHandlerForException+0xf [minkernel\ntos\rtl\amd64\xcptmisc.asm @ 132] 
0a 000000a1`cdc0bd70 00007ff9`de27fe7e ntdll!RtlDispatchException+0x219 [minkernel\ntos\rtl\amd64\exdsptch.c @ 693] 
0b 000000a1`cdc0c480 00007ff9`dbf7a839 ntdll!KiUserExceptionDispatch+0x2e [minkernel\ntos\rtl\amd64\trampoln.asm @ 749] 
0c 000000a1`cdc0cc10 00007ff9`514b8069 KERNELBASE!RaiseException+0x69 [minkernel\kernelbase\xcpt.c @ 937] 
0d 000000a1`cdc0ccf0 00007ff9`514b809b CoreCLR!NakedThrowHelper2+0x9 [D:\git\coreclr1\src\vm\amd64\RedirectedHandledJITCase.asm @ 229] 
0e 000000a1`cdc0cd20 00007ff9`514b80a5 CoreCLR!NakedThrowHelper_RspAligned+0x1e [D:\git\coreclr1\src\vm\amd64\RedirectedHandledJITCase.asm @ 233] 
0f 000000a1`cdc0d248 00007ff8`f25e8a6a CoreCLR!NakedThrowHelper_FixRsp+0x5 [D:\git\coreclr1\src\vm\amd64\RedirectedHandledJITCase.asm @ 233] 
10 000000a1`cdc0d250 00007ff8`f1c88cba GitHub_21061_Funclets!GitHub_21061.Program.Run_0016C000()+0x6a
11 000000a1`cdd7d290 00007ff9`515d7503 GitHub_21061_Funclets!GitHub_21061.Program.Main(System.String[])+0x72a
12 000000a1`cdd7d2c0 00007ff9`512bded8 CoreCLR!CallDescrWorkerInternal+0x83 [D:\git\coreclr1\src\vm\amd64\CallDescrWorkerAMD64.asm @ 101] 
13 000000a1`cdd7d300 00007ff9`512b3466 CoreCLR!MethodDescCallSite::CallTargetWorker+0x9a8 [D:\git\coreclr1\src\vm\callhelpers.cpp @ 554] 
14 (Inline Function) --------`-------- CoreCLR!MethodDescCallSite::Call+0x16 [D:\git\coreclr1\src\vm\callhelpers.h @ 459] 
15 000000a1`cdd7d7a0 00007ff9`512b3016 CoreCLR!RunMainInternal+0x16e [D:\git\coreclr1\src\vm\assembly.cpp @ 1506] 
16 000000a1`cdd7d9c0 00007ff9`512b3119 CoreCLR!``RunMain'::`30'::__Body::Run'::`5'::__Body::Run+0x76 [D:\git\coreclr1\src\vm\assembly.cpp @ 1577] 
17 000000a1`cdd7da00 00007ff9`512b3291 CoreCLR!`RunMain'::`30'::__Body::Run+0x89 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
18 000000a1`cdd7da60 00007ff9`512aedfc CoreCLR!RunMain+0xf5 [D:\git\coreclr1\src\vm\assembly.cpp @ 1579] 
19 000000a1`cdd7dae0 00007ff9`50f2a245 CoreCLR!Assembly::ExecuteMainMethod+0x208 [D:\git\coreclr1\src\vm\assembly.cpp @ 1689] 
*** WARNING: Unable to verify checksum for CoreRun.exe
1a 000000a1`cdd7df40 00007ff7`418f5f6f CoreCLR!CorHost2::ExecuteAssembly+0x505 [D:\git\coreclr1\src\vm\corhost.cpp @ 461] 
1b 000000a1`cdd7e200 00007ff7`418f748a CoreRun!TryRun+0x73b [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 697] 
1c 000000a1`cdd7f680 00007ff7`4191fc79 CoreRun!wmain+0x146 [D:\git\coreclr1\src\coreclr\hosts\corerun\corerun.cpp @ 815] 

linux-x64

Process 18484 stopped
* thread #1, name = 'corerun', stop reason = signal SIGSEGV: invalid address (fault address: 0x7fffff7fefff)
    frame #0: 0x00007ffff639a0d1 libcoreclr.so`JIT_StackProbe at jithelpers_fast.S:562
   559          or      rsp, (PAGE_SIZE - 1) // rsp points to the last byte on the first unprobed page
   560
   561  LOCAL_LABEL(ProbeLoop):
-> 562          test    dword ptr [rsp], eax
   563          sub     rsp, PAGE_SIZE
   564          cmp     rsp, r11
   565          jge     LOCAL_LABEL(ProbeLoop)
(lldb) bt
* thread #1, name = 'corerun', stop reason = signal SIGSEGV: invalid address (fault address: 0x7fffff7fefff)
  * frame #0: 0x00007ffff639a0d1 libcoreclr.so`JIT_StackProbe at jithelpers_fast.S:562
    frame #1: 0x00007fff7f15c246
    frame #2: 0x00007ffff6380479 libcoreclr.so`ExceptionTracker::CallCatchHandler(this=0x00005555557d7d80, pContextRecord=<unavailable>, pfAborting=0x00007fffff802280) at exceptionhandling.cpp:656:21
    frame #3: 0x00007ffff6381b11 libcoreclr.so`::ProcessCLRException(pExceptionRecord=0x00005555558342c0, MemoryStackFp=140737479989136, pContextRecord=0x00007fffff803a20, pDispatcherContext=0x00007fffff803490) at exceptionhandling.cpp:1192:35
    frame #4: 0x00007ffff6387d0e libcoreclr.so`UnwindManagedExceptionPass2(ex=0x00007fffff804b70, unwindStartContext=<unavailable>) at exceptionhandling.cpp:4489:27
    frame #5: 0x00007ffff6388277 libcoreclr.so`UnwindManagedExceptionPass1(ex=<unavailable>, frameContext=<unavailable>) at exceptionhandling.cpp:4651:17
    frame #6: 0x00007ffff63886a7 libcoreclr.so`DispatchManagedException(ex=<unavailable>, isHardwareException=<unavailable>) at exceptionhandling.cpp:4777:17
    frame #7: 0x00007ffff637f699 libcoreclr.so`HandleHardwareException(ex=0x00007fffff804b70) at exceptionhandling.cpp:5277:9
    frame #8: 0x00007ffff664c430 libcoreclr.so`SEHProcessException(exception=<unavailable>) at seh.cpp:283:21
    frame #9: 0x00007ffff664e050 libcoreclr.so`common_signal_handler(code=<unavailable>, siginfo=<unavailable>, sigcontext=<unavailable>, numParams=<unavailable>) at signal.cpp:814:9
    frame #10: 0x00007ffff664d401 libcoreclr.so`sigfpe_handler(code=8, siginfo=0x00007fffff805330, context=0x00007fffff805200) at signal.cpp:346:13
    frame #11: 0x00007ffff79c4890 libpthread.so.0`___lldb_unnamed_symbol1$$libpthread.so.0 + 1
    frame #12: 0x00007fff7f15c228
    frame #13: 0x00007fff7ce898b2
    frame #14: 0x00007ffff63998fb libcoreclr.so`CallDescrWorkerInternal at unixasmmacrosamd64.inc:866
    frame #15: 0x00007ffff6232139 libcoreclr.so`CallDescrWorkerWithHandler(pCallDescrData=0x00007fffffffd990, fCriticalCall=NO) at callhelpers.cpp:70:5
    frame #16: 0x00007ffff6232b99 libcoreclr.so`MethodDescCallSite::CallTargetWorker(this=<unavailable>, pArguments=0x00007fffffffda98, pReturnValue=<unavailable>, cbReturnValue=<unavailable>) at callhelpers.cpp:546:9
    frame #17: 0x00007ffff63b63cb libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) [inlined] MethodDescCallSite::Call(this=<unavailable>, pArguments=<unavailable>) at callhelpers.h:459:9
    frame #18: 0x00007ffff63b63b4 libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) at assembly.cpp:1505
    frame #19: 0x00007ffff63b619a libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) [inlined] RunMain(MethodDesc*, short, int*, REF<PtrArray>*)::$_1::operator()(Param*) const::'lambda'(Param*)::operator()(Param*) const at assembly.cpp:1577
    frame #20: 0x00007ffff63b619a libcoreclr.so`RunMain(MethodDesc*, short, int*, REF<PtrArray>*) at assembly.cpp:1579
    frame #21: 0x00007ffff63b611b libcoreclr.so`RunMain(pFD=<unavailable>, numSkipArgs=<unavailable>, piRetVal=<unavailable>, stringArgs=<unavailable>) at assembly.cpp:1579
    frame #22: 0x00007ffff63b6812 libcoreclr.so`Assembly::ExecuteMainMethod(this=<unavailable>, stringArgs=0x00007fffffffe048, waitForOtherThreads=YES) at assembly.cpp:1689:18
    frame #23: 0x00007ffff6111108 libcoreclr.so`CorHost2::ExecuteAssembly(this=<unavailable>, dwAppDomainId=<unavailable>, pwzAssemblyPath=<unavailable>, argc=<unavailable>, argv=0x0000000000000000, pReturnValue=<unavailable>) at corhost.cpp:460:39
    frame #24: 0x00007ffff60d823c libcoreclr.so`::coreclr_execute_assembly(hostHandle=<unavailable>, domainId=<unavailable>, argc=<unavailable>, argv=<unavailable>, managedAssemblyPath=<unavailable>, exitCode=<unavailable>) at unixinterface.cpp:407:24
    frame #25: 0x000055555555693e corerun`ExecuteManagedAssembly(currentExeAbsolutePath=<unavailable>, clrFilesAbsolutePath=<unavailable>, managedAssemblyAbsolutePath=<unavailable>, managedAssemblyArgc=<unavailable>, managedAssemblyArgv=0x0000000000000000) at coreruncommon.cpp:476:22
    frame #26: 0x0000555555555a3c corerun`corerun(argc=<unavailable>, argv=<unavailable>) at corerun.cpp:149:20
    frame #27: 0x00007ffff6ca3b97 libc.so.6`__libc_start_main(main=(corerun`main at corerun.cpp:161:12), argc=2, argv=0x00007fffffffe4b8, init=<unavailable>, fini=<unavailable>, rtld_fini=<unavailable>, stack_end=0x00007fffffffe4a8) at libc-start.c:310
    frame #28: 0x0000555555555679 corerun`_start + 41

@BruceForstall
Copy link
Member

BruceForstall commented Oct 2, 2019

EH backtraces look great!

@BruceForstall
Copy link
Member

I know you've got test for this. Would it be worthwhile adding this to the repo, even if it isn't built and run as part of the test tree? (I understand your test is somewhat manual in nature.)

@echesakov
Copy link
Author

echesakov commented Oct 2, 2019

@BruceForstall Sure, I will add the test and T4 template that generates the tests in a separate PR

Copy link
Member

@erozenfeld erozenfeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/inc/corinfo.h Outdated Show resolved Hide resolved
src/inc/readytorun.h Show resolved Hide resolved
end
PAGE_SIZE equ 1000h

LEAF_ENTRY JIT_StackProbe, _TEXT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see a line or two of comments in these asm helpers describing the purpose and function of the helper (what it does), in addition to the register "on entry" / "on exit" documentation (which is super useful).

It would also be useful to indicate what all the requirements are around each helper (as the requirements differ per platform). E.g., on Linux you can't probe beyond ESP/RSP.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BruceForstall I believe I have addressed all your suggestions - please take a look and let me know if I need to clarify anything else


ProbeLoop:
test dword ptr [rax], eax
sub rax, PAGE_SIZE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The probing math is a little tricky, to ensure exactly the right number of pages are probed. I would suggest a couple comments, e.g.:

or      rax, (PAGE_SIZE - 1)   ; rax points to the **highest address** on the first unprobed page
                       ; This is done to make the loop end condition simpler.
...
sub     rax, PAGE_SIZE  ; rax points to the highest address of the next page to probe
...
cmp rax, r11 ; if rax >= r11, then we need to probe the page pointed to by rax.

@@ -955,5 +955,29 @@ endif ; _DEBUG

NESTED_END TailCallHelperStub, _TEXT

end
PAGE_SIZE equ 1000h
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interesting side-effect here is that the page size (that we probe) is hard-coded to 0x1000, whereas in PAL builds, the page size is currently dynamic. For >4K pages, we might over-probe. But I suppose that is ok -- better perhaps than burning a register to pass in the page size, or creating extra page size specific helpers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I though about several options here:

  1. Have several versions of the helpers (e.g. JIT_StackProbe_0x1000 and JIT_StackProbe_0x10000) on platforms that can have different page sizes (e.g. arm64) and do selection when emitting a call to the helper from JIT.
  2. Burn a register and pass a page size from the JIT side (which feels weird to me since JIT asks EE for a page size). It's also going to be tough for find a spare register on x86.
  3. Use a stack for passing parameters and basically do the same as in 2).
  4. Hard-code the page size as I did

I chose 4 and as a contingency plan if there will be a strong requirement for using "true" page size we can add a logic that will patch the helper during the process startup and adjust the page size.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple nits, but otherwise looks good.

src/vm/i386/jithelp.asm Outdated Show resolved Hide resolved
@echesakov echesakov merged commit 2ca2b2b into dotnet:master Oct 7, 2019
@echesakov echesakov deleted the JitStackProbeHelper branch October 7, 2019 16:55
MichalStrehovsky added a commit to MichalStrehovsky/coreclr that referenced this pull request Oct 9, 2019
MichalStrehovsky added a commit that referenced this pull request Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot unwind stack when stack probing hits the stack limit on Unix
7 participants