win: fixes for Windows x64

Mostly size_t <-> unsigned int warnings, but I also had a mistake in
PROCESS_BASIC_INFORMATION, the pids are 32-on-32 and 64-on-64.

The Windows build is still x86 until https://codereview.chromium.org/981333002/.
I don't think I'll bother maintaining the x86 build for now, though we will probably
need it for x86 OSs in the future. It should be straightforward to revive it once we
need it, and have bots to support it.

R=mark@chromium.org
BUG=crashpad:1

Review URL: https://codereview.chromium.org/983103004
This commit is contained in:
Scott Graham 2015-03-06 16:05:34 -08:00
parent 64b87325b9
commit 07fcf63c21
24 changed files with 75 additions and 54 deletions

View File

@ -390,7 +390,7 @@ void Metadata::Read() {
base::CheckedNumeric<uint32_t> records_size =
base::CheckedNumeric<uint32_t>(header.num_records) *
sizeof(MetadataFileReportRecord);
static_cast<uint32_t>(sizeof(MetadataFileReportRecord));
if (!records_size.IsValid()) {
LOG(ERROR) << "record size out of range";
return;

View File

@ -18,12 +18,15 @@
// This is intended to be roughly equivalent to #include_next.
#include <../include/sys/types.h>
#include <stdint.h>
#ifdef _WIN64
typedef __int64 ssize_t;
typedef int64_t ssize_t;
typedef uint64_t pid_t;
#else
typedef __w64 int ssize_t;
typedef __w64 unsigned int pid_t;
#endif
typedef unsigned long pid_t;
#endif // CRASHPAD_COMPAT_WIN_SYS_TYPES_H_

View File

@ -17,6 +17,7 @@
#include <sys/types.h>
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "minidump/minidump_context_writer.h"
#include "snapshot/exception_snapshot.h"
#include "util/file/file_writer.h"
@ -66,7 +67,8 @@ void MinidumpExceptionWriter::SetExceptionInformation(
arraysize(exception_.ExceptionRecord.ExceptionInformation);
CHECK_LE(parameters, kMaxParameters);
exception_.ExceptionRecord.NumberParameters = parameters;
exception_.ExceptionRecord.NumberParameters =
base::checked_cast<uint32_t>(parameters);
size_t parameter = 0;
for (; parameter < parameters; ++parameter) {
exception_.ExceptionRecord.ExceptionInformation[parameter] =

View File

@ -181,7 +181,7 @@ TEST(MinidumpExceptionWriter, Standard) {
expected_exception_stream.ExceptionRecord.ExceptionAddress =
kExceptionAddress;
expected_exception_stream.ExceptionRecord.NumberParameters =
exception_information.size();
static_cast<uint32_t>(exception_information.size());
for (size_t index = 0; index < exception_information.size(); ++index) {
expected_exception_stream.ExceptionRecord.ExceptionInformation[index] =
exception_information[index];
@ -209,7 +209,8 @@ TEST(MinidumpExceptionWriter, InitializeFromSnapshot) {
expect_exception.ExceptionRecord.ExceptionCode = 100;
expect_exception.ExceptionRecord.ExceptionFlags = 1;
expect_exception.ExceptionRecord.ExceptionAddress = 0xfedcba9876543210;
expect_exception.ExceptionRecord.NumberParameters = exception_codes.size();
expect_exception.ExceptionRecord.NumberParameters =
static_cast<uint32_t>(exception_codes.size());
for (size_t index = 0; index < exception_codes.size(); ++index) {
expect_exception.ExceptionRecord.ExceptionInformation[index] =
exception_codes[index];

View File

@ -194,7 +194,7 @@ std::vector<internal::MinidumpWritable*> MinidumpFileWriter::Children() {
return children;
}
bool MinidumpFileWriter::WillWriteAtOffsetImpl(off_t offset) {
bool MinidumpFileWriter::WillWriteAtOffsetImpl(FileOffset offset) {
DCHECK_EQ(state(), kStateFrozen);
DCHECK_EQ(offset, 0);
DCHECK_EQ(streams_.size(), stream_types_.size());

View File

@ -27,6 +27,7 @@
#include "minidump/minidump_extensions.h"
#include "minidump/minidump_stream_writer.h"
#include "minidump/minidump_writable.h"
#include "util/file/file_io.h"
#include "util/stdlib/pointer_container.h"
namespace crashpad {
@ -105,7 +106,7 @@ class MinidumpFileWriter final : public internal::MinidumpWritable {
bool Freeze() override;
size_t SizeOfObject() override;
std::vector<MinidumpWritable*> Children() override;
bool WillWriteAtOffsetImpl(off_t offset) override;
bool WillWriteAtOffsetImpl(FileOffset offset) override;
bool WriteObject(FileWriterInterface* file_writer) override;
private:

View File

@ -129,7 +129,7 @@ size_t MinidumpMemoryWriter::SizeOfObject() {
return MemoryRangeSize();
}
bool MinidumpMemoryWriter::WillWriteAtOffsetImpl(off_t offset) {
bool MinidumpMemoryWriter::WillWriteAtOffsetImpl(FileOffset offset) {
DCHECK_EQ(state(), kStateFrozen);
// There will always be at least one registered descriptor, the one for this

View File

@ -26,6 +26,7 @@
#include "base/memory/scoped_ptr.h"
#include "minidump/minidump_stream_writer.h"
#include "minidump/minidump_writable.h"
#include "util/file/file_io.h"
#include "util/stdlib/pointer_container.h"
namespace crashpad {
@ -105,7 +106,7 @@ class MinidumpMemoryWriter : public internal::MinidumpWritable {
//! \note Valid in #kStateFrozen or any subsequent state.
size_t Alignment() override;
bool WillWriteAtOffsetImpl(off_t offset) override;
bool WillWriteAtOffsetImpl(FileOffset offset) override;
//! \brief Returns the objects desired write phase.
//!

View File

@ -34,8 +34,9 @@ const MinidumpModuleCrashpadInfoList* MinidumpModuleCrashpadInfoListAtStart(
const std::string& file_contents,
size_t count) {
MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
location_descriptor.DataSize = sizeof(MinidumpModuleCrashpadInfoList) +
count * sizeof(MinidumpModuleCrashpadInfoLink);
location_descriptor.DataSize =
static_cast<uint32_t>(sizeof(MinidumpModuleCrashpadInfoList) +
count * sizeof(MinidumpModuleCrashpadInfoLink));
location_descriptor.Rva = 0;
const MinidumpModuleCrashpadInfoList* list =

View File

@ -19,6 +19,7 @@
#include <limits>
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "minidump/minidump_string_writer.h"
#include "minidump/minidump_writer_util.h"
#include "snapshot/module_snapshot.h"
@ -154,13 +155,14 @@ bool MinidumpModuleMiscDebugRecordWriter::Freeze() {
// NUL-terminate.
if (!image_debug_misc_.Unicode) {
DCHECK(data_utf16_.empty());
image_debug_misc_.Length = offsetof(decltype(image_debug_misc_), Data) +
(data_.size() + 1) * sizeof(data_[0]);
image_debug_misc_.Length = base::checked_cast<uint32_t>(
offsetof(decltype(image_debug_misc_), Data) +
(data_.size() + 1) * sizeof(data_[0]));
} else {
DCHECK(data_.empty());
image_debug_misc_.Length =
image_debug_misc_.Length = base::checked_cast<uint32_t>(
offsetof(decltype(image_debug_misc_), Data) +
(data_utf16_.size() + 1) * sizeof(data_utf16_[0]);
(data_utf16_.size() + 1) * sizeof(data_utf16_[0]));
}
return true;

View File

@ -31,9 +31,9 @@ const MinidumpSimpleStringDictionary* MinidumpSimpleStringDictionaryAtStart(
const std::string& file_contents,
size_t count) {
MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
location_descriptor.DataSize =
location_descriptor.DataSize = static_cast<uint32_t>(
sizeof(MinidumpSimpleStringDictionary) +
count * sizeof(MinidumpSimpleStringDictionaryEntry);
count * sizeof(MinidumpSimpleStringDictionaryEntry));
location_descriptor.Rva = 0;
return MinidumpWritableAtLocationDescriptor<MinidumpSimpleStringDictionary>(
file_contents, location_descriptor);

View File

@ -19,6 +19,7 @@
#include <utility>
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "snapshot/thread_snapshot.h"
namespace crashpad {
@ -54,7 +55,8 @@ void BuildMinidumpThreadIDMap(
for (const ThreadSnapshot* thread_snapshot : thread_snapshots) {
uint64_t thread_id_64 = thread_snapshot->ThreadID();
if (thread_id_map->find(thread_id_64) == thread_id_map->end()) {
uint32_t thread_id_32 = thread_id_map->size();
uint32_t thread_id_32 =
base::checked_cast<uint32_t>(thread_id_map->size());
thread_id_map->insert(std::make_pair(thread_id_64, thread_id_32));
}
}

View File

@ -43,7 +43,7 @@ bool MinidumpWritable::WriteEverything(FileWriterInterface* file_writer) {
DCHECK_EQ(state_, kStateFrozen);
off_t offset = 0;
FileOffset offset = 0;
std::vector<MinidumpWritable*> write_sequence;
size_t size = WillWriteAtOffset(kPhaseEarly, &offset, &write_sequence);
if (size == kInvalidSize) {
@ -124,9 +124,9 @@ MinidumpWritable::Phase MinidumpWritable::WritePhase() {
size_t MinidumpWritable::WillWriteAtOffset(
Phase phase,
off_t* offset,
FileOffset* offset,
std::vector<MinidumpWritable*>* write_sequence) {
off_t local_offset = *offset;
FileOffset local_offset = *offset;
CHECK_GE(local_offset, 0);
size_t leading_pad_bytes_this_phase;
@ -218,10 +218,10 @@ size_t MinidumpWritable::WillWriteAtOffset(
std::vector<MinidumpWritable*> children = Children();
for (MinidumpWritable* child : children) {
// Use “auto” here because its impossible to know whether size_t (size) or
// off_t (local_offset) is the wider type, and thus what type the result of
// adding these two variables will have.
// FileOffset (local_offset) is the wider type, and thus what type the
// result of adding these two variables will have.
auto unaligned_child_offset = local_offset + size;
off_t child_offset;
FileOffset child_offset;
if (!AssignIfInRange(&child_offset, unaligned_child_offset)) {
LOG(ERROR) << "offset " << unaligned_child_offset << " out of range";
return kInvalidSize;
@ -239,7 +239,7 @@ size_t MinidumpWritable::WillWriteAtOffset(
return leading_pad_bytes_this_phase + size;
}
bool MinidumpWritable::WillWriteAtOffsetImpl(off_t offset) {
bool MinidumpWritable::WillWriteAtOffsetImpl(FileOffset offset) {
return true;
}

View File

@ -22,6 +22,7 @@
#include <vector>
#include "base/basictypes.h"
#include "util/file/file_io.h"
namespace crashpad {
@ -212,7 +213,7 @@ class MinidumpWritable {
//! processing when an object transitions to #kStateWritable should
//! implement WillWriteAtOffsetImpl(), which is called by this method.
size_t WillWriteAtOffset(Phase phase,
off_t* offset,
FileOffset* offset,
std::vector<MinidumpWritable*>* write_sequence);
//! \brief Called once an objects writable file offset is determined, as it
@ -232,7 +233,7 @@ class MinidumpWritable {
//!
//! \note Valid in #kStateFrozen. The object will transition to
//! #kStateWritable after this method returns.
virtual bool WillWriteAtOffsetImpl(off_t offset);
virtual bool WillWriteAtOffsetImpl(FileOffset offset);
//! \brief Writes the object, transitioning it from #kStateWritable to
//! #kStateWritten.

View File

@ -89,7 +89,7 @@ class BaseTestMinidumpWritable : public crashpad::internal::MinidumpWritable {
return has_phase_ ? phase_ : MinidumpWritable::Phase();
}
bool WillWriteAtOffsetImpl(off_t offset) override {
bool WillWriteAtOffsetImpl(FileOffset offset) override {
EXPECT_EQ(state(), kStateFrozen);
expected_offset_ = offset;
bool rv = MinidumpWritable::WillWriteAtOffsetImpl(offset);
@ -107,7 +107,7 @@ class BaseTestMinidumpWritable : public crashpad::internal::MinidumpWritable {
private:
std::vector<BaseTestMinidumpWritable*> children_;
off_t expected_offset_;
FileOffset expected_offset_;
size_t alignment_;
Phase phase_;
bool has_alignment_;

View File

@ -42,7 +42,7 @@ size_t TestMinidumpMemoryWriter::MemoryRangeSize() const {
return size_;
}
bool TestMinidumpMemoryWriter::WillWriteAtOffsetImpl(off_t offset) {
bool TestMinidumpMemoryWriter::WillWriteAtOffsetImpl(FileOffset offset) {
EXPECT_EQ(state(), kStateFrozen);
expected_offset_ = offset;
bool rv = MinidumpMemoryWriter::WillWriteAtOffsetImpl(offset);

View File

@ -44,12 +44,12 @@ class TestMinidumpMemoryWriter final : public MinidumpMemoryWriter {
size_t MemoryRangeSize() const override;
// MinidumpWritable:
bool WillWriteAtOffsetImpl(off_t offset) override;
bool WillWriteAtOffsetImpl(FileOffset offset) override;
bool WriteObject(FileWriterInterface* file_writer) override;
private:
uint64_t base_address_;
off_t expected_offset_;
FileOffset expected_offset_;
size_t size_;
uint8_t value_;

View File

@ -26,7 +26,8 @@ namespace test {
const MinidumpRVAList* MinidumpRVAListAtStart(const std::string& file_contents,
size_t count) {
MINIDUMP_LOCATION_DESCRIPTOR location_descriptor;
location_descriptor.DataSize = sizeof(MinidumpRVAList) + count * sizeof(RVA);
location_descriptor.DataSize =
static_cast<uint32_t>(sizeof(MinidumpRVAList) + count * sizeof(RVA));
location_descriptor.Rva = 0;
const MinidumpRVAList* list =

View File

@ -63,7 +63,7 @@ TEST(ProcessSnapshotMinidump, Empty) {
RVA WriteString(FileWriterInterface* writer, const std::string& string) {
RVA rva = static_cast<RVA>(writer->SeekGet());
uint32_t string_size = string.size();
uint32_t string_size = static_cast<uint32_t>(string.size());
EXPECT_TRUE(writer->Write(&string_size, sizeof(string_size)));
// Include the trailing NUL character.
@ -88,16 +88,17 @@ void WriteMinidumpSimpleStringDictionary(
location->Rva = static_cast<RVA>(writer->SeekGet());
const uint32_t simple_string_dictionary_entries = entries.size();
const uint32_t simple_string_dictionary_entries =
static_cast<uint32_t>(entries.size());
EXPECT_TRUE(writer->Write(&simple_string_dictionary_entries,
sizeof(simple_string_dictionary_entries)));
for (const MinidumpSimpleStringDictionaryEntry& entry : entries) {
EXPECT_TRUE(writer->Write(&entry, sizeof(entry)));
}
location->DataSize =
location->DataSize = static_cast<uint32_t>(
sizeof(simple_string_dictionary_entries) +
entries.size() * sizeof(MinidumpSimpleStringDictionaryEntry);
entries.size() * sizeof(MinidumpSimpleStringDictionaryEntry));
}
// Writes |strings| to |writer| as a MinidumpRVAList referencing
@ -113,13 +114,14 @@ void WriteMinidumpStringList(MINIDUMP_LOCATION_DESCRIPTOR* location,
location->Rva = static_cast<RVA>(writer->SeekGet());
const uint32_t string_list_entries = rvas.size();
const uint32_t string_list_entries = static_cast<uint32_t>(rvas.size());
EXPECT_TRUE(writer->Write(&string_list_entries, sizeof(string_list_entries)));
for (RVA rva : rvas) {
EXPECT_TRUE(writer->Write(&rva, sizeof(rva)));
}
location->DataSize = sizeof(string_list_entries) + rvas.size() * sizeof(RVA);
location->DataSize = static_cast<uint32_t>(sizeof(string_list_entries) +
rvas.size() * sizeof(RVA));
}
TEST(ProcessSnapshotMinidump, AnnotationsSimpleMap) {

View File

@ -16,9 +16,7 @@
namespace crashpad {
ProcessReaderWin::ProcessReaderWin()
: initialized_(),
is_64_bit_(false) {
ProcessReaderWin::ProcessReaderWin() : process_info_(), initialized_() {
}
ProcessReaderWin::~ProcessReaderWin() {
@ -27,6 +25,8 @@ ProcessReaderWin::~ProcessReaderWin() {
bool ProcessReaderWin::Initialize(HANDLE process) {
INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
process_info_.Initialize(process);
INITIALIZATION_STATE_SET_VALID(initialized_);
return true;
}

View File

@ -18,6 +18,7 @@
#include <windows.h>
#include "util/misc/initialization_state_dcheck.h"
#include "util/win/process_info.h"
namespace crashpad {
@ -39,10 +40,10 @@ class ProcessReaderWin {
bool Initialize(HANDLE process);
//! \return `true` if the target task is a 64-bit process.
bool Is64Bit() const { return is_64_bit_; }
bool Is64Bit() const { return process_info_.Is64Bit(); }
private:
bool is_64_bit_;
ProcessInfo process_info_;
InitializationStateDcheck initialized_;
DISALLOW_COPY_AND_ASSIGN(ProcessReaderWin);

View File

@ -46,7 +46,8 @@ std::string GenerateBoundaryString() {
for (int index = 0; index < 32; ++index) {
const char kCharacters[] =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
int random_value = base::RandInt(0, strlen(kCharacters) - 1);
int random_value =
base::RandInt(0, static_cast<int>(strlen(kCharacters)) - 1);
boundary_string += kCharacters[random_value];
}
boundary_string += "---";

View File

@ -18,6 +18,7 @@
#include <winhttp.h>
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/scoped_generic.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
@ -149,9 +150,10 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
for (const auto& pair : headers()) {
std::wstring header_string =
base::UTF8ToUTF16(pair.first) + L": " + base::UTF8ToUTF16(pair.second);
if (!WinHttpAddRequestHeaders(request.get(),
if (!WinHttpAddRequestHeaders(
request.get(),
header_string.c_str(),
header_string.size(),
base::checked_cast<DWORD>(header_string.size()),
WINHTTP_ADDREQ_FLAG_ADD)) {
LogErrorWinHttpMessage("WinHttpAddRequestHeaders");
return false;
@ -178,8 +180,8 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
&post_data[0],
post_data.size(),
post_data.size(),
base::checked_cast<DWORD>(post_data.size()),
base::checked_cast<DWORD>(post_data.size()),
0)) {
LogErrorWinHttpMessage("WinHttpSendRequest");
return false;

View File

@ -37,8 +37,8 @@ struct FULL_PROCESS_BASIC_INFORMATION {
PPEB PebBaseAddress;
KAFFINITY AffinityMask;
PVOID BasePriority;
ULONG UniqueProcessId;
ULONG InheritedFromUniqueProcessId;
ULONG_PTR UniqueProcessId;
ULONG_PTR InheritedFromUniqueProcessId;
};
} // namespace internal