mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 15:25:52 +00:00
Bug 1380096 - Don't require that sMainThreadRunnableName is null-terminated, r=erahm
MozReview-Commit-ID: 9Zo1vjmKzZC
This commit is contained in:
parent
5ce4cca339
commit
c93fca087e
@ -138,7 +138,7 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
||||
ScopedSetPtr<NativeStack> nativeStackPtr(mNativeStackToFill, aNativeStack);
|
||||
#endif
|
||||
|
||||
char nameBuffer[1000] = {0};
|
||||
Vector<char, 1000> nameBuffer;
|
||||
auto callback = [&, this] (void** aPCs, size_t aCount, bool aIsMainThread) {
|
||||
// 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,
|
||||
@ -149,9 +149,10 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
||||
// main thread, so we only want to read sMainThreadRunnableName and copy its
|
||||
// value in the case that we are currently suspending the main thread.
|
||||
if (aIsMainThread && nsThread::sMainThreadRunnableName) {
|
||||
strncpy(nameBuffer, nsThread::sMainThreadRunnableName, sizeof(nameBuffer));
|
||||
// Make sure the string is null-terminated.
|
||||
nameBuffer[sizeof(nameBuffer) - 1] = '\0';
|
||||
MOZ_ALWAYS_TRUE(
|
||||
nameBuffer.append(nsThread::sMainThreadRunnableName->BeginReading(),
|
||||
std::min(uint32_t(nameBuffer.sMaxInlineStorage),
|
||||
uint32_t(nsThread::sMainThreadRunnableName->Length()))));
|
||||
}
|
||||
|
||||
#ifdef MOZ_THREADSTACKHELPER_PSEUDO
|
||||
@ -177,8 +178,8 @@ ThreadStackHelper::GetStacksInternal(Stack* aStack,
|
||||
}
|
||||
|
||||
// Copy the name buffer allocation into the output string.
|
||||
if (nameBuffer[0] != 0) {
|
||||
aRunnableName = nameBuffer;
|
||||
if (nameBuffer.length() > 0) {
|
||||
aRunnableName.AssignASCII(nameBuffer.begin(), nameBuffer.length());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ static LazyLogModule sThreadLog("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
|
||||
@ -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
|
||||
// name in a static so that BHR can record it.
|
||||
const char* restoreRunnableName = nullptr;
|
||||
const nsACString* restoreRunnableName = nullptr;
|
||||
auto clear = MakeScopeExit([&] {
|
||||
if (MAIN_THREAD == mIsMainThread) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
sMainThreadRunnableName = restoreRunnableName;
|
||||
}
|
||||
});
|
||||
if (MAIN_THREAD == mIsMainThread) {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
restoreRunnableName = sMainThreadRunnableName;
|
||||
sMainThreadRunnableName = name.get();
|
||||
sMainThreadRunnableName = &name;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -93,7 +93,7 @@ public:
|
||||
static bool SaveMemoryReportNearOOM(ShouldSaveMemoryReport aShouldSave);
|
||||
#endif
|
||||
|
||||
static const char* sMainThreadRunnableName;
|
||||
static const nsACString* sMainThreadRunnableName;
|
||||
|
||||
private:
|
||||
void DoMainThreadSpecificProcessing(bool aReallyWait);
|
||||
|
Loading…
Reference in New Issue
Block a user