Chromium Code Reviews| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "client/crashpad_info.h" | 15 #include "client/crashpad_info.h" |
| 16 | 16 |
| 17 #include "util/stdlib/cxx.h" | |
| 18 | |
| 19 #if defined(OS_MAC) | |
|
Mark Mentovai
2014/12/15 23:38:34
#include "build/build_config.h" to use this.
The
scottmg
2014/12/16 00:18:07
Done. I'm unclear on the guidance for this. It mus
Mark Mentovai
2014/12/16 14:14:14
scottmg wrote:
| |
| 17 #include <mach-o/loader.h> | 20 #include <mach-o/loader.h> |
| 18 | 21 #elif defined(OS_WIN) |
| 19 #include "util/stdlib/cxx.h" | 22 #include <windows.h> |
| 23 #endif | |
| 20 | 24 |
| 21 #if CXX_LIBRARY_VERSION >= 2011 | 25 #if CXX_LIBRARY_VERSION >= 2011 |
| 22 #include <type_traits> | 26 #include <type_traits> |
| 23 #endif | 27 #endif |
| 24 | 28 |
| 25 namespace { | 29 namespace { |
| 26 | 30 |
| 27 static const uint32_t kCrashpadInfoVersion = 1; | 31 static const uint32_t kCrashpadInfoVersion = 1; |
| 28 | 32 |
| 29 } // namespace | 33 } // namespace |
| 30 | 34 |
| 31 namespace crashpad { | 35 namespace crashpad { |
| 32 | 36 |
| 33 #if CXX_LIBRARY_VERSION >= 2011 || DOXYGEN | 37 #if CXX_LIBRARY_VERSION >= 2011 || DOXYGEN |
| 34 // In C++11, check that CrashpadInfo has standard layout, which is what is | 38 // In C++11, check that CrashpadInfo has standard layout, which is what is |
| 35 // actually important. | 39 // actually important. |
| 36 static_assert(std::is_standard_layout<CrashpadInfo>::value, | 40 static_assert(std::is_standard_layout<CrashpadInfo>::value, |
| 37 "CrashpadInfo must be standard layout"); | 41 "CrashpadInfo must be standard layout"); |
| 38 #else | 42 #else |
| 39 // In C++98 (ISO 14882), section 9.5.1 says that a union cannot have a member | 43 // In C++98 (ISO 14882), section 9.5.1 says that a union cannot have a member |
| 40 // with a non-trivial ctor, copy ctor, dtor, or assignment operator. Use this | 44 // with a non-trivial ctor, copy ctor, dtor, or assignment operator. Use this |
| 41 // property to ensure that CrashpadInfo remains POD. This doesn’t work for C++11 | 45 // property to ensure that CrashpadInfo remains POD. This doesn’t work for C++11 |
| 42 // because the requirements for unions have been relaxed. | 46 // because the requirements for unions have been relaxed. |
| 43 union Compile_Assert { | 47 union Compile_Assert { |
| 44 CrashpadInfo Compile_Assert__CrashpadInfo_must_be_pod; | 48 CrashpadInfo Compile_Assert__CrashpadInfo_must_be_pod; |
| 45 }; | 49 }; |
| 46 #endif | 50 #endif |
| 47 | 51 |
| 52 #if defined(OS_MAC) | |
| 53 | |
| 48 // Put the structure in __DATA,__crashpad_info where it can be easily found | 54 // Put the structure in __DATA,__crashpad_info where it can be easily found |
|
Mark Mentovai
2014/12/15 23:38:34
Aside from the actual section name, this comment’s
scottmg
2014/12/16 00:18:07
Improved.
I removed the Windows pragmas for now a
| |
| 49 // without having to consult the symbol table. The “used” attribute prevents it | 55 // without having to consult the symbol table. The “used” attribute prevents it |
| 50 // from being dead-stripped. This isn’t placed in an unnamed namespace: | 56 // from being dead-stripped. This isn’t placed in an unnamed namespace: |
| 51 // hopefully, this will catch attempts to place multiple copies of this | 57 // hopefully, this will catch attempts to place multiple copies of this |
| 52 // structure into the same module. If that’s attempted, and the name of the | 58 // structure into the same module. If that’s attempted, and the name of the |
| 53 // symbol is the same in each translation unit, it will result in a linker | 59 // symbol is the same in each translation unit, it will result in a linker |
| 54 // error, which is better than having multiple structures show up. | 60 // error, which is better than having multiple structures show up. |
| 55 // | 61 // |
| 56 // This may result in a static module initializer in debug-mode builds, but | 62 // This may result in a static module initializer in debug-mode builds, but |
| 57 // because it’s POD, no code should need to run to initialize this under | 63 // because it’s POD, no code should need to run to initialize this under |
| 58 // release-mode optimization. | 64 // release-mode optimization. |
| 59 __attribute__((section(SEG_DATA ",__crashpad_info"), | 65 __attribute__((section(SEG_DATA ",__crashpad_info"), |
| 60 used, | 66 used, |
| 61 visibility("hidden"))) CrashpadInfo g_crashpad_info; | 67 visibility("hidden"))) CrashpadInfo g_crashpad_info; |
| 62 | 68 |
| 69 #elif defined(OS_WIN) | |
| 70 | |
| 71 #pragma data_seg(push, crashpad_info, "__crashpad_info") | |
| 72 CrashpadInfo g_crashpad_info; | |
| 73 #pragma data_seg(pop, crashpad_info) | |
| 74 | |
| 75 #endif | |
| 76 | |
| 63 // static | 77 // static |
| 64 CrashpadInfo* CrashpadInfo::GetCrashpadInfo() { | 78 CrashpadInfo* CrashpadInfo::GetCrashpadInfo() { |
| 65 return &g_crashpad_info; | 79 return &g_crashpad_info; |
| 66 } | 80 } |
| 67 | 81 |
| 68 CrashpadInfo::CrashpadInfo() | 82 CrashpadInfo::CrashpadInfo() |
| 69 : signature_(kSignature), | 83 : signature_(kSignature), |
| 70 size_(sizeof(*this)), | 84 size_(sizeof(*this)), |
| 71 version_(kCrashpadInfoVersion), | 85 version_(kCrashpadInfoVersion), |
| 72 padding_0_(0), | 86 padding_0_(0), |
| 73 simple_annotations_(nullptr) { | 87 simple_annotations_(nullptr) { |
| 74 } | 88 } |
| 75 | 89 |
| 76 const uint32_t CrashpadInfo::kSignature; | 90 const uint32_t CrashpadInfo::kSignature; |
| 77 | 91 |
| 78 } // namespace crashpad | 92 } // namespace crashpad |
| OLD | NEW |