added stack overflow prevention
This commit is contained in:
parent
4dc2925b7a
commit
ed226eba6d
4 changed files with 24 additions and 14 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nimrod's Runtime Library
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
# (c) Copyright 2014 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
@ -44,16 +44,6 @@ var
|
|||
# a global variable for the root of all try blocks
|
||||
currException {.rtlThreadVar.}: ref E_Base
|
||||
|
||||
when defined(nimRequiresNimFrame):
|
||||
proc nimFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
|
||||
s.prev = framePtr
|
||||
framePtr = s
|
||||
else:
|
||||
proc pushFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
|
||||
# XXX only for backwards compatibility
|
||||
s.prev = framePtr
|
||||
framePtr = s
|
||||
|
||||
proc popFrame {.compilerRtl, inl.} =
|
||||
framePtr = framePtr.prev
|
||||
|
||||
|
|
@ -280,6 +270,23 @@ proc getStackTrace(e: ref E_Base): string =
|
|||
else:
|
||||
result = ""
|
||||
|
||||
when defined(nimRequiresNimFrame):
|
||||
proc stackOverflow() {.noinline.} =
|
||||
writeStackTrace()
|
||||
showErrorMessage("Stack overflow\n")
|
||||
quitOrDebug()
|
||||
|
||||
proc nimFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
|
||||
s.calldepth = if framePtr == nil: 0 else: framePtr.calldepth+1
|
||||
s.prev = framePtr
|
||||
framePtr = s
|
||||
if s.calldepth == 2000: stackOverflow()
|
||||
else:
|
||||
proc pushFrame(s: PFrame) {.compilerRtl, inl, exportc: "nimFrame".} =
|
||||
# XXX only for backwards compatibility
|
||||
s.prev = framePtr
|
||||
framePtr = s
|
||||
|
||||
when defined(endb):
|
||||
var
|
||||
dbgAborting: bool # whether the debugger wants to abort
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue