2014-10-17 13:47:02 -04:00
|
|
|
|
// Copyright 2014 The Crashpad Authors. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
|
//
|
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
//
|
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
#include "client/crashpad_info.h"
|
|
|
|
|
|
2014-12-16 10:22:41 -08:00
|
|
|
|
#include "build/build_config.h"
|
2014-10-17 14:24:12 -04:00
|
|
|
|
#include "util/stdlib/cxx.h"
|
|
|
|
|
|
2014-12-16 10:22:41 -08:00
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
|
#include <mach-o/loader.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
#if CXX_LIBRARY_VERSION >= 2011
|
|
|
|
|
#include <type_traits>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
static const uint32_t kCrashpadInfoVersion = 1;
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
namespace crashpad {
|
|
|
|
|
|
2014-10-29 11:33:34 -04:00
|
|
|
|
#if CXX_LIBRARY_VERSION >= 2011 || DOXYGEN
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// In C++11, check that CrashpadInfo has standard layout, which is what is
|
|
|
|
|
// actually important.
|
|
|
|
|
static_assert(std::is_standard_layout<CrashpadInfo>::value,
|
|
|
|
|
"CrashpadInfo must be standard layout");
|
|
|
|
|
#else
|
|
|
|
|
// In C++98 (ISO 14882), section 9.5.1 says that a union cannot have a member
|
|
|
|
|
// with a non-trivial ctor, copy ctor, dtor, or assignment operator. Use this
|
|
|
|
|
// property to ensure that CrashpadInfo remains POD. This doesn’t work for C++11
|
|
|
|
|
// because the requirements for unions have been relaxed.
|
|
|
|
|
union Compile_Assert {
|
|
|
|
|
CrashpadInfo Compile_Assert__CrashpadInfo_must_be_pod;
|
|
|
|
|
};
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-12-16 10:22:41 -08:00
|
|
|
|
// This structure needs to be stored somewhere that is easy to find without
|
|
|
|
|
// external information.
|
|
|
|
|
//
|
|
|
|
|
// It isn’t placed in an unnamed namespace: hopefully, this will catch attempts
|
|
|
|
|
// to place multiple copies of this structure into the same module. If that’s
|
|
|
|
|
// attempted, and the name of the symbol is the same in each translation unit,
|
|
|
|
|
// it will result in a linker error, which is better than having multiple
|
|
|
|
|
// structures show up.
|
2014-10-17 13:47:02 -04:00
|
|
|
|
//
|
|
|
|
|
// This may result in a static module initializer in debug-mode builds, but
|
|
|
|
|
// because it’s POD, no code should need to run to initialize this under
|
|
|
|
|
// release-mode optimization.
|
2014-12-16 10:22:41 -08:00
|
|
|
|
#if defined(OS_MACOSX)
|
|
|
|
|
|
|
|
|
|
// Put the structure in __DATA,__crashpad_info where it can be easily found
|
|
|
|
|
// without having to consult the symbol table. The “used” attribute prevents it
|
|
|
|
|
// from being dead-stripped.
|
2014-10-17 13:47:02 -04:00
|
|
|
|
__attribute__((section(SEG_DATA ",__crashpad_info"),
|
|
|
|
|
used,
|
|
|
|
|
visibility("hidden"))) CrashpadInfo g_crashpad_info;
|
|
|
|
|
|
2014-12-16 10:22:41 -08:00
|
|
|
|
#elif defined(OS_WIN)
|
|
|
|
|
|
2015-05-01 13:48:23 -07:00
|
|
|
|
// Put the struct in a section name CPADinfo where it can be found without the
|
|
|
|
|
// symbol table.
|
|
|
|
|
#pragma section("CPADinfo", read, write)
|
|
|
|
|
__declspec(allocate("CPADinfo")) CrashpadInfo g_crashpad_info;
|
2014-12-16 10:22:41 -08:00
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-10-17 13:47:02 -04:00
|
|
|
|
// static
|
|
|
|
|
CrashpadInfo* CrashpadInfo::GetCrashpadInfo() {
|
|
|
|
|
return &g_crashpad_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CrashpadInfo::CrashpadInfo()
|
|
|
|
|
: signature_(kSignature),
|
|
|
|
|
size_(sizeof(*this)),
|
|
|
|
|
version_(kCrashpadInfoVersion),
|
2015-03-11 17:07:11 -04:00
|
|
|
|
crashpad_handler_behavior_(TriState::kUnset),
|
|
|
|
|
system_crash_reporter_forwarding_(TriState::kUnset),
|
2014-10-17 13:47:02 -04:00
|
|
|
|
padding_0_(0),
|
|
|
|
|
simple_annotations_(nullptr) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace crashpad
|