diff options
author | David Mason <davmason@microsoft.com> | 2019-10-30 11:26:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-30 11:26:32 -0700 |
commit | 93584136cf938d5f65e98e3bb7f0580526ae0716 (patch) | |
tree | 62d743e39fc0bea8b6acdfa59a326dd7c96ccb8d /src/vm | |
parent | d336d32e608e6c18ec4d089524ea1920e44f6737 (diff) | |
download | coreclr-93584136cf938d5f65e98e3bb7f0580526ae0716.tar.gz coreclr-93584136cf938d5f65e98e3bb7f0580526ae0716.tar.bz2 coreclr-93584136cf938d5f65e98e3bb7f0580526ae0716.zip |
[Release/3.1] Port profiler APIs to set and retrieve environment variables to 3.1 (#27512)
Diffstat (limited to 'src/vm')
-rw-r--r-- | src/vm/proftoeeinterfaceimpl.cpp | 90 | ||||
-rw-r--r-- | src/vm/proftoeeinterfaceimpl.h | 16 |
2 files changed, 105 insertions, 1 deletions
diff --git a/src/vm/proftoeeinterfaceimpl.cpp b/src/vm/proftoeeinterfaceimpl.cpp index e0caccf4a2..2a8a46c468 100644 --- a/src/vm/proftoeeinterfaceimpl.cpp +++ b/src/vm/proftoeeinterfaceimpl.cpp @@ -594,6 +594,10 @@ COM_METHOD ProfToEEInterfaceImpl::QueryInterface(REFIID id, void ** pInterface) { *pInterface = static_cast<ICorProfilerInfo10 *>(this); } + else if (id == IID_ICorProfilerInfo11) + { + *pInterface = static_cast<ICorProfilerInfo11 *>(this); + } else if (id == IID_IUnknown) { *pInterface = static_cast<IUnknown *>(static_cast<ICorProfilerInfo *>(this)); @@ -7009,6 +7013,92 @@ HRESULT ProfToEEInterfaceImpl::ResumeRuntime() return S_OK; } +HRESULT ProfToEEInterfaceImpl::GetEnvironmentVariable( + const WCHAR *szName, + ULONG cchValue, + ULONG *pcchValue, + __out_ecount_part_opt(cchValue, *pcchValue) WCHAR szValue[]) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + MODE_ANY; + EE_THREAD_NOT_REQUIRED; + CANNOT_TAKE_LOCK; + + PRECONDITION(CheckPointer(szName, NULL_NOT_OK)); + PRECONDITION(CheckPointer(pcchValue, NULL_OK)); + PRECONDITION(CheckPointer(szValue, NULL_OK)); + } + CONTRACTL_END; + + PROFILER_TO_CLR_ENTRYPOINT_ASYNC_EX(kP2EEAllowableAfterAttach, + (LF_CORPROF, + LL_INFO1000, + "**PROF: GetEnvironmentVariable.\n")); + + if (szName == nullptr) + { + return E_INVALIDARG; + } + + if ((cchValue != 0) && (szValue == nullptr)) + { + return E_INVALIDARG; + } + + HRESULT hr = S_OK; + + if ((pcchValue != nullptr) || (szValue != nullptr)) + { + DWORD trueLen = GetEnvironmentVariableW(szName, szValue, cchValue); + if (trueLen == 0) + { + hr = HRESULT_FROM_WIN32(GetLastError()); + } + else if ((trueLen > cchValue) && (szValue != nullptr)) + { + hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + } + + if (pcchValue != nullptr) + { + *pcchValue = trueLen; + } + } + + return hr; +} + +HRESULT ProfToEEInterfaceImpl::SetEnvironmentVariable(const WCHAR *szName, const WCHAR *szValue) +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + MODE_ANY; + EE_THREAD_NOT_REQUIRED; + CANNOT_TAKE_LOCK; + + PRECONDITION(CheckPointer(szName, NULL_NOT_OK)); + PRECONDITION(CheckPointer(szValue, NULL_OK)); + } + CONTRACTL_END; + + PROFILER_TO_CLR_ENTRYPOINT_ASYNC_EX(kP2EEAllowableAfterAttach, + (LF_CORPROF, + LL_INFO1000, + "**PROF: SetEnvironmentVariable.\n")); + + if (szName == nullptr) + { + return E_INVALIDARG; + } + + return SetEnvironmentVariableW(szName, szValue) ? S_OK : HRESULT_FROM_WIN32(GetLastError()); +} + /* * GetStringLayout * diff --git a/src/vm/proftoeeinterfaceimpl.h b/src/vm/proftoeeinterfaceimpl.h index bc4b13d23c..c8f9ffacf5 100644 --- a/src/vm/proftoeeinterfaceimpl.h +++ b/src/vm/proftoeeinterfaceimpl.h @@ -141,7 +141,7 @@ typedef struct _PROFILER_STACK_WALK_DATA PROFILER_STACK_WALK_DATA; // from the profiler implementation. The profiler will call back on the v-table // to get at EE internals as required. -class ProfToEEInterfaceImpl : public ICorProfilerInfo10 +class ProfToEEInterfaceImpl : public ICorProfilerInfo11 { public: @@ -628,6 +628,20 @@ public: // end ICorProfilerInfo10 + // begin ICorProfilerInfo11 + + COM_METHOD GetEnvironmentVariable( + const WCHAR *szName, + ULONG cchValue, + ULONG *pcchValue, + __out_ecount_part_opt(cchValue, *pcchValue) WCHAR szValue[]); + + COM_METHOD SetEnvironmentVariable( + const WCHAR *szName, + const WCHAR *szValue); + + // end ICorProfilerInfo11 + protected: // Internal Helper Functions |