summaryrefslogtreecommitdiff
path: root/src/vm/proftoeeinterfaceimpl.cpp
diff options
context:
space:
mode:
authorDavid Mason <davmason@microsoft.com>2019-06-05 17:30:46 -0700
committerGitHub <noreply@github.com>2019-06-05 17:30:46 -0700
commit8cb41af71ecff4e53fd02242b2710fcf6a4102ac (patch)
tree1fa854316ff86a2d2b4d13f9b97780918a59f10e /src/vm/proftoeeinterfaceimpl.cpp
parent3dd303f0004ed4771bc29167df30efda07e4cf7e (diff)
downloadcoreclr-8cb41af71ecff4e53fd02242b2710fcf6a4102ac.tar.gz
coreclr-8cb41af71ecff4e53fd02242b2710fcf6a4102ac.tar.bz2
coreclr-8cb41af71ecff4e53fd02242b2710fcf6a4102ac.zip
APIs to allow profilers to use DoStackSnapShot on Linux (#24968)
Diffstat (limited to 'src/vm/proftoeeinterfaceimpl.cpp')
-rw-r--r--src/vm/proftoeeinterfaceimpl.cpp80
1 files changed, 67 insertions, 13 deletions
diff --git a/src/vm/proftoeeinterfaceimpl.cpp b/src/vm/proftoeeinterfaceimpl.cpp
index 4d9b733856..13bf2a4b4b 100644
--- a/src/vm/proftoeeinterfaceimpl.cpp
+++ b/src/vm/proftoeeinterfaceimpl.cpp
@@ -6938,6 +6938,71 @@ HRESULT ProfToEEInterfaceImpl::GetLOHObjectSizeThreshold(DWORD *pThreshold)
return S_OK;
}
+HRESULT ProfToEEInterfaceImpl::SuspendRuntime()
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_TRIGGERS;
+ MODE_ANY;
+ CAN_TAKE_LOCK;
+ EE_THREAD_NOT_REQUIRED;
+ }
+ CONTRACTL_END;
+
+ PROFILER_TO_CLR_ENTRYPOINT_SYNC_EX(
+ kP2EEAllowableAfterAttach | kP2EETriggers,
+ (LF_CORPROF,
+ LL_INFO1000,
+ "**PROF: SuspendRuntime\n"));
+
+ if (!g_fEEStarted)
+ {
+ return CORPROF_E_RUNTIME_UNINITIALIZED;
+ }
+
+ if (ThreadSuspend::SysIsSuspendInProgress() || (ThreadSuspend::GetSuspensionThread() != 0))
+ {
+ return CORPROF_E_SUSPENSION_IN_PROGRESS;
+ }
+
+ g_profControlBlock.fProfilerRequestedRuntimeSuspend = TRUE;
+ ThreadSuspend::SuspendEE(ThreadSuspend::SUSPEND_REASON::SUSPEND_FOR_PROFILER);
+ return S_OK;
+}
+
+HRESULT ProfToEEInterfaceImpl::ResumeRuntime()
+{
+ CONTRACTL
+ {
+ NOTHROW;
+ GC_TRIGGERS;
+ MODE_ANY;
+ CAN_TAKE_LOCK;
+ }
+ CONTRACTL_END;
+
+ PROFILER_TO_CLR_ENTRYPOINT_SYNC_EX(
+ kP2EEAllowableAfterAttach | kP2EETriggers,
+ (LF_CORPROF,
+ LL_INFO1000,
+ "**PROF: ResumeRuntime\n"));
+
+ if (!g_fEEStarted)
+ {
+ return CORPROF_E_RUNTIME_UNINITIALIZED;
+ }
+
+ if (!g_profControlBlock.fProfilerRequestedRuntimeSuspend)
+ {
+ return CORPROF_E_UNSUPPORTED_CALL_SEQUENCE;
+ }
+
+ ThreadSuspend::RestartEE(FALSE /* bFinishedGC */, TRUE /* SuspendSucceeded */);
+ g_profControlBlock.fProfilerRequestedRuntimeSuspend = FALSE;
+ return S_OK;
+}
+
/*
* GetStringLayout
*
@@ -7796,15 +7861,6 @@ HRESULT ProfToEEInterfaceImpl::DoStackSnapshot(ThreadID thread,
BYTE * pbContext,
ULONG32 contextSize)
{
-
-#if !defined(FEATURE_HIJACK)
-
- // DoStackSnapshot needs Thread::Suspend/ResumeThread functionality.
- // On platforms w/o support for these APIs return E_NOTIMPL.
- return E_NOTIMPL;
-
-#else // !defined(FEATURE_HIJACK)
-
CONTRACTL
{
// Yay! (Note: NOTHROW is vital. The throw at minimum allocates
@@ -7968,7 +8024,7 @@ HRESULT ProfToEEInterfaceImpl::DoStackSnapshot(ThreadID thread,
HostCallPreference hostCallPreference;
// First, check "1) Target thread to walk == current thread OR Target thread is suspended"
- if (pThreadToSnapshot != pCurrentThread)
+ if (pThreadToSnapshot != pCurrentThread && !g_profControlBlock.fProfilerRequestedRuntimeSuspend)
{
#ifndef PLATFORM_SUPPORTS_SAFE_THREADSUSPEND
hr = E_NOTIMPL;
@@ -8151,7 +8207,7 @@ HRESULT ProfToEEInterfaceImpl::DoStackSnapshot(ThreadID thread,
// inlined P/Invoke. In this case, the InlinedCallFrame will be used to help start off our
// stackwalk at the top of the stack.
//
- if (pThreadToSnapshot != pCurrentThread)
+ if (pThreadToSnapshot != pCurrentThread && !g_profControlBlock.fProfilerRequestedRuntimeSuspend)
{
#ifndef PLATFORM_SUPPORTS_SAFE_THREADSUSPEND
hr = E_NOTIMPL;
@@ -8253,8 +8309,6 @@ Cleanup:
}
return hr;
-
-#endif // !defined(FEATURE_HIJACK)
}