mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 989499 - Part 1: Add a way to get the stack top. r=BenWa
This commit is contained in:
parent
e4b6aa22d0
commit
789be3e18f
48
tools/profiler/core/StackTop.cpp
Normal file
48
tools/profiler/core/StackTop.cpp
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifdef XP_MACOSX
|
||||||
|
#include <mach/task.h>
|
||||||
|
#include <mach/thread_act.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#elif XP_WIN
|
||||||
|
#include <windows.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "StackTop.h"
|
||||||
|
|
||||||
|
void *GetStackTop(void *guess) {
|
||||||
|
#if defined(XP_MACOSX)
|
||||||
|
pthread_t thread = pthread_self();
|
||||||
|
return pthread_get_stackaddr_np(thread);
|
||||||
|
#elif defined(XP_WIN)
|
||||||
|
#if defined(_MSC_VER) && defined(_M_IX86)
|
||||||
|
// offset 0x18 from the FS segment register gives a pointer to
|
||||||
|
// the thread information block for the current thread
|
||||||
|
NT_TIB* pTib;
|
||||||
|
__asm {
|
||||||
|
MOV EAX, FS:[18h]
|
||||||
|
MOV pTib, EAX
|
||||||
|
}
|
||||||
|
return static_cast<void*>(pTib->StackBase);
|
||||||
|
#elif defined(__GNUC__) && defined(i386)
|
||||||
|
// offset 0x18 from the FS segment register gives a pointer to
|
||||||
|
// the thread information block for the current thread
|
||||||
|
NT_TIB* pTib;
|
||||||
|
asm ( "movl %%fs:0x18, %0\n"
|
||||||
|
: "=r" (pTib)
|
||||||
|
);
|
||||||
|
return static_cast<void*>(pTib->StackBase);
|
||||||
|
#elif defined(_M_X64) || defined(__x86_64)
|
||||||
|
PNT_TIB64 pTib = reinterpret_cast<PNT_TIB64>(NtCurrentTeb());
|
||||||
|
return static_cast<void*>(pTib->StackBase);
|
||||||
|
#else
|
||||||
|
#error Need a way to get the stack bounds on this platform (Windows)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
return guess;
|
||||||
|
#endif
|
||||||
|
}
|
10
tools/profiler/core/StackTop.h
Normal file
10
tools/profiler/core/StackTop.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
#ifndef MOZ_STACK_TOP_H
|
||||||
|
#define MOZ_STACK_TOP_H
|
||||||
|
void *GetStackTop(void *guess);
|
||||||
|
#endif
|
@ -950,7 +950,7 @@ void mozilla_sampler_unlock()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mozilla_sampler_register_thread(const char* aName, void* stackTop)
|
bool mozilla_sampler_register_thread(const char* aName, void* aGuessStackTop)
|
||||||
{
|
{
|
||||||
if (sInitCount == 0) {
|
if (sInitCount == 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -969,6 +969,7 @@ bool mozilla_sampler_register_thread(const char* aName, void* stackTop)
|
|||||||
PseudoStack* stack = PseudoStack::create();
|
PseudoStack* stack = PseudoStack::create();
|
||||||
tlsPseudoStack.set(stack);
|
tlsPseudoStack.set(stack);
|
||||||
bool isMainThread = is_main_thread_name(aName);
|
bool isMainThread = is_main_thread_name(aName);
|
||||||
|
void* stackTop = GetStackTop(aGuessStackTop);
|
||||||
return Sampler::RegisterCurrentThread(aName, stack, isMainThread, stackTop);
|
return Sampler::RegisterCurrentThread(aName, stack, isMainThread, stackTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
#include "PlatformMacros.h"
|
#include "PlatformMacros.h"
|
||||||
#include "v8-support.h"
|
#include "v8-support.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "StackTop.h"
|
||||||
|
|
||||||
// We need a definition of gettid(), but glibc doesn't provide a
|
// We need a definition of gettid(), but glibc doesn't provide a
|
||||||
// wrapper for it.
|
// wrapper for it.
|
||||||
|
@ -32,6 +32,7 @@ if CONFIG['MOZ_ENABLE_PROFILER_SPS']:
|
|||||||
'core/ProfileJSONWriter.cpp',
|
'core/ProfileJSONWriter.cpp',
|
||||||
'core/ProfilerBacktrace.cpp',
|
'core/ProfilerBacktrace.cpp',
|
||||||
'core/ProfilerMarkers.cpp',
|
'core/ProfilerMarkers.cpp',
|
||||||
|
'core/StackTop.cpp',
|
||||||
'core/SyncProfile.cpp',
|
'core/SyncProfile.cpp',
|
||||||
'core/ThreadInfo.cpp',
|
'core/ThreadInfo.cpp',
|
||||||
'core/ThreadProfile.cpp',
|
'core/ThreadProfile.cpp',
|
||||||
|
@ -215,7 +215,7 @@ static inline void profiler_lock() {}
|
|||||||
// Re-enable the profiler and notify 'profiler-unlocked'.
|
// Re-enable the profiler and notify 'profiler-unlocked'.
|
||||||
static inline void profiler_unlock() {}
|
static inline void profiler_unlock() {}
|
||||||
|
|
||||||
static inline void profiler_register_thread(const char* name, void* stackTop) {}
|
static inline void profiler_register_thread(const char* name, void* guessStackTop) {}
|
||||||
static inline void profiler_unregister_thread() {}
|
static inline void profiler_unregister_thread() {}
|
||||||
|
|
||||||
// These functions tell the profiler that a thread went to sleep so that we can avoid
|
// These functions tell the profiler that a thread went to sleep so that we can avoid
|
||||||
|
@ -204,9 +204,9 @@ void profiler_unlock()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
void profiler_register_thread(const char* name, void* stackTop)
|
void profiler_register_thread(const char* name, void* guessStackTop)
|
||||||
{
|
{
|
||||||
mozilla_sampler_register_thread(name, stackTop);
|
mozilla_sampler_register_thread(name, guessStackTop);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
|
Loading…
Reference in New Issue
Block a user