Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(37)

Unified Diff: snapshot/mac/process_types.cc

Issue 1274663005: Provide a properly-typed ExpectedSizeForVersion() for types that need it (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snapshot/mac/process_types.h ('k') | snapshot/mac/process_types/crashreporterclient.proctype » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/mac/process_types.cc
diff --git a/snapshot/mac/process_types.cc b/snapshot/mac/process_types.cc
index 196a01ddf4ce059623407e8cf92ffe9da5bfcfbe..0fc14f0e0b5e971b643bd98917a88688ae0bb028 100644
--- a/snapshot/mac/process_types.cc
+++ b/snapshot/mac/process_types.cc
@@ -17,7 +17,6 @@
#include <string.h>
#include <uuid/uuid.h>
-#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "snapshot/mac/process_types/internal.h"
#include "util/mach/task_memory.h"
@@ -83,68 +82,58 @@ inline void Assign<uuid_t, uuid_t>(uuid_t* destination, const uuid_t& source) {
// operates on each member in the struct.
#define PROCESS_TYPE_STRUCT_IMPLEMENT 1
-#define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \
- namespace crashpad { \
- namespace process_types { \
- \
- /* static */ \
- size_t struct_name::ExpectedSize(ProcessReader* process_reader) { \
- if (!process_reader->Is64Bit()) { \
- return internal::struct_name<internal::Traits32>::Size(); \
- } else { \
- return internal::struct_name<internal::Traits64>::Size(); \
- } \
- } \
- \
- /* static */ \
- size_t struct_name::ExpectedSizeForVersion(ProcessReader* process_reader, \
- uint64_t version) { \
- if (!process_reader->Is64Bit()) { \
- return internal::struct_name< \
- internal::Traits32>::ExpectedSizeForVersion(version); \
- } else { \
- return internal::struct_name< \
- internal::Traits64>::ExpectedSizeForVersion(version); \
- } \
- } \
- \
- /* static */ \
- bool struct_name::ReadInto(ProcessReader* process_reader, \
- mach_vm_address_t address, \
- struct_name* generic) { \
- if (!process_reader->Is64Bit()) { \
- return ReadIntoInternal<internal::struct_name<internal::Traits32> >( \
- process_reader, address, generic); \
- } else { \
- return ReadIntoInternal<internal::struct_name<internal::Traits64> >( \
- process_reader, address, generic); \
- } \
- } \
- \
- /* static */ \
- template <typename T> \
- bool struct_name::ReadIntoInternal(ProcessReader* process_reader, \
- mach_vm_address_t address, \
- struct_name* generic) { \
- T specific; \
- if (!specific.Read(process_reader, address)) { \
- return false; \
- } \
- specific.GenericizeInto(generic, &generic->size_); \
- return true; \
- } \
- \
- namespace internal { \
- \
- template <typename Traits> \
- void struct_name<Traits>::GenericizeInto( \
- process_types::struct_name* generic, \
- size_t* specific_size) { \
+#define PROCESS_TYPE_STRUCT_BEGIN(struct_name) \
+ namespace crashpad { \
+ namespace process_types { \
+ \
+ /* static */ \
+ size_t struct_name::ExpectedSize(ProcessReader* process_reader) { \
+ if (!process_reader->Is64Bit()) { \
+ return internal::struct_name<internal::Traits32>::Size(); \
+ } else { \
+ return internal::struct_name<internal::Traits64>::Size(); \
+ } \
+ } \
+ \
+ /* static */ \
+ bool struct_name::ReadInto(ProcessReader* process_reader, \
+ mach_vm_address_t address, \
+ struct_name* generic) { \
+ if (!process_reader->Is64Bit()) { \
+ return ReadIntoInternal<internal::struct_name<internal::Traits32> >( \
+ process_reader, address, generic); \
+ } else { \
+ return ReadIntoInternal<internal::struct_name<internal::Traits64> >( \
+ process_reader, address, generic); \
+ } \
+ } \
+ \
+ /* static */ \
+ template <typename T> \
+ bool struct_name::ReadIntoInternal(ProcessReader* process_reader, \
+ mach_vm_address_t address, \
+ struct_name* generic) { \
+ T specific; \
+ if (!specific.Read(process_reader, address)) { \
+ return false; \
+ } \
+ specific.GenericizeInto(generic, &generic->size_); \
+ return true; \
+ } \
+ \
+ namespace internal { \
+ \
+ template <typename Traits> \
+ void struct_name<Traits>::GenericizeInto( \
+ process_types::struct_name* generic, \
+ size_t* specific_size) { \
*specific_size = Size();
#define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...) \
Assign(&generic->member_name, member_name);
+#define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field)
+
#define PROCESS_TYPE_STRUCT_END(struct_name) \
} \
} /* namespace internal */ \
@@ -155,6 +144,7 @@ inline void Assign<uuid_t, uuid_t>(uuid_t* destination, const uuid_t& source) {
#undef PROCESS_TYPE_STRUCT_BEGIN
#undef PROCESS_TYPE_STRUCT_MEMBER
+#undef PROCESS_TYPE_STRUCT_VERSIONED
#undef PROCESS_TYPE_STRUCT_END
#undef PROCESS_TYPE_STRUCT_IMPLEMENT
@@ -185,12 +175,15 @@ inline void Assign<uuid_t, uuid_t>(uuid_t* destination, const uuid_t& source) {
#define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...)
+#define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field)
+
#define PROCESS_TYPE_STRUCT_END(struct_name)
#include "snapshot/mac/process_types/all.proctype"
#undef PROCESS_TYPE_STRUCT_BEGIN
#undef PROCESS_TYPE_STRUCT_MEMBER
+#undef PROCESS_TYPE_STRUCT_VERSIONED
#undef PROCESS_TYPE_STRUCT_END
#undef PROCESS_TYPE_STRUCT_IMPLEMENT_INTERNAL_READ_INTO
@@ -216,12 +209,6 @@ inline void Assign<uuid_t, uuid_t>(uuid_t* destination, const uuid_t& source) {
address, sizeof(struct_name<Traits>[count]), specific); \
} \
\
- /* static */ \
- template <typename Traits> \
- size_t struct_name<Traits>::ExpectedSizeForVersion(uint64_t version) { \
- NOTREACHED(); \
- return 0; \
- } \
} /* namespace internal */ \
\
/* static */ \
@@ -261,11 +248,57 @@ inline void Assign<uuid_t, uuid_t>(uuid_t* destination, const uuid_t& source) {
#define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...)
+#define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field)
+
#define PROCESS_TYPE_STRUCT_END(struct_name)
#include "snapshot/mac/process_types/all.proctype"
#undef PROCESS_TYPE_STRUCT_BEGIN
#undef PROCESS_TYPE_STRUCT_MEMBER
+#undef PROCESS_TYPE_STRUCT_VERSIONED
#undef PROCESS_TYPE_STRUCT_END
#undef PROCESS_TYPE_STRUCT_IMPLEMENT_ARRAY
+
+// Implement the generic crashpad::process_types::struct_name
+// ExpectedSizeForVersion(), which delegates to the templatized
+// ExpectedSizeForVersion(), which returns the expected size of a versioned
+// structure given a version parameter. This is only implemented for structures
+// that use PROCESS_TYPE_STRUCT_VERSIONED(), and implementations of the internal
+// templatized functions must be provided in
+// snapshot/mac/process_types/custom.cc.
+#define PROCESS_TYPE_STRUCT_IMPLEMENT_VERSIONED 1
+
+#define PROCESS_TYPE_STRUCT_BEGIN(struct_name)
+
+#define PROCESS_TYPE_STRUCT_MEMBER(member_type, member_name, ...)
+
+#define PROCESS_TYPE_STRUCT_VERSIONED(struct_name, version_field) \
+ namespace crashpad { \
+ namespace process_types { \
+ \
+ /* static */ \
+ size_t struct_name::ExpectedSizeForVersion( \
+ ProcessReader* process_reader, \
+ decltype(struct_name::version_field) version) { \
+ if (!process_reader->Is64Bit()) { \
+ return internal::struct_name< \
+ internal::Traits32>::ExpectedSizeForVersion(version); \
+ } else { \
+ return internal::struct_name< \
+ internal::Traits64>::ExpectedSizeForVersion(version); \
+ } \
+ } \
+ \
+ } /* namespace process_types */ \
+ } /* namespace crashpad */
+
+#define PROCESS_TYPE_STRUCT_END(struct_name)
+
+#include "snapshot/mac/process_types/all.proctype"
+
+#undef PROCESS_TYPE_STRUCT_BEGIN
+#undef PROCESS_TYPE_STRUCT_MEMBER
+#undef PROCESS_TYPE_STRUCT_VERSIONED
+#undef PROCESS_TYPE_STRUCT_END
+#undef PROCESS_TYPE_STRUCT_IMPLEMENT_VERSIONED
« no previous file with comments | « snapshot/mac/process_types.h ('k') | snapshot/mac/process_types/crashreporterclient.proctype » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698