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 "client/crashpad_info.h" |
| 16 |
| 17 #include <mach-o/loader.h> |
| 18 |
| 19 #if CXX_LIBRARY_VERSION >= 2011 |
| 20 #include <type_traits> |
| 21 #endif |
| 22 |
| 23 namespace { |
| 24 |
| 25 static const uint32_t kCrashpadInfoSignature = 'cpad'; |
| 26 static const uint32_t kCrashpadInfoVersion = 1; |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace crashpad { |
| 31 |
| 32 #if CXX_LIBRARY_VERSION >= 2011 |
| 33 // In C++11, check that CrashpadInfo has standard layout, which is what is |
| 34 // actually important. |
| 35 static_assert(std::is_standard_layout<CrashpadInfo>::value, |
| 36 "CrashpadInfo must be standard layout"); |
| 37 #else |
| 38 // In C++98 (ISO 14882), section 9.5.1 says that a union cannot have a member |
| 39 // with a non-trivial ctor, copy ctor, dtor, or assignment operator. Use this |
| 40 // property to ensure that CrashpadInfo remains POD. This doesn’t work for C++11 |
| 41 // because the requirements for unions have been relaxed. |
| 42 union Compile_Assert { |
| 43 CrashpadInfo Compile_Assert__CrashpadInfo_must_be_pod; |
| 44 }; |
| 45 #endif |
| 46 |
| 47 // Put the structure in __DATA,__crashpad_info where it can be easily found |
| 48 // without having to consult the symbol table. The “used” attribute prevents it |
| 49 // from being dead-stripped. This isn’t placed in an unnamed namespace: |
| 50 // hopefully, this will catch attempts to place multiple copies of this |
| 51 // structure into the same module. If that’s attempted, and the name of the |
| 52 // symbol is the same in each translation unit, it will result in a linker |
| 53 // error, which is better than having multiple structures show up. |
| 54 // |
| 55 // This may result in a static module initializer in debug-mode builds, but |
| 56 // because it’s POD, no code should need to run to initialize this under |
| 57 // release-mode optimization. |
| 58 __attribute__((section(SEG_DATA ",__crashpad_info"), |
| 59 used, |
| 60 visibility("hidden"))) CrashpadInfo g_crashpad_info; |
| 61 |
| 62 // static |
| 63 CrashpadInfo* CrashpadInfo::GetCrashpadInfo() { |
| 64 return &g_crashpad_info; |
| 65 } |
| 66 |
| 67 CrashpadInfo::CrashpadInfo() |
| 68 : signature_(kCrashpadInfoSignature), |
| 69 size_(sizeof(*this)), |
| 70 version_(kCrashpadInfoVersion), |
| 71 padding_0_(0), |
| 72 simple_annotations_(nullptr) { |
| 73 } |
| 74 |
| 75 } // namespace crashpad |
OLD | NEW |