Change: Limit total script ops that can be consumed by a list valuate
(cherry picked from commit 1d0b40b2b2f2998d96221b18ae65a4d1524c61a7)
This commit is contained in:
6
src/3rdparty/squirrel/squirrel/sqvm.cpp
vendored
6
src/3rdparty/squirrel/squirrel/sqvm.cpp
vendored
@@ -115,6 +115,8 @@ SQVM::SQVM(SQSharedState *ss)
|
||||
_can_suspend = false;
|
||||
_in_stackoverflow = false;
|
||||
_ops_till_suspend = 0;
|
||||
_ops_till_suspend_error_threshold = INT64_MIN;
|
||||
_ops_till_suspend_error_label = nullptr;
|
||||
_callsstack = nullptr;
|
||||
_callsstacksize = 0;
|
||||
_alloccallsstacksize = 0;
|
||||
@@ -743,6 +745,10 @@ exception_restore:
|
||||
{
|
||||
DecreaseOps(1);
|
||||
if (ShouldSuspend()) { _suspended = SQTrue; _suspended_traps = traps; return true; }
|
||||
if (IsOpsTillSuspendError()) {
|
||||
Raise_Error("excessive CPU usage in %s", _ops_till_suspend_error_label);
|
||||
SQ_THROW();
|
||||
}
|
||||
|
||||
const SQInstruction &_i_ = *ci->_ip++;
|
||||
#ifdef _DEBUG_DUMP
|
||||
|
||||
7
src/3rdparty/squirrel/squirrel/sqvm.h
vendored
7
src/3rdparty/squirrel/squirrel/sqvm.h
vendored
@@ -168,6 +168,8 @@ public:
|
||||
|
||||
SQBool _can_suspend;
|
||||
SQInteger _ops_till_suspend;
|
||||
SQInteger _ops_till_suspend_error_threshold;
|
||||
const char *_ops_till_suspend_error_label;
|
||||
SQBool _in_stackoverflow;
|
||||
|
||||
bool ShouldSuspend()
|
||||
@@ -175,6 +177,11 @@ public:
|
||||
return _can_suspend && _ops_till_suspend <= 0;
|
||||
}
|
||||
|
||||
bool IsOpsTillSuspendError()
|
||||
{
|
||||
return _ops_till_suspend < _ops_till_suspend_error_threshold;
|
||||
}
|
||||
|
||||
void DecreaseOps(SQInteger amount)
|
||||
{
|
||||
if (_ops_till_suspend - amount < _ops_till_suspend) _ops_till_suspend -= amount;
|
||||
|
||||
Reference in New Issue
Block a user