summaryrefslogtreecommitdiff
path: root/src/mongo/scripting
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2015-10-26 13:02:08 -0400
committerAndrew Morrow <acm@mongodb.com>2015-10-27 08:06:43 -0400
commit1a95eb42b15e2e1ecf905765530cb10c12340d38 (patch)
tree0e256a0d6c8a6e55d3d42034d7b77f5aabd0845a /src/mongo/scripting
parente556e4763ad88c3308347b56b4831c46b014627e (diff)
downloadmongo-1a95eb42b15e2e1ecf905765530cb10c12340d38.tar.gz
SERVER-19614 Use stack bounds to limit JS recursion
Diffstat (limited to 'src/mongo/scripting')
-rw-r--r--src/mongo/scripting/mozjs/implscope.cpp24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.cpp b/src/mongo/scripting/mozjs/implscope.cpp
index 6b10c52f6b0..bde92513bb0 100644
--- a/src/mongo/scripting/mozjs/implscope.cpp
+++ b/src/mongo/scripting/mozjs/implscope.cpp
@@ -38,6 +38,7 @@
#include "mongo/base/error_codes.h"
#include "mongo/db/operation_context.h"
#include "mongo/platform/decimal128.h"
+#include "mongo/platform/stack_locator.h"
#include "mongo/scripting/mozjs/objectwrapper.h"
#include "mongo/scripting/mozjs/valuereader.h"
#include "mongo/scripting/mozjs/valuewriter.h"
@@ -227,13 +228,22 @@ MozJSImplScope::MozRuntime::MozRuntime() {
_runtime = JS_NewRuntime(kMaxBytesBeforeGC);
- // TODO: Re-enable this when it can be done in a way that does
- // not conflict with the performance fix in SERVER-20678. The
- // jscore/recursion.js tes tshould be re-enabled when this is
- // uncommented.
- //
- // static_assert(kMaxStackBytes > (32 * 1024), "kMaxStackBytes must be larger than 32k");
- // JS_SetNativeStackQuota(_runtime, kMaxStackBytes - (32 * 1024));
+ const StackLocator locator;
+ const auto available = locator.available();
+ if (available) {
+ // We fudge by 64k for a two reasons. First, it appears
+ // that the internal recursion checks that SM performs can
+ // have stack usage between checks of more than 32k in
+ // some builds. Second, some platforms report the guard
+ // page (in the linux sense) as "part of the stack", even
+ // though accessing that page will fault the process. We
+ // don't have a good way of getting information about the
+ // guard page on those platforms.
+ //
+ // TODO: What if we are running on a platform with very
+ // large pages, like 4MB?
+ JS_SetNativeStackQuota(_runtime, available.get() - (64 * 1024));
+ }
}
uassert(ErrorCodes::JSInterpreterFailure, "Failed to initialize JSRuntime", _runtime);