|
|
@@ -128,22 +128,37 @@ ServerCleanupProcess(
|
|
|
/* [in] */ handle_t binding,
|
|
|
/* [in] */ intptr_t processHandle)
|
|
|
{
|
|
|
+ ServerContextManager::CleanUpForProcess((HANDLE)processHandle);
|
|
|
CloseHandle((HANDLE)processHandle);
|
|
|
return S_OK;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+void
|
|
|
+__RPC_USER PTHREADCONTEXT_HANDLE_rundown(__RPC__in PTHREADCONTEXT_HANDLE phContext)
|
|
|
+{
|
|
|
+ ServerCleanupThreadContext(nullptr, &phContext);
|
|
|
+}
|
|
|
+
|
|
|
+void
|
|
|
+__RPC_USER PSCRIPTCONTEXT_HANDLE_rundown(__RPC__in PSCRIPTCONTEXT_HANDLE phContext)
|
|
|
+{
|
|
|
+ ServerCloseScriptContext(nullptr, phContext);
|
|
|
+ ServerCleanupScriptContext(nullptr, &phContext);
|
|
|
+}
|
|
|
+
|
|
|
HRESULT
|
|
|
ServerInitializeThreadContext(
|
|
|
/* [in] */ handle_t binding,
|
|
|
/* [in] */ __RPC__in ThreadContextDataIDL * threadContextData,
|
|
|
- /* [out] */ __RPC__out intptr_t *threadContextRoot,
|
|
|
+ /* [out] */ __RPC__out PPTHREADCONTEXT_HANDLE threadContextInfoAddress,
|
|
|
/* [out] */ __RPC__out intptr_t *prereservedRegionAddr)
|
|
|
{
|
|
|
ServerThreadContext * contextInfo = nullptr;
|
|
|
try
|
|
|
{
|
|
|
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory));
|
|
|
- contextInfo = HeapNew(ServerThreadContext, threadContextData);
|
|
|
+ contextInfo = (ServerThreadContext*)HeapNew(ServerThreadContext, threadContextData);
|
|
|
ServerContextManager::RegisterThreadContext(contextInfo);
|
|
|
}
|
|
|
catch (Js::OutOfMemoryException)
|
|
|
@@ -153,7 +168,7 @@ ServerInitializeThreadContext(
|
|
|
|
|
|
return ServerCallWrapper(contextInfo, [&]()->HRESULT
|
|
|
{
|
|
|
- *threadContextRoot = (intptr_t)EncodePointer(contextInfo);
|
|
|
+ *threadContextInfoAddress = (PTHREADCONTEXT_HANDLE)EncodePointer(contextInfo);
|
|
|
*prereservedRegionAddr = (intptr_t)contextInfo->GetPreReservedVirtualAllocator()->EnsurePreReservedRegion();
|
|
|
|
|
|
return S_OK;
|
|
|
@@ -163,15 +178,19 @@ ServerInitializeThreadContext(
|
|
|
HRESULT
|
|
|
ServerCleanupThreadContext(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t threadContextRoot)
|
|
|
+ /* [in] */ PPTHREADCONTEXT_HANDLE threadContextInfoAddress)
|
|
|
{
|
|
|
- ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextRoot);
|
|
|
+ ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer(*threadContextInfoAddress);
|
|
|
if (threadContextInfo == nullptr)
|
|
|
{
|
|
|
Assert(false);
|
|
|
return RPC_S_INVALID_ARG;
|
|
|
}
|
|
|
|
|
|
+ // This tells the run-time, when it is marshalling the out
|
|
|
+ // parameters, that the context handle has been closed normally.
|
|
|
+ *threadContextInfoAddress = nullptr;
|
|
|
+
|
|
|
return ServerCallWrapper(threadContextInfo, [&]()->HRESULT
|
|
|
{
|
|
|
threadContextInfo->Close();
|
|
|
@@ -183,10 +202,10 @@ ServerCleanupThreadContext(
|
|
|
HRESULT
|
|
|
ServerUpdatePropertyRecordMap(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t threadContextInfoAddress,
|
|
|
+ /* [in] */ PTHREADCONTEXT_HANDLE threadContextInfoAddress,
|
|
|
/* [in] */ __RPC__in UpdatedPropertysIDL * updatedProps)
|
|
|
{
|
|
|
- ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextInfoAddress);
|
|
|
+ ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer(threadContextInfoAddress);
|
|
|
|
|
|
if (threadContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -213,11 +232,11 @@ ServerUpdatePropertyRecordMap(
|
|
|
HRESULT
|
|
|
ServerAddDOMFastPathHelper(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextRoot,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress,
|
|
|
/* [in] */ intptr_t funcInfoAddr,
|
|
|
/* [in] */ int helper)
|
|
|
{
|
|
|
- ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextRoot);
|
|
|
+ ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
|
|
|
if (scriptContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -235,11 +254,11 @@ ServerAddDOMFastPathHelper(
|
|
|
HRESULT
|
|
|
ServerAddModuleRecordInfo(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextInfoAddress,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress,
|
|
|
/* [in] */ unsigned int moduleId,
|
|
|
/* [in] */ intptr_t localExportSlotsAddr)
|
|
|
{
|
|
|
- ServerScriptContext * serverScriptContext = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress);
|
|
|
+ ServerScriptContext * serverScriptContext = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
if (serverScriptContext == nullptr)
|
|
|
{
|
|
|
Assert(false);
|
|
|
@@ -254,13 +273,13 @@ ServerAddModuleRecordInfo(
|
|
|
|
|
|
}
|
|
|
|
|
|
-HRESULT
|
|
|
+HRESULT
|
|
|
ServerSetWellKnownHostTypeId(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t threadContextRoot,
|
|
|
+ /* [in] */ PTHREADCONTEXT_HANDLE threadContextInfoAddress,
|
|
|
/* [in] */ int typeId)
|
|
|
{
|
|
|
- ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextRoot);
|
|
|
+ ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer(threadContextInfoAddress);
|
|
|
|
|
|
if (threadContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -279,10 +298,10 @@ HRESULT
|
|
|
ServerInitializeScriptContext(
|
|
|
/* [in] */ handle_t binding,
|
|
|
/* [in] */ __RPC__in ScriptContextDataIDL * scriptContextData,
|
|
|
- /* [in] */ intptr_t threadContextInfoAddress,
|
|
|
- /* [out] */ __RPC__out intptr_t * scriptContextInfoAddress)
|
|
|
+ /* [in] */ PTHREADCONTEXT_HANDLE threadContextInfoAddress,
|
|
|
+ /* [out] */ __RPC__out PPSCRIPTCONTEXT_HANDLE scriptContextInfoAddress)
|
|
|
{
|
|
|
- ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextInfoAddress);
|
|
|
+ ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer(threadContextInfoAddress);
|
|
|
|
|
|
*scriptContextInfoAddress = 0;
|
|
|
if (threadContextInfo == nullptr)
|
|
|
@@ -295,7 +314,7 @@ ServerInitializeScriptContext(
|
|
|
{
|
|
|
ServerScriptContext * contextInfo = HeapNew(ServerScriptContext, scriptContextData, threadContextInfo);
|
|
|
ServerContextManager::RegisterScriptContext(contextInfo);
|
|
|
- *scriptContextInfoAddress = (intptr_t)EncodePointer(contextInfo);
|
|
|
+ *scriptContextInfoAddress = (PSCRIPTCONTEXT_HANDLE)EncodePointer(contextInfo);
|
|
|
|
|
|
#if !FLOATVAR
|
|
|
// TODO: should move this to ServerInitializeThreadContext, also for the fields in IDL
|
|
|
@@ -308,9 +327,9 @@ ServerInitializeScriptContext(
|
|
|
HRESULT
|
|
|
ServerCleanupScriptContext(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextRoot)
|
|
|
+ /* [in] */ PPSCRIPTCONTEXT_HANDLE scriptContextInfoAddress)
|
|
|
{
|
|
|
- ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextRoot);
|
|
|
+ ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer(*scriptContextInfoAddress);
|
|
|
|
|
|
if (scriptContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -318,6 +337,10 @@ ServerCleanupScriptContext(
|
|
|
return RPC_S_INVALID_ARG;
|
|
|
}
|
|
|
|
|
|
+ // This tells the run-time, when it is marshalling the out
|
|
|
+ // parameters, that the context handle has been closed normally.
|
|
|
+ *scriptContextInfoAddress = nullptr;
|
|
|
+
|
|
|
Assert(scriptContextInfo->IsClosed());
|
|
|
HeapDelete(scriptContextInfo);
|
|
|
|
|
|
@@ -327,9 +350,9 @@ ServerCleanupScriptContext(
|
|
|
HRESULT
|
|
|
ServerCloseScriptContext(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextRoot)
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress)
|
|
|
{
|
|
|
- ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextRoot);
|
|
|
+ ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
|
|
|
if (scriptContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -356,11 +379,11 @@ ServerCloseScriptContext(
|
|
|
HRESULT
|
|
|
ServerNewInterpreterThunkBlock(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextInfo,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfo,
|
|
|
/* [in] */ boolean asmJsThunk,
|
|
|
/* [out] */ __RPC__out InterpreterThunkInfoIDL * thunkInfo)
|
|
|
{
|
|
|
- ServerScriptContext * scriptContext = (ServerScriptContext *)DecodePointer((void*)scriptContextInfo);
|
|
|
+ ServerScriptContext * scriptContext = (ServerScriptContext *)DecodePointer(scriptContextInfo);
|
|
|
|
|
|
memset(thunkInfo, 0, sizeof(InterpreterThunkInfoIDL));
|
|
|
|
|
|
@@ -434,10 +457,10 @@ ServerNewInterpreterThunkBlock(
|
|
|
HRESULT
|
|
|
ServerFreeAllocation(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t threadContextInfo,
|
|
|
+ /* [in] */ PTHREADCONTEXT_HANDLE threadContextInfo,
|
|
|
/* [in] */ intptr_t address)
|
|
|
{
|
|
|
- ServerThreadContext * context = (ServerThreadContext*)DecodePointer((void*)threadContextInfo);
|
|
|
+ ServerThreadContext * context = (ServerThreadContext*)DecodePointer(threadContextInfo);
|
|
|
|
|
|
if (context == nullptr)
|
|
|
{
|
|
|
@@ -445,7 +468,7 @@ ServerFreeAllocation(
|
|
|
return RPC_S_INVALID_ARG;
|
|
|
}
|
|
|
|
|
|
- return ServerCallWrapper(context, [&]()->HRESULT
|
|
|
+ return ServerCallWrapper(context, [&]()->HRESULT
|
|
|
{
|
|
|
if (CONFIG_FLAG(OOPCFGRegistration))
|
|
|
{
|
|
|
@@ -460,12 +483,12 @@ ServerFreeAllocation(
|
|
|
HRESULT
|
|
|
ServerIsInterpreterThunkAddr(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextInfoAddress,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress,
|
|
|
/* [in] */ intptr_t address,
|
|
|
/* [in] */ boolean asmjsThunk,
|
|
|
/* [out] */ __RPC__out boolean * result)
|
|
|
{
|
|
|
- ServerScriptContext * context = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress);
|
|
|
+ ServerScriptContext * context = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
|
|
|
if (context == nullptr)
|
|
|
{
|
|
|
@@ -488,11 +511,11 @@ ServerIsInterpreterThunkAddr(
|
|
|
HRESULT
|
|
|
ServerIsNativeAddr(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t threadContextInfo,
|
|
|
+ /* [in] */ PTHREADCONTEXT_HANDLE threadContextInfo,
|
|
|
/* [in] */ intptr_t address,
|
|
|
/* [out] */ __RPC__out boolean * result)
|
|
|
{
|
|
|
- ServerThreadContext * context = (ServerThreadContext*)DecodePointer((void*)threadContextInfo);
|
|
|
+ ServerThreadContext * context = (ServerThreadContext*)DecodePointer(threadContextInfo);
|
|
|
|
|
|
*result = false;
|
|
|
if (context == nullptr)
|
|
|
@@ -525,10 +548,10 @@ ServerIsNativeAddr(
|
|
|
HRESULT
|
|
|
ServerSetIsPRNGSeeded(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextInfoAddress,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress,
|
|
|
/* [in] */ boolean value)
|
|
|
{
|
|
|
- ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress);
|
|
|
+ ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
|
|
|
if (scriptContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -546,13 +569,13 @@ ServerSetIsPRNGSeeded(
|
|
|
HRESULT
|
|
|
ServerRemoteCodeGen(
|
|
|
/* [in] */ handle_t binding,
|
|
|
- /* [in] */ intptr_t scriptContextInfoAddress,
|
|
|
+ /* [in] */ PSCRIPTCONTEXT_HANDLE scriptContextInfoAddress,
|
|
|
/* [in] */ __RPC__in CodeGenWorkItemIDL *workItemData,
|
|
|
/* [out] */ __RPC__out JITOutputIDL *jitData)
|
|
|
{
|
|
|
memset(jitData, 0, sizeof(JITOutputIDL));
|
|
|
|
|
|
- ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress);
|
|
|
+ ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer(scriptContextInfoAddress);
|
|
|
|
|
|
if (scriptContextInfo == nullptr)
|
|
|
{
|
|
|
@@ -686,7 +709,7 @@ void ServerContextManager::UnRegisterThreadContext(ServerThreadContext* threadCo
|
|
|
{
|
|
|
ServerScriptContext* scriptContext = iter.Current().Key();
|
|
|
if (scriptContext->GetThreadContext() == threadContext)
|
|
|
- {
|
|
|
+ {
|
|
|
if (!scriptContext->IsClosed())
|
|
|
{
|
|
|
scriptContext->Close();
|
|
|
@@ -773,30 +796,6 @@ bool ServerContextManager::CheckLivenessAndAddref(ServerThreadContext* context)
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void ServerContextManager::IdleCleanup()
|
|
|
-{
|
|
|
- JsUtil::BaseHashSet<HANDLE, HeapAllocator> clientProcesses(&HeapAllocator::Instance);
|
|
|
- {
|
|
|
- AutoCriticalSection autoCS(&cs);
|
|
|
- threadContexts.Map([&clientProcesses](ServerThreadContext* threadContext)
|
|
|
- {
|
|
|
- if (!clientProcesses.ContainsKey(threadContext->GetProcessHandle()))
|
|
|
- {
|
|
|
- clientProcesses.Add(threadContext->GetProcessHandle());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- clientProcesses.Map([](HANDLE hProcess)
|
|
|
- {
|
|
|
- DWORD exitCode = STILL_ACTIVE;
|
|
|
- if (!GetExitCodeProcess(hProcess, &exitCode) && exitCode != STILL_ACTIVE)
|
|
|
- {
|
|
|
- CleanUpForProcess(hProcess);
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
template<typename Fn>
|
|
|
HRESULT ServerCallWrapper(ServerThreadContext* threadContextInfo, Fn fn)
|
|
|
{
|
|
|
@@ -807,19 +806,6 @@ HRESULT ServerCallWrapper(ServerThreadContext* threadContextInfo, Fn fn)
|
|
|
AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
|
|
|
AutoReleaseThreadContext autoThreadContext(threadContextInfo);
|
|
|
hr = fn();
|
|
|
-
|
|
|
- DWORD exitCode = STILL_ACTIVE;
|
|
|
- if (!GetExitCodeProcess(threadContextInfo->GetProcessHandle(), &exitCode))
|
|
|
- {
|
|
|
- Assert(false); // fail to check target process
|
|
|
- hr = E_FAIL;
|
|
|
- }
|
|
|
-
|
|
|
- if (exitCode != STILL_ACTIVE)
|
|
|
- {
|
|
|
- ServerContextManager::CleanUpForProcess(threadContextInfo->GetProcessHandle());
|
|
|
- hr = E_FAIL;
|
|
|
- }
|
|
|
}
|
|
|
catch (ContextClosedException&)
|
|
|
{
|