OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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 "minidump/minidump_misc_info_writer.h" |
| 16 |
| 17 #include "base/logging.h" |
| 18 #include "base/numerics/safe_conversions.h" |
| 19 #include "base/strings/utf_string_conversions.h" |
| 20 #include "minidump/minidump_writer_util.h" |
| 21 #include "util/numeric/safe_assignment.h" |
| 22 |
| 23 namespace crashpad { |
| 24 |
| 25 MinidumpMiscInfoWriter::MinidumpMiscInfoWriter() |
| 26 : MinidumpStreamWriter(), misc_info_() { |
| 27 } |
| 28 |
| 29 void MinidumpMiscInfoWriter::SetProcessId(uint32_t process_id) { |
| 30 DCHECK_EQ(state(), kStateMutable); |
| 31 |
| 32 misc_info_.ProcessId = process_id; |
| 33 misc_info_.Flags1 |= MINIDUMP_MISC1_PROCESS_ID; |
| 34 } |
| 35 |
| 36 void MinidumpMiscInfoWriter::SetProcessTimes(time_t process_create_time, |
| 37 uint32_t process_user_time, |
| 38 uint32_t process_kernel_time) { |
| 39 DCHECK_EQ(state(), kStateMutable); |
| 40 |
| 41 internal::MinidumpWriterUtil::AssignTimeT(&misc_info_.ProcessCreateTime, |
| 42 process_create_time); |
| 43 |
| 44 misc_info_.ProcessUserTime = process_user_time; |
| 45 misc_info_.ProcessKernelTime = process_kernel_time; |
| 46 misc_info_.Flags1 |= MINIDUMP_MISC1_PROCESS_TIMES; |
| 47 } |
| 48 |
| 49 void MinidumpMiscInfoWriter::SetProcessorPowerInfo( |
| 50 uint32_t processor_max_mhz, |
| 51 uint32_t processor_current_mhz, |
| 52 uint32_t processor_mhz_limit, |
| 53 uint32_t processor_max_idle_state, |
| 54 uint32_t processor_current_idle_state) { |
| 55 DCHECK_EQ(state(), kStateMutable); |
| 56 |
| 57 misc_info_.ProcessorMaxMhz = processor_max_mhz; |
| 58 misc_info_.ProcessorCurrentMhz = processor_current_mhz; |
| 59 misc_info_.ProcessorMhzLimit = processor_mhz_limit; |
| 60 misc_info_.ProcessorMaxIdleState = processor_max_idle_state; |
| 61 misc_info_.ProcessorCurrentIdleState = processor_current_idle_state; |
| 62 misc_info_.Flags1 |= MINIDUMP_MISC1_PROCESSOR_POWER_INFO; |
| 63 } |
| 64 |
| 65 void MinidumpMiscInfoWriter::SetProcessIntegrityLevel( |
| 66 uint32_t process_integrity_level) { |
| 67 DCHECK_EQ(state(), kStateMutable); |
| 68 |
| 69 misc_info_.ProcessIntegrityLevel = process_integrity_level; |
| 70 misc_info_.Flags1 |= MINIDUMP_MISC3_PROCESS_INTEGRITY; |
| 71 } |
| 72 |
| 73 void MinidumpMiscInfoWriter::SetProcessExecuteFlags( |
| 74 uint32_t process_execute_flags) { |
| 75 DCHECK_EQ(state(), kStateMutable); |
| 76 |
| 77 misc_info_.ProcessExecuteFlags = process_execute_flags; |
| 78 misc_info_.Flags1 |= MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS; |
| 79 } |
| 80 |
| 81 void MinidumpMiscInfoWriter::SetProtectedProcess(uint32_t protected_process) { |
| 82 DCHECK_EQ(state(), kStateMutable); |
| 83 |
| 84 misc_info_.ProtectedProcess = protected_process; |
| 85 misc_info_.Flags1 |= MINIDUMP_MISC3_PROTECTED_PROCESS; |
| 86 } |
| 87 |
| 88 void MinidumpMiscInfoWriter::SetTimeZone(uint32_t time_zone_id, |
| 89 int32_t bias, |
| 90 const std::string& standard_name, |
| 91 const SYSTEMTIME& standard_date, |
| 92 int32_t standard_bias, |
| 93 const std::string& daylight_name, |
| 94 const SYSTEMTIME& daylight_date, |
| 95 int32_t daylight_bias) { |
| 96 DCHECK_EQ(state(), kStateMutable); |
| 97 |
| 98 misc_info_.TimeZoneId = time_zone_id; |
| 99 misc_info_.TimeZone.Bias = bias; |
| 100 |
| 101 internal::MinidumpWriterUtil::AssignUTF8ToUTF16( |
| 102 misc_info_.TimeZone.StandardName, |
| 103 arraysize(misc_info_.TimeZone.StandardName), |
| 104 standard_name); |
| 105 |
| 106 misc_info_.TimeZone.StandardDate = standard_date; |
| 107 misc_info_.TimeZone.StandardBias = standard_bias; |
| 108 |
| 109 internal::MinidumpWriterUtil::AssignUTF8ToUTF16( |
| 110 misc_info_.TimeZone.DaylightName, |
| 111 arraysize(misc_info_.TimeZone.DaylightName), |
| 112 daylight_name); |
| 113 |
| 114 misc_info_.TimeZone.DaylightDate = daylight_date; |
| 115 misc_info_.TimeZone.DaylightBias = daylight_bias; |
| 116 |
| 117 misc_info_.Flags1 |= MINIDUMP_MISC3_TIMEZONE; |
| 118 } |
| 119 |
| 120 void MinidumpMiscInfoWriter::SetBuildString( |
| 121 const std::string& build_string, |
| 122 const std::string& debug_build_string) { |
| 123 DCHECK_EQ(state(), kStateMutable); |
| 124 |
| 125 misc_info_.Flags1 |= MINIDUMP_MISC4_BUILDSTRING; |
| 126 |
| 127 internal::MinidumpWriterUtil::AssignUTF8ToUTF16( |
| 128 misc_info_.BuildString, arraysize(misc_info_.BuildString), build_string); |
| 129 internal::MinidumpWriterUtil::AssignUTF8ToUTF16( |
| 130 misc_info_.DbgBldStr, |
| 131 arraysize(misc_info_.DbgBldStr), |
| 132 debug_build_string); |
| 133 } |
| 134 |
| 135 bool MinidumpMiscInfoWriter::Freeze() { |
| 136 DCHECK_EQ(state(), kStateMutable); |
| 137 |
| 138 if (!MinidumpStreamWriter::Freeze()) { |
| 139 return false; |
| 140 } |
| 141 |
| 142 size_t size = CalculateSizeOfObjectFromFlags(); |
| 143 if (!AssignIfInRange(&misc_info_.SizeOfInfo, size)) { |
| 144 LOG(ERROR) << "size " << size << " out of range"; |
| 145 return false; |
| 146 } |
| 147 |
| 148 return true; |
| 149 } |
| 150 |
| 151 size_t MinidumpMiscInfoWriter::SizeOfObject() { |
| 152 DCHECK_GE(state(), kStateFrozen); |
| 153 |
| 154 return CalculateSizeOfObjectFromFlags(); |
| 155 } |
| 156 |
| 157 bool MinidumpMiscInfoWriter::WriteObject(FileWriterInterface* file_writer) { |
| 158 DCHECK_EQ(state(), kStateWritable); |
| 159 |
| 160 return file_writer->Write(&misc_info_, CalculateSizeOfObjectFromFlags()); |
| 161 } |
| 162 |
| 163 MinidumpStreamType MinidumpMiscInfoWriter::StreamType() const { |
| 164 return kMinidumpStreamTypeMiscInfo; |
| 165 } |
| 166 |
| 167 size_t MinidumpMiscInfoWriter::CalculateSizeOfObjectFromFlags() const { |
| 168 DCHECK_GE(state(), kStateFrozen); |
| 169 |
| 170 if (misc_info_.Flags1 & MINIDUMP_MISC4_BUILDSTRING) { |
| 171 return sizeof(MINIDUMP_MISC_INFO_4); |
| 172 } |
| 173 if (misc_info_.Flags1 & |
| 174 (MINIDUMP_MISC3_PROCESS_INTEGRITY | MINIDUMP_MISC3_PROCESS_EXECUTE_FLAGS | |
| 175 MINIDUMP_MISC3_TIMEZONE | MINIDUMP_MISC3_PROTECTED_PROCESS)) { |
| 176 return sizeof(MINIDUMP_MISC_INFO_3); |
| 177 } |
| 178 if (misc_info_.Flags1 & MINIDUMP_MISC1_PROCESSOR_POWER_INFO) { |
| 179 return sizeof(MINIDUMP_MISC_INFO_2); |
| 180 } |
| 181 return sizeof(MINIDUMP_MISC_INFO); |
| 182 } |
| 183 |
| 184 } // namespace crashpad |
OLD | NEW |