Browse Source

handle exception for ReadProcessMemory/WriteProcessMemory as well

Lei Shi 9 years ago
parent
commit
4613d284f2

+ 1 - 0
lib/Backend/CodeGenNumberAllocator.cpp

@@ -333,6 +333,7 @@ Js::JavascriptNumber* XProcNumberPageSegmentImpl::AllocateNumber(Func* func, dou
             if (!WriteProcessMemory(hProcess, (void*)number, pLocalNumber, sizeCat, &bytesWritten)
                 || 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
             }

+ 1 - 0
lib/Common/Memory/CustomHeap.cpp

@@ -1069,6 +1069,7 @@ void FillDebugBreak(_In_ BYTE* buffer, __in size_t byteCount, HANDLE processHand
     {
         if (!WriteProcessMemory(processHandle, buffer, writeBuffer, byteCount, NULL))
         {
+            Js::Throw::CheckAndThrowJITOperationFailed();
             Js::Throw::FatalInternalError();
         }
         HeapDeleteArray(byteCount, writeBuffer);

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

@@ -24,6 +24,8 @@ 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);
@@ -48,6 +50,7 @@ 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 - 0
lib/Common/Memory/PageAllocator.cpp

@@ -933,6 +933,7 @@ PageAllocatorBase<T>::FillAllocPages(__in void * address, uint pageCount)
         readBuffer = HeapNewArray(byte, bufferSize);
         if (!ReadProcessMemory(this->processHandle, address, readBuffer, bufferSize, NULL))
         {
+            Js::Throw::CheckAndThrowJITOperationFailed();
             Js::Throw::InternalError();
         }
     }