mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Use atomics in metrics recording terminate handler
Accessing static data which requires dynamic initialization produces undefined behavior in signal handlers. Bug: crashpad:384 Change-Id: Ic100c8b34cb61a8ed76bd09e5a1178086d31fd68 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/3433270 Reviewed-by: Mark Mentovai <mark@chromium.org> Commit-Queue: Joshua Peraza <jperaza@chromium.org>
This commit is contained in:
parent
f96b86e360
commit
d464981876
@ -21,6 +21,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <atomic>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -286,10 +287,10 @@ bool AddKeyValueToMap(std::map<std::string, std::string>* map,
|
|||||||
// a normal exit, or if a CallMetricsRecordNormalExit object is destroyed after
|
// a normal exit, or if a CallMetricsRecordNormalExit object is destroyed after
|
||||||
// something else logs an exit event.
|
// something else logs an exit event.
|
||||||
void MetricsRecordExit(Metrics::LifetimeMilestone milestone) {
|
void MetricsRecordExit(Metrics::LifetimeMilestone milestone) {
|
||||||
[[maybe_unused]] static bool once = [](Metrics::LifetimeMilestone milestone) {
|
static std::atomic_flag metrics_exit_recorded = ATOMIC_FLAG_INIT;
|
||||||
|
if (!metrics_exit_recorded.test_and_set()) {
|
||||||
Metrics::HandlerLifetimeMilestone(milestone);
|
Metrics::HandlerLifetimeMilestone(milestone);
|
||||||
return true;
|
}
|
||||||
}(milestone);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls MetricsRecordExit() to record a failure, and returns EXIT_FAILURE for
|
// Calls MetricsRecordExit() to record a failure, and returns EXIT_FAILURE for
|
||||||
|
Loading…
x
Reference in New Issue
Block a user