Bug 1380096 - Don't require that sMainThreadRunnableName is null-terminated, r=erahm
MozReview-Commit-ID: 9Zo1vjmKzZC
This commit is contained in:
@@ -138,7 +138,7 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
|||||||
ScopedSetPtr<NativeStack> nativeStackPtr(mNativeStackToFill, aNativeStack);
|
ScopedSetPtr<NativeStack> nativeStackPtr(mNativeStackToFill, aNativeStack);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char nameBuffer[1000] = {0};
|
Vector<char, 1000> nameBuffer;
|
||||||
auto callback = [&, this] (void** aPCs, size_t aCount, bool aIsMainThread) {
|
auto callback = [&, this] (void** aPCs, size_t aCount, bool aIsMainThread) {
|
||||||
// NOTE: We cannot allocate any memory in this callback, as the target
|
// NOTE: We cannot allocate any memory in this callback, as the target
|
||||||
// thread is suspended, so we first copy it into a stack-allocated buffer,
|
// thread is suspended, so we first copy it into a stack-allocated buffer,
|
||||||
@@ -149,9 +149,10 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
|||||||
// main thread, so we only want to read sMainThreadRunnableName and copy its
|
// main thread, so we only want to read sMainThreadRunnableName and copy its
|
||||||
// value in the case that we are currently suspending the main thread.
|
// value in the case that we are currently suspending the main thread.
|
||||||
if (aIsMainThread && nsThread::sMainThreadRunnableName) {
|
if (aIsMainThread && nsThread::sMainThreadRunnableName) {
|
||||||
strncpy(nameBuffer, nsThread::sMainThreadRunnableName, sizeof(nameBuffer));
|
MOZ_ALWAYS_TRUE(
|
||||||
// Make sure the string is null-terminated.
|
nameBuffer.append(nsThread::sMainThreadRunnableName->BeginReading(),
|
||||||
nameBuffer[sizeof(nameBuffer) - 1] = '\0';
|
std::min(uint32_t(nameBuffer.sMaxInlineStorage),
|
||||||
|
uint32_t(nsThread::sMainThreadRunnableName->Length()))));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef MOZ_THREADSTACKHELPER_PSEUDO
|
#ifdef MOZ_THREADSTACKHELPER_PSEUDO
|
||||||
@@ -177,8 +178,8 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copy the name buffer allocation into the output string.
|
// Copy the name buffer allocation into the output string.
|
||||||
if (nameBuffer[0] != 0) {
|
if (nameBuffer.length() > 0) {
|
||||||
aRunnableName = nameBuffer;
|
aRunnableName.AssignASCII(nameBuffer.begin(), nameBuffer.length());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ static LazyLogModule sThreadLog("nsThread");
|
|||||||
|
|
||||||
NS_DECL_CI_INTERFACE_GETTER(nsThread)
|
NS_DECL_CI_INTERFACE_GETTER(nsThread)
|
||||||
|
|
||||||
const char* nsThread::sMainThreadRunnableName = nullptr;
|
const nsACString* nsThread::sMainThreadRunnableName = nullptr;
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Because we do not have our own nsIFactory, we have to implement nsIClassInfo
|
// Because we do not have our own nsIFactory, we have to implement nsIClassInfo
|
||||||
@@ -1422,15 +1422,17 @@ nsThread::ProcessNextEvent(bool aMayWait, bool* aResult)
|
|||||||
|
|
||||||
// If we're on the main thread, we want to record our current runnable's
|
// If we're on the main thread, we want to record our current runnable's
|
||||||
// name in a static so that BHR can record it.
|
// name in a static so that BHR can record it.
|
||||||
const char* restoreRunnableName = nullptr;
|
const nsACString* restoreRunnableName = nullptr;
|
||||||
auto clear = MakeScopeExit([&] {
|
auto clear = MakeScopeExit([&] {
|
||||||
if (MAIN_THREAD == mIsMainThread) {
|
if (MAIN_THREAD == mIsMainThread) {
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
sMainThreadRunnableName = restoreRunnableName;
|
sMainThreadRunnableName = restoreRunnableName;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (MAIN_THREAD == mIsMainThread) {
|
if (MAIN_THREAD == mIsMainThread) {
|
||||||
|
MOZ_ASSERT(NS_IsMainThread());
|
||||||
restoreRunnableName = sMainThreadRunnableName;
|
restoreRunnableName = sMainThreadRunnableName;
|
||||||
sMainThreadRunnableName = name.get();
|
sMainThreadRunnableName = &name;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public:
|
|||||||
static bool SaveMemoryReportNearOOM(ShouldSaveMemoryReport aShouldSave);
|
static bool SaveMemoryReportNearOOM(ShouldSaveMemoryReport aShouldSave);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char* sMainThreadRunnableName;
|
static const nsACString* sMainThreadRunnableName;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void DoMainThreadSpecificProcessing(bool aReallyWait);
|
void DoMainThreadSpecificProcessing(bool aReallyWait);
|
||||||
|
|||||||
Reference in New Issue
Block a user