OLD | NEW |
(Empty) | |
| 1 ; Copyright 2017 The Crashpad Authors. All rights reserved. |
| 2 ; |
| 3 ; Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 ; you may not use this file except in compliance with the License. |
| 5 ; You may obtain a copy of the License at |
| 6 ; |
| 7 ; http://www.apache.org/licenses/LICENSE-2.0 |
| 8 ; |
| 9 ; Unless required by applicable law or agreed to in writing, software |
| 10 ; distributed under the License is distributed on an "AS IS" BASIS, |
| 11 ; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 ; See the License for the specific language governing permissions and |
| 13 ; limitations under the License. |
| 14 |
| 15 ; Detect ml64 assembling for x86_64 by checking for rax. |
| 16 ifdef rax |
| 17 _M_X64 equ 1 |
| 18 else |
| 19 _M_IX86 equ 1 |
| 20 endif |
| 21 |
| 22 ifdef _M_IX86 |
| 23 .586 |
| 24 .xmm |
| 25 .model flat |
| 26 |
| 27 includelib kernel32.lib |
| 28 |
| 29 extern __imp__TerminateProcess@8:proc |
| 30 |
| 31 ; namespace crashpad { |
| 32 ; bool SafeTerminateProcess(HANDLE process, UINT exit_code); |
| 33 ; } // namespace crashpad |
| 34 SAFETERMINATEPROCESS_SYMBOL equ ?SafeTerminateProcess@crashpad@@YA_NPAXI@Z |
| 35 |
| 36 _TEXT segment |
| 37 public SAFETERMINATEPROCESS_SYMBOL |
| 38 |
| 39 SAFETERMINATEPROCESS_SYMBOL proc |
| 40 |
| 41 ; This function is written in assembler source because it’s important for it |
| 42 ; to not be inlined, for it to allocate a stack frame, and most critically, |
| 43 ; for it to not trust esp on return from TerminateProcess(). |
| 44 ; __declspec(noinline) can prevent inlining and #pragma optimize("y", off) can |
| 45 ; disable frame pointer omission, but there’s no way to force a C compiler to |
| 46 ; distrust esp, and even if there was a way, it’d probably be fragile. |
| 47 |
| 48 push ebp |
| 49 mov ebp, esp |
| 50 |
| 51 push [ebp+12] |
| 52 push [ebp+8] |
| 53 call dword ptr [__imp__TerminateProcess@8] |
| 54 |
| 55 ; Convert from BOOL to bool. |
| 56 test eax, eax |
| 57 setne al |
| 58 |
| 59 ; TerminateProcess() is supposed to be stdcall (callee clean-up), and esp and |
| 60 ; ebp are expected to already be equal. But if it’s been patched badly by |
| 61 ; something that’s cdecl (caller clean-up), this next move will get things |
| 62 ; back on track. |
| 63 mov esp, ebp |
| 64 pop ebp |
| 65 |
| 66 ret |
| 67 |
| 68 SAFETERMINATEPROCESS_SYMBOL endp |
| 69 |
| 70 _TEXT ends |
| 71 |
| 72 endif |
| 73 |
| 74 end |
OLD | NEW |