Skip to content

Commit cf1d16e

Browse files
committed
Merge remote-tracking branch 'google/main' into kq-merge-march-2023
2 parents 310d064 + c21292d commit cf1d16e

File tree

91 files changed

+3688
-234
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3688
-234
lines changed

Diff for: .gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
/third_party/linux/clang
3737
/third_party/linux/sysroot
3838
/third_party/gyp/gyp
39+
/third_party/mini_chromium/mini_chromium
40+
/third_party/ninja/linux
41+
/third_party/ninja/mac*
42+
/third_party/ninja/ninja.exe
43+
/third_party/zlib/zlib
3944
/xcodebuild
4045
tag
4146
/cbuild

Diff for: BUILD.gn

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ if (crashpad_is_in_chromium || crashpad_is_in_fuchsia) {
3939
if (crashpad_is_in_fuchsia) {
4040
# TODO(fuchsia:46559): Fix the leaks and remove this.
4141
deps += [ "//build/config/sanitizers:suppress-lsan.DO-NOT-USE-THIS" ]
42+
# TODO(fxbug.dev/108368): Remove this once the underlying issue is addressed.
43+
exclude_toolchain_tags = [ "hwasan" ]
4244
}
4345
if (crashpad_is_android) {
4446
use_raw_android_executable = true

Diff for: DEPS

+49-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414

1515
vars = {
1616
'chromium_git': 'https://chromium.googlesource.com',
17-
'gn_version': 'git_revision:2ecd43a10266bd091c98e6dcde507c64f6a0dad3',
17+
'gn_version': 'git_revision:5e19d2fb166fbd4f6f32147fbb2f497091a54ad8',
18+
# ninja CIPD package version.
19+
# https://chrome-infra-packages.appspot.com/p/infra/3pp/tools/ninja
20+
'ninja_version': 'version:[email protected]',
1821
'pull_linux_clang': False,
1922
'pull_win_toolchain': False,
2023
# Controls whether crashpad/build/ios/setup-ios-gn.py is run as part of
@@ -133,6 +136,51 @@ deps = {
133136
'condition': 'checkout_fuchsia and host_os == "linux"',
134137
'dep_type': 'cipd'
135138
},
139+
# depot_tools/ninja wrapper calls third_party/ninja/{ninja, ninja.exe}.
140+
# crashpad/third_party/ninja/ninja is another wrapper to call linux ninja
141+
# or mac ninja.
142+
# This allows crashpad developers to work for multiple platforms on the same
143+
# machine.
144+
'crashpad/third_party/ninja': {
145+
'packages': [
146+
{
147+
'package': 'infra/3pp/tools/ninja/${{platform}}',
148+
'version': Var('ninja_version'),
149+
}
150+
],
151+
'condition': 'host_os == "win"',
152+
'dep_type': 'cipd',
153+
},
154+
'crashpad/third_party/ninja/linux': {
155+
'packages': [
156+
{
157+
'package': 'infra/3pp/tools/ninja/${{platform}}',
158+
'version': Var('ninja_version'),
159+
}
160+
],
161+
'condition': 'host_os == "linux"',
162+
'dep_type': 'cipd',
163+
},
164+
'crashpad/third_party/ninja/mac-amd64': {
165+
'packages': [
166+
{
167+
'package': 'infra/3pp/tools/ninja/mac-amd64',
168+
'version': Var('ninja_version'),
169+
}
170+
],
171+
'condition': 'host_os == "mac" and host_cpu == "x64"',
172+
'dep_type': 'cipd',
173+
},
174+
'crashpad/third_party/ninja/mac-arm64': {
175+
'packages': [
176+
{
177+
'package': 'infra/3pp/tools/ninja/mac-arm64',
178+
'version': Var('ninja_version'),
179+
}
180+
],
181+
'condition': 'host_os == "mac" and host_cpu == "arm64"',
182+
'dep_type': 'cipd',
183+
},
136184
'crashpad/third_party/win/toolchain': {
137185
# This package is only updated when the solution in .gclient includes an
138186
# entry like:

Diff for: build/BUILD.gn

+6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ config("crashpad_is_in_fuchsia") {
3030
}
3131
}
3232

33+
config("flock_always_supported_defines") {
34+
defines = [
35+
"CRASHPAD_FLOCK_ALWAYS_SUPPORTED=$crashpad_flock_always_supported",
36+
]
37+
}
38+
3339
group("default_exe_manifest_win") {
3440
if (crashpad_is_in_chromium) {
3541
deps = [ "//build/win:default_exe_manifest" ]

Diff for: build/crashpad_buildconfig.gni

+6-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ crashpad_is_standalone = crashpad_dependencies == "standalone"
3737
# This is the parent directory that contains the mini_chromium source dir.
3838
# This variable is not used when crashpad_is_in_chromium.
3939
if (crashpad_is_in_fuchsia) {
40-
mini_chromium_source_parent = "//third_party/crashpad/third_party/mini_chromium"
40+
import("//third_party/crashpad/fuchsia_buildconfig.gni")
41+
mini_chromium_source_parent =
42+
fuchsia_crashpad_root + "/third_party/mini_chromium"
4143
} else {
4244
mini_chromium_source_parent = "../third_party/mini_chromium"
4345
}
@@ -49,7 +51,7 @@ _mini_chromium_source_root = "$mini_chromium_source_parent/mini_chromium"
4951
if (crashpad_is_external || crashpad_is_in_dart) {
5052
mini_chromium_import_root = "../../../$_mini_chromium_source_root"
5153
} else if (crashpad_is_in_fuchsia) {
52-
mini_chromium_import_root = "//third_party/mini_chromium"
54+
mini_chromium_import_root = fuchsia_mini_chromium_root
5355
} else {
5456
mini_chromium_import_root = _mini_chromium_source_root
5557
}
@@ -81,6 +83,8 @@ if (crashpad_is_in_chromium) {
8183
crashpad_is_clang = mini_chromium_is_clang
8284
}
8385

86+
crashpad_flock_always_supported = !(crashpad_is_android || crashpad_is_fuchsia)
87+
8488
template("crashpad_executable") {
8589
executable(target_name) {
8690
forward_variables_from(invoker,

Diff for: build/run_tests.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ def _adb_shell(command_args, env={}):
312312
_adb_shell(['rm', '-rf', device_temp_dir])
313313

314314

315-
def _RunOnIOSTarget(binary_dir, test, is_xcuitest=False):
315+
def _RunOnIOSTarget(binary_dir, test, is_xcuitest=False, gtest_filter=None):
316316
"""Runs the given iOS |test| app on iPhone 8 with the default OS version."""
317317

318-
def xctest(binary_dir, test):
318+
def xctest(binary_dir, test, gtest_filter=None):
319319
"""Returns a dict containing the xctestrun data needed to run an
320320
XCTest-based test app."""
321321
test_path = os.path.join(CRASHPAD_DIR, binary_dir)
@@ -332,6 +332,8 @@ def xctest(binary_dir, test):
332332
'XCInjectBundleInto': '__TESTHOST__/' + test,
333333
}
334334
}
335+
if gtest_filter:
336+
module_data['CommandLineArguments'] = ['--gtest_filter='+gtest_filter]
335337
return {test: module_data}
336338

337339
def xcuitest(binary_dir, test):
@@ -368,16 +370,18 @@ def xcuitest(binary_dir, test):
368370

369371
xctestrun_path = f.name
370372
print(xctestrun_path)
373+
command = [
374+
'xcodebuild', 'test-without-building', '-xctestrun', xctestrun_path,
375+
'-destination', 'platform=iOS Simulator,name=iPhone 8',
376+
]
371377
with open(xctestrun_path, 'wb') as fp:
372378
if is_xcuitest:
373379
plistlib.dump(xcuitest(binary_dir, test), fp)
380+
if gtest_filter:
381+
command.append('-only-testing:' + test + '/' + gtest_filter)
374382
else:
375-
plistlib.dump(xctest(binary_dir, test), fp)
376-
377-
subprocess.check_call([
378-
'xcodebuild', 'test-without-building', '-xctestrun', xctestrun_path,
379-
'-destination', 'platform=iOS Simulator,name=iPhone 8'
380-
])
383+
plistlib.dump(xctest(binary_dir, test, gtest_filter), fp)
384+
subprocess.check_call(command)
381385

382386

383387
# This script is primarily used from the waterfall so that the list of tests
@@ -468,7 +472,8 @@ def main(args):
468472
elif is_ios:
469473
_RunOnIOSTarget(args.binary_dir,
470474
test,
471-
is_xcuitest=test.startswith('ios'))
475+
is_xcuitest=test.startswith('ios'),
476+
gtest_filter=args.gtest_filter)
472477
else:
473478
subprocess.check_call([os.path.join(args.binary_dir, test)] +
474479
extra_command_line)

Diff for: client/BUILD.gn

+17
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ static_library("common") {
119119
"crash_report_database.h",
120120
"crashpad_info.cc",
121121
"crashpad_info.h",
122+
"length_delimited_ring_buffer.h",
123+
"ring_buffer_annotation.h",
122124
"settings.cc",
123125
"settings.h",
124126
"simple_address_range_bag.h",
@@ -144,6 +146,19 @@ static_library("common") {
144146
"../util",
145147
]
146148
deps = [ "../util" ]
149+
configs += [ "../build:flock_always_supported_defines" ]
150+
}
151+
152+
crashpad_executable("ring_buffer_annotation_load_test") {
153+
testonly = true
154+
sources = [
155+
"ring_buffer_annotation_load_test_main.cc",
156+
]
157+
deps = [
158+
":client",
159+
"../tools:tool_support",
160+
"$mini_chromium_source_parent:base",
161+
]
147162
}
148163

149164
source_set("client_test") {
@@ -153,7 +168,9 @@ source_set("client_test") {
153168
"annotation_list_test.cc",
154169
"annotation_test.cc",
155170
"crash_report_database_test.cc",
171+
"length_delimited_ring_buffer_test.cc",
156172
"prune_crash_reports_test.cc",
173+
"ring_buffer_annotation_test.cc",
157174
"settings_test.cc",
158175
"simple_address_range_bag_test.cc",
159176
"simple_string_dictionary_test.cc",

Diff for: client/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,3 @@ target_include_directories(client PUBLIC ..)
5555
if (LINUX)
5656
target_link_libraries(client PUBLIC Threads::Threads)
5757
endif (LINUX)
58-

Diff for: client/annotation.h

+77-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <algorithm>
1919
#include <atomic>
20+
#include <optional>
2021

2122
#include <stdint.h>
2223
#include <string.h>
@@ -26,6 +27,7 @@
2627
#include "base/numerics/safe_conversions.h"
2728
#include "base/strings/string_piece.h"
2829
#include "build/build_config.h"
30+
#include "util/synchronization/scoped_spin_guard.h"
2931

3032
namespace crashpad {
3133
#if BUILDFLAG(IS_IOS)
@@ -94,6 +96,20 @@ class Annotation {
9496
kUserDefinedStart = 0x8000,
9597
};
9698

99+
//! \brief Mode used to guard concurrent reads from writes.
100+
enum class ConcurrentAccessGuardMode : bool {
101+
//! \!brief Annotation does not guard reads from concurrent
102+
//! writes. Annotation values can be corrupted if the process crashes
103+
//! mid-write and the handler tries to read from the Annotation while
104+
//! being written to.
105+
kUnguarded = false,
106+
107+
//! \!brief Annotation guards reads from concurrent writes using
108+
//! ScopedSpinGuard. Clients must use TryCreateScopedSpinGuard()
109+
//! before reading or writing the data in this Annotation.
110+
kScopedSpinGuard = true,
111+
};
112+
97113
//! \brief Creates a user-defined Annotation::Type.
98114
//!
99115
//! This exists to remove the casting overhead of `enum class`.
@@ -132,12 +148,11 @@ class Annotation {
132148
//! \param[in] value_ptr A pointer to the value for the annotation. The
133149
//! pointer may not be changed once associated with an annotation, but
134150
//! the data may be mutated.
135-
constexpr Annotation(Type type, const char name[], void* const value_ptr)
136-
: link_node_(nullptr),
137-
name_(name),
138-
value_ptr_(value_ptr),
139-
size_(0),
140-
type_(type) {}
151+
constexpr Annotation(Type type, const char name[], void* value_ptr)
152+
: Annotation(type,
153+
name,
154+
value_ptr,
155+
ConcurrentAccessGuardMode::kUnguarded) {}
141156

142157
Annotation(const Annotation&) = delete;
143158
Annotation& operator=(const Annotation&) = delete;
@@ -172,7 +187,58 @@ class Annotation {
172187
const char* name() const { return name_; }
173188
const void* value() const { return value_ptr_; }
174189

190+
ConcurrentAccessGuardMode concurrent_access_guard_mode() const {
191+
return concurrent_access_guard_mode_;
192+
}
193+
194+
//! \brief If this Annotation guards concurrent access using ScopedSpinGuard,
195+
//! tries to obtain the spin guard and returns the result.
196+
//!
197+
//! \param[in] timeout_ns The timeout in nanoseconds after which to give up
198+
//! trying to obtain the spin guard.
199+
//! \return std::nullopt if the spin guard could not be obtained within
200+
//! timeout_ns, or the obtained spin guard otherwise.
201+
std::optional<ScopedSpinGuard> TryCreateScopedSpinGuard(uint64_t timeout_ns) {
202+
// This can't use DCHECK_EQ() because ostream doesn't support
203+
// operator<<(bool).
204+
DCHECK(concurrent_access_guard_mode_ ==
205+
ConcurrentAccessGuardMode::kScopedSpinGuard);
206+
if (concurrent_access_guard_mode_ ==
207+
ConcurrentAccessGuardMode::kUnguarded) {
208+
return std::nullopt;
209+
}
210+
return ScopedSpinGuard::TryCreateScopedSpinGuard(timeout_ns,
211+
spin_guard_state_);
212+
}
213+
175214
protected:
215+
//! \brief Constructs a new annotation.
216+
//!
217+
//! Upon construction, the annotation will not be included in any crash
218+
//! reports until \sa SetSize() is called with a value greater than `0`.
219+
//!
220+
//! \param[in] type The data type of the value of the annotation.
221+
//! \param[in] name A `NUL`-terminated C-string name for the annotation. Names
222+
//! do not have to be unique, though not all crash processors may handle
223+
//! Annotations with the same name. Names should be constexpr data with
224+
//! static storage duration.
225+
//! \param[in] value_ptr A pointer to the value for the annotation. The
226+
//! pointer may not be changed once associated with an annotation, but
227+
//! the data may be mutated.
228+
//! \param[in] concurrent_access_guard_mode Mode used to guard concurrent
229+
//! reads from writes.
230+
constexpr Annotation(Type type,
231+
const char name[],
232+
void* value_ptr,
233+
ConcurrentAccessGuardMode concurrent_access_guard_mode)
234+
: link_node_(nullptr),
235+
name_(name),
236+
value_ptr_(value_ptr),
237+
size_(0),
238+
type_(type),
239+
concurrent_access_guard_mode_(concurrent_access_guard_mode),
240+
spin_guard_state_() {}
241+
176242
friend class AnnotationList;
177243
#if BUILDFLAG(IS_IOS)
178244
friend class internal::InProcessIntermediateDumpHandler;
@@ -192,6 +258,11 @@ class Annotation {
192258
void* const value_ptr_;
193259
ValueSizeType size_;
194260
const Type type_;
261+
262+
//! \brief Mode used to guard concurrent reads from writes.
263+
const ConcurrentAccessGuardMode concurrent_access_guard_mode_;
264+
265+
SpinGuardState spin_guard_state_;
195266
};
196267

197268
//! \brief An \sa Annotation that stores a `NUL`-terminated C-string value.

0 commit comments

Comments
 (0)