Przeglądaj źródła

address review comments

Lei Shi 9 lat temu
rodzic
commit
46e3e99e34

+ 0 - 1
lib/Backend/CodeGenNumberAllocator.cpp

@@ -334,7 +334,6 @@ Js::JavascriptNumber* XProcNumberPageSegmentImpl::AllocateNumber(Func* func, dou
                 || bytesWritten != sizeCat)
             {
                 Js::Throw::CheckAndThrowJITOperationFailed();
-                Output::Print(_u("FATAL ERROR: WriteProcessMemory failed, GLE: %d\n"), GetLastError());
                 Js::Throw::FatalInternalError(); // TODO: don't bring down whole server process, but pass the last error to main process
             }
 

+ 0 - 1
lib/Backend/NativeCodeGenerator.cpp

@@ -896,7 +896,6 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
     {
         HRESULT hr = JITManager::GetJITManager()->RemoteCodeGenCall(
             workItem->GetJITData(),
-            scriptContext->GetThreadContext()->GetRemoteThreadContextAddr(),
             scriptContext->GetRemoteScriptAddr(),
             &jitWriteData);
         JITManager::HandleServerCallResult(hr);

+ 0 - 2
lib/Common/Memory/MemUtils.cpp

@@ -25,7 +25,6 @@ Memory::ChakraMemSet(_In_ void *dst, int val, size_t sizeInBytes, HANDLE process
         if (!WriteProcessMemory(processHandle, dst, writeBuffer, sizeInBytes, NULL))
         {
             Js::Throw::CheckAndThrowJITOperationFailed();
-            // if it's not E_ACCESSDENIED
             Js::Throw::FatalInternalError();
         }
         HeapDeleteArray(sizeInBytes, writeBuffer);
@@ -49,7 +48,6 @@ Memory::ChakraMemCopy(_In_ void *dst, size_t sizeInBytes, _In_reads_bytes_(count
     {
         if (!WriteProcessMemory(processHandle, dst, src, count, NULL))
         {
-            Output::Print(_u("FATAL ERROR: WriteProcessMemory failed, GLE: %d\n"), GetLastError());
             Js::Throw::CheckAndThrowJITOperationFailed();
             Js::Throw::FatalInternalError();
         }

+ 1 - 2
lib/JITClient/JITManager.cpp

@@ -548,7 +548,6 @@ JITManager::IsNativeAddr(
 HRESULT
 JITManager::RemoteCodeGenCall(
     __in CodeGenWorkItemIDL *workItemData,
-    __in intptr_t threadContextInfoAddress,
     __in intptr_t scriptContextInfoAddress,
     __out JITOutputIDL *jitData)
 {
@@ -557,7 +556,7 @@ JITManager::RemoteCodeGenCall(
     HRESULT hr = E_FAIL;
     RpcTryExcept
     {
-        hr = ClientRemoteCodeGen(m_rpcBindingHandle, threadContextInfoAddress, scriptContextInfoAddress, workItemData, jitData);
+        hr = ClientRemoteCodeGen(m_rpcBindingHandle, scriptContextInfoAddress, workItemData, jitData);
     }
         RpcExcept(RpcExceptionFilter(RpcExceptionCode()))
     {

+ 0 - 1
lib/JITClient/JITManager.h

@@ -73,7 +73,6 @@ public:
 
     HRESULT RemoteCodeGenCall(
         __in CodeGenWorkItemIDL *workItemData,
-        __in intptr_t threadContextInfoAddress,
         __in intptr_t scriptContextInfoAddress,
         __out JITOutputIDL *jitData);
 

+ 0 - 1
lib/JITIDL/ChakraJIT.idl

@@ -81,7 +81,6 @@ interface IChakraJIT
 
     HRESULT RemoteCodeGen(
         [in] handle_t binding,
-        [in] CHAKRA_PTR threadContextInfoAddress,
         [in] CHAKRA_PTR scriptContextInfoAddress,
         [in] CodeGenWorkItemIDL * workItemData,
         [out] JITOutputIDL * jitData);

+ 20 - 29
lib/JITServer/JITServer.cpp

@@ -132,17 +132,21 @@ ServerInitializeThreadContext(
     AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
 
     ServerThreadContext * contextInfo = HeapNewNoThrow(ServerThreadContext, threadContextData);
-    if (contextInfo == nullptr) 
+    if (contextInfo == nullptr)
     {
         return E_OUTOFMEMORY;
     }
 
-    ServerContextManager::RegisterThreadContext(contextInfo);
+    AutoReleaseContext<ServerThreadContext> autoThreadContext(contextInfo);
+    return ServerCallWrapper(contextInfo, [&]()->HRESULT
+    {
+        ServerContextManager::RegisterThreadContext(contextInfo);
 
-    *threadContextRoot = (intptr_t)EncodePointer(contextInfo);
-    *prereservedRegionAddr = (intptr_t)contextInfo->GetPreReservedVirtualAllocator()->EnsurePreReservedRegion();
-   
-    return S_OK;
+        *threadContextRoot = (intptr_t)EncodePointer(contextInfo);
+        *prereservedRegionAddr = (intptr_t)contextInfo->GetPreReservedVirtualAllocator()->EnsurePreReservedRegion();
+
+        return S_OK;
+    });
 }
 
 HRESULT
@@ -285,12 +289,9 @@ ServerSetWellKnownHostTypeId(
     }
 
     AutoReleaseContext<ServerThreadContext> autoThreadContext(threadContextInfo);
-    return ServerCallWrapper(threadContextInfo, [&]()->HRESULT
-    {
-        threadContextInfo->SetWellKnownHostTypeId((Js::TypeId)typeId);
-        return S_OK;
-    });
+    threadContextInfo->SetWellKnownHostTypeId((Js::TypeId)typeId);
 
+    return S_OK;
 }
 
 HRESULT
@@ -374,15 +375,13 @@ ServerCleanupScriptContext(
         return RPC_S_INVALID_ARG;
     }
 
-    if (!ServerContextManager::IsScriptContextAlive(scriptContextInfo))
+    if (ServerContextManager::IsScriptContextAlive(scriptContextInfo))
     {
-        return E_ACCESSDENIED;
+        AutoReleaseContext<ServerScriptContext> autoScriptContext(scriptContextInfo);        
+        scriptContextInfo->Close();
+        ServerContextManager::UnRegisterScriptContext(scriptContextInfo);
     }
 
-    AutoReleaseContext<ServerScriptContext> autoScriptContext(scriptContextInfo);
-
-    scriptContextInfo->Close();
-    ServerContextManager::UnRegisterScriptContext(scriptContextInfo);
     return S_OK;
 }
 
@@ -486,14 +485,11 @@ ServerSetIsPRNGSeeded(
 HRESULT
 ServerRemoteCodeGen(
     /* [in] */ handle_t binding,
-    /* [in] */ intptr_t threadContextInfoAddress,
     /* [in] */ intptr_t scriptContextInfoAddress,
     /* [in] */ __RPC__in CodeGenWorkItemIDL *workItemData,
     /* [out] */ __RPC__out JITOutputIDL *jitData)
 {
-    UNREFERENCED_PARAMETER(binding);
     AUTO_NESTED_HANDLED_EXCEPTION_TYPE(static_cast<ExceptionType>(ExceptionType_OutOfMemory | ExceptionType_StackOverflow));
-
     LARGE_INTEGER start_time = { 0 };
     if (PHASE_TRACE1(Js::BackEndPhase))
     {
@@ -501,29 +497,24 @@ ServerRemoteCodeGen(
     }
     memset(jitData, 0, sizeof(JITOutputIDL));
 
-    ServerThreadContext * threadContextInfo = (ServerThreadContext*)DecodePointer((void*)threadContextInfoAddress);
     ServerScriptContext * scriptContextInfo = (ServerScriptContext*)DecodePointer((void*)scriptContextInfoAddress);
 
-    if (threadContextInfo == nullptr || scriptContextInfo == nullptr)
+    if (scriptContextInfo == nullptr)
     {
         return RPC_S_INVALID_ARG;
     }
 
-    if (!ServerContextManager::IsThreadContextAlive(threadContextInfo))
-    {
-        return E_ACCESSDENIED;
-    }
-
     if (!ServerContextManager::IsScriptContextAlive(scriptContextInfo))
     {
         return E_ACCESSDENIED;
     }
 
-    AutoReleaseContext<ServerThreadContext> autoThreadContext(threadContextInfo);
     AutoReleaseContext<ServerScriptContext> autoScriptContext(scriptContextInfo);
 
-    return ServerCallWrapper(threadContextInfo, [&]() ->HRESULT
+    return ServerCallWrapper(scriptContextInfo, [&]() ->HRESULT
     {
+        ServerThreadContext * threadContextInfo = scriptContextInfo->GetThreadContext();
+
         NoRecoverMemoryJitArenaAllocator jitArena(L"JITArena", threadContextInfo->GetPageAllocator(), Js::Throw::OutOfMemory);
         JITTimeWorkItem * jitWorkItem = Anew(&jitArena, JITTimeWorkItem, workItemData);