OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 // | 52 // |
53 // It isn’t placed in an unnamed namespace: hopefully, this will catch attempts | 53 // It isn’t placed in an unnamed namespace: hopefully, this will catch attempts |
54 // to place multiple copies of this structure into the same module. If that’s | 54 // to place multiple copies of this structure into the same module. If that’s |
55 // attempted, and the name of the symbol is the same in each translation unit, | 55 // attempted, and the name of the symbol is the same in each translation unit, |
56 // it will result in a linker error, which is better than having multiple | 56 // it will result in a linker error, which is better than having multiple |
57 // structures show up. | 57 // structures show up. |
58 // | 58 // |
59 // This may result in a static module initializer in debug-mode builds, but | 59 // This may result in a static module initializer in debug-mode builds, but |
60 // because it’s POD, no code should need to run to initialize this under | 60 // because it’s POD, no code should need to run to initialize this under |
61 // release-mode optimization. | 61 // release-mode optimization. |
| 62 #if defined(OS_POSIX) |
| 63 __attribute__(( |
| 64 |
| 65 // Put the structure in a well-known section name where it can be easily |
| 66 // found without having to consult the symbol table. |
62 #if defined(OS_MACOSX) | 67 #if defined(OS_MACOSX) |
| 68 section(SEG_DATA ",crashpad_info"), |
| 69 #elif defined(OS_LINUX) || defined(OS_ANDROID) |
| 70 section("crashpad_info"), |
| 71 #else // !defined(OS_MACOSX) && !defined(OS_LINUX) && !defined(OS_ANDROID) |
| 72 #error Port |
| 73 #endif // !defined(OS_MACOSX) && !defined(OS_LINUX) && !defined(OS_ANDROID) |
63 | 74 |
64 // Put the structure in __DATA,__crashpad_info where it can be easily found | |
65 // without having to consult the symbol table. The “used” attribute prevents it | |
66 // from being dead-stripped. | |
67 __attribute__((section(SEG_DATA ",__crashpad_info"), | |
68 used, | |
69 visibility("hidden") | |
70 #if __has_feature(address_sanitizer) | 75 #if __has_feature(address_sanitizer) |
71 // AddressSanitizer would add a trailing red zone of at least 32 bytes, which | 76 // AddressSanitizer would add a trailing red zone of at least 32 bytes, |
72 // would be reflected in the size of the custom section. This confuses | 77 // which would be reflected in the size of the custom section. This confuses |
73 // MachOImageReader::GetCrashpadInfo(), which finds that the section’s size | 78 // MachOImageReader::GetCrashpadInfo(), which finds that the section’s size |
74 // disagrees with the structure’s size_ field. By specifying an alignment | 79 // disagrees with the structure’s size_ field. By specifying an alignment |
75 // greater than the red zone size, the red zone will be suppressed. | 80 // greater than the red zone size, the red zone will be suppressed. |
76 , | 81 aligned(64), |
77 aligned(64) | 82 #endif // __has_feature(address_sanitizer) |
78 #endif | 83 |
79 )) CrashpadInfo g_crashpad_info; | 84 // The “used” attribute prevents the structure from being dead-stripped. |
| 85 used, |
| 86 |
| 87 // There’s no need to expose this as a public symbol from the symbol table. |
| 88 // All accesses from the outside can locate the well-known section name. |
| 89 visibility("hidden"))) |
80 | 90 |
81 #elif defined(OS_WIN) | 91 #elif defined(OS_WIN) |
82 | 92 |
83 // Put the struct in a section name CPADinfo where it can be found without the | 93 // Put the struct in a section name CPADinfo where it can be found without the |
84 // symbol table. | 94 // symbol table. |
85 #pragma section("CPADinfo", read, write) | 95 #pragma section("CPADinfo", read, write) |
86 __declspec(allocate("CPADinfo")) CrashpadInfo g_crashpad_info; | 96 __declspec(allocate("CPADinfo")) |
87 | 97 |
88 #endif | 98 #else // !defined(OS_POSIX) && !defined(OS_WIN) |
| 99 #error Port |
| 100 #endif // !defined(OS_POSIX) && !defined(OS_WIN) |
| 101 |
| 102 CrashpadInfo g_crashpad_info; |
89 | 103 |
90 // static | 104 // static |
91 CrashpadInfo* CrashpadInfo::GetCrashpadInfo() { | 105 CrashpadInfo* CrashpadInfo::GetCrashpadInfo() { |
92 return &g_crashpad_info; | 106 return &g_crashpad_info; |
93 } | 107 } |
94 | 108 |
95 CrashpadInfo::CrashpadInfo() | 109 CrashpadInfo::CrashpadInfo() |
96 : signature_(kSignature), | 110 : signature_(kSignature), |
97 size_(sizeof(*this)), | 111 size_(sizeof(*this)), |
98 version_(kCrashpadInfoVersion), | 112 version_(kCrashpadInfoVersion), |
(...skipping 20 matching lines...) Expand all Loading... |
119 to_be_added->next = base::checked_cast<uint64_t>( | 133 to_be_added->next = base::checked_cast<uint64_t>( |
120 reinterpret_cast<uintptr_t>(user_data_minidump_stream_head_)); | 134 reinterpret_cast<uintptr_t>(user_data_minidump_stream_head_)); |
121 to_be_added->stream_type = stream_type; | 135 to_be_added->stream_type = stream_type; |
122 to_be_added->base_address = | 136 to_be_added->base_address = |
123 base::checked_cast<uint64_t>(reinterpret_cast<uintptr_t>(data)); | 137 base::checked_cast<uint64_t>(reinterpret_cast<uintptr_t>(data)); |
124 to_be_added->size = base::checked_cast<uint64_t>(size); | 138 to_be_added->size = base::checked_cast<uint64_t>(size); |
125 user_data_minidump_stream_head_ = to_be_added; | 139 user_data_minidump_stream_head_ = to_be_added; |
126 } | 140 } |
127 | 141 |
128 } // namespace crashpad | 142 } // namespace crashpad |
OLD | NEW |