| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 // Copyright 2015 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 #include "util/win/ntstatus_logging.h" | 
|  | 16 | 
|  | 17 #include <string> | 
|  | 18 | 
|  | 19 #include "base/strings/stringprintf.h" | 
|  | 20 | 
|  | 21 namespace { | 
|  | 22 | 
|  | 23 std::string FormatNtstatus(DWORD ntstatus) { | 
|  | 24   char msgbuf[256]; | 
|  | 25   DWORD len = FormatMessageA( | 
|  | 26       FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | | 
|  | 27           FORMAT_MESSAGE_MAX_WIDTH_MASK | FORMAT_MESSAGE_FROM_HMODULE, | 
|  | 28       GetModuleHandle(L"ntdll.dll"), | 
|  | 29       ntstatus, | 
|  | 30       0, | 
|  | 31       msgbuf, | 
|  | 32       arraysize(msgbuf), | 
|  | 33       nullptr); | 
|  | 34   if (len) { | 
|  | 35     return msgbuf; | 
|  | 36   } else { | 
|  | 37     return base::StringPrintf("<failed to retrieve error message (0x%x)>", | 
|  | 38                               GetLastError()); | 
|  | 39   } | 
|  | 40 } | 
|  | 41 | 
|  | 42 }  // namespace | 
|  | 43 | 
|  | 44 namespace logging { | 
|  | 45 | 
|  | 46 NtstatusLogMessage::NtstatusLogMessage(const char* function, | 
|  | 47                                        const char* file_path, | 
|  | 48                                        int line, | 
|  | 49                                        LogSeverity severity, | 
|  | 50                                        DWORD ntstatus) | 
|  | 51     : LogMessage( | 
|  | 52 #if defined(MINI_CHROMIUM_BASE_LOGGING_H_) | 
|  | 53         function, | 
|  | 54 #endif | 
|  | 55         file_path, line, severity), ntstatus_(ntstatus) { | 
|  | 56 } | 
|  | 57 | 
|  | 58 NtstatusLogMessage::~NtstatusLogMessage() { | 
|  | 59   stream() << ": " << FormatNtstatus(ntstatus_) | 
|  | 60            << base::StringPrintf(" (0x%08x)", ntstatus_); | 
|  | 61 } | 
|  | 62 | 
|  | 63 }  // namespace logging | 
| OLD | NEW | 
|---|