Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/process/memory.h" | 5 #include "base/process/memory.h" |
| 6 | 6 |
| 7 #include <new.h> | 7 #include <new.h> |
| 8 #include <psapi.h> | 8 #include <psapi.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 #pragma warning(push) | 31 #pragma warning(push) |
| 32 #pragma warning(disable: 4702) // Unreachable code after the _exit. | 32 #pragma warning(disable: 4702) // Unreachable code after the _exit. |
| 33 | 33 |
| 34 NOINLINE int OnNoMemory(size_t size) { | 34 NOINLINE int OnNoMemory(size_t size) { |
| 35 // Kill the process. This is important for security since most of code | 35 // Kill the process. This is important for security since most of code |
| 36 // does not check the result of memory allocation. | 36 // does not check the result of memory allocation. |
| 37 // https://msdn.microsoft.com/en-us/library/het71c37.aspx | 37 // https://msdn.microsoft.com/en-us/library/het71c37.aspx |
| 38 ::RaiseException(win::kOomExceptionCode, EXCEPTION_NONCONTINUABLE, 0, | 38 // Pass the size of the failed request |
|
scottmg
2017/02/06 18:17:41
'.' at end of sentence.
Sigurður Ásgeirsson
2017/02/06 19:43:58
Ooops, abortive comment - thanks. Done.
| |
| 39 nullptr); | 39 ULONG_PTR exception_args[] = {size}; |
| 40 ::RaiseException(win::kOomExceptionCode, EXCEPTION_NONCONTINUABLE, | |
| 41 arraysize(exception_args), exception_args); | |
| 42 | |
| 40 // Safety check, make sure process exits here. | 43 // Safety check, make sure process exits here. |
| 41 _exit(win::kOomExceptionCode); | 44 _exit(win::kOomExceptionCode); |
| 42 return 0; | 45 return 0; |
| 43 } | 46 } |
| 44 | 47 |
| 45 #pragma warning(pop) | 48 #pragma warning(pop) |
| 46 | 49 |
| 47 } // namespace | 50 } // namespace |
| 48 | 51 |
| 49 void TerminateBecauseOutOfMemory(size_t size) { | 52 void TerminateBecauseOutOfMemory(size_t size) { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 60 _set_new_mode(1); | 63 _set_new_mode(1); |
| 61 } | 64 } |
| 62 | 65 |
| 63 // Implemented using a weak symbol. | 66 // Implemented using a weak symbol. |
| 64 bool UncheckedMalloc(size_t size, void** result) { | 67 bool UncheckedMalloc(size_t size, void** result) { |
| 65 *result = malloc_unchecked(size); | 68 *result = malloc_unchecked(size); |
| 66 return *result != NULL; | 69 return *result != NULL; |
| 67 } | 70 } |
| 68 | 71 |
| 69 } // namespace base | 72 } // namespace base |
| OLD | NEW |