Bug 970643 - Valgrind does not understand OdinMonkey's guard page mechanism. r=luke.

This commit is contained in:
Julian Seward 2014-03-20 23:23:48 +01:00
parent e88569a5ca
commit 880659951c
2 changed files with 37 additions and 2 deletions

View File

@ -15,6 +15,10 @@
# include <sys/mman.h>
#endif
#ifdef MOZ_VALGRIND
# include <valgrind/memcheck.h>
#endif
#include "jsapi.h"
#include "jsarray.h"
#include "jscntxt.h"
@ -428,10 +432,16 @@ ArrayBufferObject::prepareForAsmJS(JSContext *cx, Handle<ArrayBufferObject*> buf
return false;
}
# else
if (mprotect(data, buffer->byteLength(), PROT_READ | PROT_WRITE)) {
size_t validLength = buffer->byteLength();
if (mprotect(data, validLength, PROT_READ | PROT_WRITE)) {
munmap(data, AsmJSMappedSize);
return false;
}
# if defined(MOZ_VALGRIND) && defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
// Tell Valgrind/Memcheck to not report accesses in the inaccessible region.
VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE((unsigned char*)data + validLength,
AsmJSMappedSize-validLength);
# endif
# endif
// Copy over the current contents of the typed array.
@ -458,6 +468,13 @@ ArrayBufferObject::releaseAsmJSArray(FreeOp *fop)
VirtualFree(data, 0, MEM_RELEASE);
# else
munmap(data, AsmJSMappedSize);
# if defined(MOZ_VALGRIND) && defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
// Tell Valgrind/Memcheck to recommence reporting accesses in the
// previously-inaccessible region.
if (AsmJSMappedSize > 0) {
VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(data, AsmJSMappedSize);
}
# endif
# endif
}
#else /* defined(JS_ION) && defined(JS_CPU_X64) */

View File

@ -15,6 +15,10 @@
# include <sys/mman.h>
#endif
#ifdef MOZ_VALGRIND
# include <valgrind/memcheck.h>
#endif
#include "mozilla/Atomics.h"
#include "jit/AsmJS.h"
@ -79,10 +83,16 @@ SharedArrayRawBuffer::New(uint32_t length)
if (!p)
return nullptr;
if (!MarkValidRegion(p, AsmJSPageSize + length)) {
size_t validLength = AsmJSPageSize + length;
if (!MarkValidRegion(p, validLength)) {
UnmapMemory(p, AsmJSMappedSize);
return nullptr;
}
# if defined(MOZ_VALGRIND) && defined(VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE)
// Tell Valgrind/Memcheck to not report accesses in the inaccessible region.
VALGRIND_DISABLE_ADDR_ERROR_REPORTING_IN_RANGE((unsigned char*)p + validLength,
AsmJSMappedSize-validLength);
# endif
#else
uint32_t allocSize = length + AsmJSPageSize;
if (allocSize <= length)
@ -116,6 +126,14 @@ SharedArrayRawBuffer::dropReference()
JS_ASSERT(uintptr_t(p) % AsmJSPageSize == 0);
#ifdef JS_CPU_X64
UnmapMemory(p, AsmJSMappedSize);
# if defined(MOZ_VALGRIND) \
&& defined(VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE)
// Tell Valgrind/Memcheck to recommence reporting accesses in the
// previously-inaccessible region.
if (AsmJSMappedSize > 0) {
VALGRIND_ENABLE_ADDR_ERROR_REPORTING_IN_RANGE(p, AsmJSMappedSize);
}
# endif
#else
UnmapMemory(p, this->length + AsmJSPageSize);
#endif