diff options
author | Jason Carey <jcarey@argv.me> | 2017-03-15 16:43:49 -0400 |
---|---|---|
committer | Jason Carey <jcarey@argv.me> | 2017-04-07 15:20:21 -0400 |
commit | 96f0fbd7911533fd4279742d81cf53b198d71b03 (patch) | |
tree | ce1167a7846b9a257abc20a15f23cebbe9599c2d /src/mongo/scripting/mozjs/implscope.h | |
parent | f2e400cce0948f8274e84b54c7da2b1e3d9dc2a5 (diff) | |
download | mongo-96f0fbd7911533fd4279742d81cf53b198d71b03.tar.gz |
SERVER-22520 Improve ASAN MozJS integration
ASAN has trouble dealing with the heap allocations SpiderMonkey
produces, due to the storage format of those pointers (tagged punbox'd
types). Keeping a side std::unordered_set<void*> which tracks
allocations provides the reachability ASAN needs for a little bit of
extra book keeping.
Diffstat (limited to 'src/mongo/scripting/mozjs/implscope.h')
-rw-r--r-- | src/mongo/scripting/mozjs/implscope.h | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/mongo/scripting/mozjs/implscope.h b/src/mongo/scripting/mozjs/implscope.h index b50bad81ca3..9569b7afbc6 100644 --- a/src/mongo/scripting/mozjs/implscope.h +++ b/src/mongo/scripting/mozjs/implscope.h @@ -61,6 +61,7 @@ #include "mongo/scripting/mozjs/regexp.h" #include "mongo/scripting/mozjs/timestamp.h" #include "mongo/scripting/mozjs/uri.h" +#include "mongo/stdx/unordered_set.h" namespace mongo { namespace mozjs { @@ -297,9 +298,6 @@ public: return _uriProto; } - void setQuickExit(int exitCode); - bool getQuickExit(int* exitCode); - static const char* const kExecResult; static const char* const kInvokeResult; @@ -318,6 +316,31 @@ public: std::string buildStackString(); + template <typename T, typename... Args> + T* trackedNew(Args&&... args) { + T* t = new T(std::forward<Args>(args)...); + _asanHandles.addPointer(t); + return t; + } + + template <typename T> + void trackedDelete(T* t) { + _asanHandles.removePointer(t); + delete (t); + } + + struct ASANHandles { + ASANHandles(); + ~ASANHandles(); + + void addPointer(void* ptr); + void removePointer(void* ptr); + + stdx::unordered_set<void*> _handles; + + static ASANHandles* getThreadASANHandles(); + }; + private: void _MozJSCreateFunction(const char* raw, ScriptingFunction functionNumber, @@ -363,6 +386,7 @@ private: void setCompileOptions(JS::CompileOptions* co); + ASANHandles _asanHandles; MozJSScriptEngine* _engine; MozRuntime _mr; JSRuntime* _runtime; @@ -379,8 +403,6 @@ private: std::atomic<bool> _pendingGC; ConnectState _connectState; Status _status; - int _exitCode; - bool _quickExit; std::string _parentStack; std::size_t _generation; bool _hasOutOfMemoryException; @@ -418,5 +440,9 @@ inline MozJSImplScope* getScope(JSContext* cx) { return static_cast<MozJSImplScope*>(JS_GetContextPrivate(cx)); } +inline MozJSImplScope* getScope(JSFreeOp* fop) { + return static_cast<MozJSImplScope*>(JS_GetRuntimePrivate(fop->runtime())); +} + } // namespace mozjs } // namespace mongo |