mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-05 11:24:08 +00:00
added stack overflow prevention
This commit is contained in:
@@ -328,7 +328,8 @@ struct TFrame {
|
||||
NCSTRING procname;
|
||||
NI line;
|
||||
NCSTRING filename;
|
||||
NI len;
|
||||
NI16 len;
|
||||
NI16 calldepth;
|
||||
};
|
||||
|
||||
#define nimfr(proc, file) \
|
||||
|
||||
@@ -2001,7 +2001,8 @@ type
|
||||
procname*: cstring ## name of the proc that is currently executing
|
||||
line*: int ## line number of the proc that is currently executing
|
||||
filename*: cstring ## filename of the proc that is currently executing
|
||||
len*: int ## length of the inspectable slots
|
||||
len*: int16 ## length of the inspectable slots
|
||||
calldepth*: int16 ## used for max call depth checking
|
||||
|
||||
when defined(JS):
|
||||
proc add*(x: var string, y: cstring) {.asmNoStackFrame.} =
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,8 @@ News
|
||||
now considered for implicit early binding.
|
||||
- ``c2nim`` moved into its own repository and is now a Babel package.
|
||||
- ``pas2nim`` moved into its own repository and is now a Babel package.
|
||||
|
||||
- ``system.$`` for floating point types now produces a human friendly string
|
||||
representation.
|
||||
|
||||
Library Additions
|
||||
-----------------
|
||||
|
||||
Reference in New Issue
Block a user