summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorGabriel Russell <gabriel.russell@mongodb.com>2017-09-27 12:52:16 +0000
committerGabriel Russell <gabriel.russell@mongodb.com>2017-10-06 15:20:48 -0400
commitd1105687533de0db72f2ceba0cd5f2612145c956 (patch)
treeb428d9ff1972190032dd5c5957c3f4ea4e9222c5 /src/mongo
parent6fa2b1b62a2a53a96f7ea535f26dff0be8f8bae2 (diff)
downloadmongo-d1105687533de0db72f2ceba0cd5f2612145c956.tar.gz
SERVER-31271 don't use nspr allocator for js threads for better ASAN
We can't use the nspr allocator to allocate threads in PR_CreateThread, because under asan instrument the allocator so that asan can track the pointers correctly. This instrumentation requires that pointers be deleted in the same thread that they were allocated in. The threads created in PR_CreateThread are not always freed in the same thread that they were created in. So, we use the standard allocator here.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/scripting/mozjs/PosixNSPR.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/mongo/scripting/mozjs/PosixNSPR.cpp b/src/mongo/scripting/mozjs/PosixNSPR.cpp
index ed1a3d5a49d..9054e930443 100644
--- a/src/mongo/scripting/mozjs/PosixNSPR.cpp
+++ b/src/mongo/scripting/mozjs/PosixNSPR.cpp
@@ -24,6 +24,7 @@
#include "mongo/stdx/chrono.h"
#include "mongo/stdx/condition_variable.h"
+#include "mongo/stdx/memory.h"
#include "mongo/stdx/mutex.h"
#include "mongo/stdx/thread.h"
#include "mongo/util/concurrency/thread_name.h"
@@ -98,9 +99,13 @@ PRThread* PR_CreateThread(PRThreadType type,
MOZ_ASSERT(priority == PR_PRIORITY_NORMAL);
try {
- std::unique_ptr<nspr::Thread, void (*)(nspr::Thread*)> t(
- js_new<nspr::Thread>(start, arg, state != PR_UNJOINABLE_THREAD),
- js_delete_nonconst<nspr::Thread>);
+ // We can't use the nspr allocator to allocate this thread, because under asan we
+ // instrument the allocator so that asan can track the pointers correctly. This
+ // instrumentation
+ // requires that pointers be deleted in the same thread that they were allocated in.
+ // The threads created in PR_CreateThread are not always freed in the same thread
+ // that they were created in. So, we use the standard allocator here.
+ auto t = mongo::stdx::make_unique<nspr::Thread>(start, arg, state != PR_UNJOINABLE_THREAD);
t->thread() = mongo::stdx::thread(&nspr::Thread::ThreadRoutine, t.get());
@@ -118,7 +123,7 @@ PRStatus PR_JoinThread(PRThread* thread) {
try {
thread->thread().join();
- js_delete(thread);
+ delete thread;
return PR_SUCCESS;
} catch (...) {