mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-08 19:04:45 +00:00
Backed out changeset 6d913c78ba72 (bug 1207753) for causing build bustages in memory/replace/logalloc/LogAlloc.cpp CLOSED TREE
This commit is contained in:
parent
ec7d45d247
commit
1ae6fdb86e
@ -15,13 +15,12 @@
|
||||
# include <pthread.h>
|
||||
#endif
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/ThreadSafety.h"
|
||||
|
||||
// Mutexes based on spinlocks. We can't use normal pthread spinlocks in all
|
||||
// places, because they require malloc()ed memory, which causes bootstrapping
|
||||
// issues in some cases. We also can't use constructors, because for statics,
|
||||
// they would fire after the first use of malloc, resetting the locks.
|
||||
struct CAPABILITY Mutex {
|
||||
struct Mutex {
|
||||
#if defined(XP_WIN)
|
||||
CRITICAL_SECTION mMutex;
|
||||
#elif defined(XP_DARWIN)
|
||||
@ -57,7 +56,7 @@ struct CAPABILITY Mutex {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void Lock() CAPABILITY_ACQUIRE() {
|
||||
inline void Lock() {
|
||||
#if defined(XP_WIN)
|
||||
EnterCriticalSection(&mMutex);
|
||||
#elif defined(XP_DARWIN)
|
||||
@ -67,7 +66,7 @@ struct CAPABILITY Mutex {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void Unlock() CAPABILITY_RELEASE() {
|
||||
inline void Unlock() {
|
||||
#if defined(XP_WIN)
|
||||
LeaveCriticalSection(&mMutex);
|
||||
#elif defined(XP_DARWIN)
|
||||
@ -86,14 +85,12 @@ struct CAPABILITY Mutex {
|
||||
// Ideally, we'd use the same type of locks everywhere, but SRWLocks
|
||||
// everywhere incur a performance penalty. See bug 1418389.
|
||||
#if defined(XP_WIN)
|
||||
struct CAPABILITY StaticMutex {
|
||||
struct StaticMutex {
|
||||
SRWLOCK mMutex;
|
||||
|
||||
inline void Lock() CAPABILITY_ACQUIRE() { AcquireSRWLockExclusive(&mMutex); }
|
||||
inline void Lock() { AcquireSRWLockExclusive(&mMutex); }
|
||||
|
||||
inline void Unlock() CAPABILITY_RELEASE() {
|
||||
ReleaseSRWLockExclusive(&mMutex);
|
||||
}
|
||||
inline void Unlock() { ReleaseSRWLockExclusive(&mMutex); }
|
||||
};
|
||||
|
||||
// Normally, we'd use a constexpr constructor, but MSVC likes to create
|
||||
@ -114,15 +111,10 @@ typedef Mutex StaticMutex;
|
||||
#endif
|
||||
|
||||
template <typename T>
|
||||
struct SCOPED_CAPABILITY MOZ_RAII AutoLock {
|
||||
explicit AutoLock(T& aMutex) CAPABILITY_ACQUIRE(aMutex) : mMutex(aMutex) {
|
||||
mMutex.Lock();
|
||||
}
|
||||
struct MOZ_RAII AutoLock {
|
||||
explicit AutoLock(T& aMutex) : mMutex(aMutex) { mMutex.Lock(); }
|
||||
|
||||
~AutoLock() CAPABILITY_RELEASE() { mMutex.Unlock(); }
|
||||
|
||||
AutoLock(const AutoLock&) = delete;
|
||||
AutoLock(AutoLock&&) = delete;
|
||||
~AutoLock() { mMutex.Unlock(); }
|
||||
|
||||
private:
|
||||
T& mMutex;
|
||||
|
@ -793,16 +793,14 @@ class GMut {
|
||||
MOZ_RELEASE_ASSERT(page.mBaseAddr == aPtr);
|
||||
|
||||
if (page.mState == AllocPageState::Freed) {
|
||||
LOG("EnsureValidAndInUse(%p), use-after-free\n", aPtr);
|
||||
// An operation on a freed page? This is a particular kind of
|
||||
// use-after-free. Deliberately touch the page in question, in order to
|
||||
// cause a crash that triggers the usual PHC machinery. But unlock sMutex
|
||||
// first, because that self-same PHC machinery needs to re-lock it, and
|
||||
// the crash causes non-local control flow so sMutex won't be unlocked
|
||||
// the normal way in the caller.
|
||||
PUSH_IGNORE_THREAD_SAFETY
|
||||
LOG("EnsureValidAndInUse(%p), use-after-free\n", aPtr);
|
||||
sMutex.Unlock();
|
||||
POP_THREAD_SAFETY
|
||||
*static_cast<uint8_t*>(aPtr) = 0;
|
||||
MOZ_CRASH("unreachable");
|
||||
}
|
||||
@ -879,8 +877,8 @@ class GMut {
|
||||
*aInfo = {TagUnknown, nullptr, 0, 0};
|
||||
}
|
||||
|
||||
static void prefork() CAPABILITY_ACQUIRE(sMutex) { sMutex.Lock(); }
|
||||
static void postfork_parent() CAPABILITY_RELEASE(sMutex) { sMutex.Unlock(); }
|
||||
static void prefork() { sMutex.Lock(); }
|
||||
static void postfork_parent() { sMutex.Unlock(); }
|
||||
static void postfork_child() { sMutex.Init(); }
|
||||
|
||||
void IncPageAllocHits(GMutLock) { mPageAllocHits++; }
|
||||
|
Loading…
Reference in New Issue
Block a user