mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
mac: Faster bit testing for EXC_GUARD exception “flavors”
After e7630628e9c9, I thought “isn’t there a standard library function for that?” There is! Change-Id: I284c7fdf8535c4fc53100e80fceb363bf2afee93 Reviewed-on: https://chromium-review.googlesource.com/431856 Reviewed-by: Scott Graham <scottmg@chromium.org>
This commit is contained in:
parent
e7630628e9
commit
1e4be91918
@ -20,6 +20,7 @@
|
||||
#include <errno.h>
|
||||
#include <libproc.h>
|
||||
#include <kern/exc_resource.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/mach_logging.h"
|
||||
@ -200,16 +201,19 @@ int32_t ExceptionCodeForMetrics(exception_type_t exception,
|
||||
// one another. For the purposes of encoding these codes for metrics,
|
||||
// convert the flavor codes to their corresponding bit shift values.
|
||||
const uint32_t guard_flavor = (code_0 >> 32) & 0x1fffffff;
|
||||
uint8_t metrics_guard_flavor = 0xff;
|
||||
for (int bit = 0; bit < 29; ++bit) {
|
||||
const uint32_t test_mask = 1 << bit;
|
||||
if (guard_flavor & test_mask) {
|
||||
// Make sure that no other bits are set.
|
||||
DCHECK_EQ(guard_flavor, test_mask);
|
||||
const int first_bit = ffs(guard_flavor);
|
||||
uint8_t metrics_guard_flavor;
|
||||
if (first_bit) {
|
||||
metrics_guard_flavor = first_bit - 1;
|
||||
|
||||
metrics_guard_flavor = bit;
|
||||
break;
|
||||
const uint32_t test_guard_flavor = 1 << metrics_guard_flavor;
|
||||
if (guard_flavor != test_guard_flavor) {
|
||||
// Another bit is set.
|
||||
DCHECK_EQ(guard_flavor, test_guard_flavor);
|
||||
metrics_guard_flavor = 0xff;
|
||||
}
|
||||
} else {
|
||||
metrics_guard_flavor = 0xff;
|
||||
}
|
||||
|
||||
metrics_code_0 = (guard_type << 8) | metrics_guard_flavor;
|
||||
|
Loading…
x
Reference in New Issue
Block a user