Skip to content

Commit

Permalink
mac: Update knowledge of CFAllocator internals for 10.14
Browse files Browse the repository at this point in the history
For each new major OS version, we need to poke at the internals
of CFAllocator to enable the out-of-memory killer for the default
CFAllocator implementations.

This update is for macOS 10.14 ("Mojave"), whose CFAllocator
internals are unchanged from 10.13 (and in fact from 10.7). It also
updates the base::mac::IsOS*() family of functions for this new OS
version.

BUG=45650
TEST=base_unittests

Change-Id: I6db31edc6d85870566a6eb491c99d7900db331c7
Reviewed-on: https://chromium-review.googlesource.com/1095320
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#566068}
  • Loading branch information
Avi Drissman authored and Commit Bot committed Jun 11, 2018
1 parent c04baf4 commit 17901fb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 17 deletions.
2 changes: 1 addition & 1 deletion base/allocator/allocator_interception_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ void oom_killer_free_purgeable(struct _malloc_zone_t* zone, void* ptr) {
// === Core Foundation CFAllocators ===

bool CanGetContextForCFAllocator() {
return !base::mac::IsOSLaterThan10_13_DontCallThis();
return !base::mac::IsOSLaterThan10_14_DontCallThis();
}

CFAllocatorContext* ContextForCFAllocator(CFAllocatorRef allocator) {
Expand Down
10 changes: 8 additions & 2 deletions base/mac/mac_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,21 @@ DEFINE_IS_OS_FUNCS(13, TEST_DEPLOYMENT_TARGET)
DEFINE_IS_OS_FUNCS(13, IGNORE_DEPLOYMENT_TARGET)
#endif

#ifdef MAC_OS_X_VERSION_10_14
DEFINE_IS_OS_FUNCS(14, TEST_DEPLOYMENT_TARGET)
#else
DEFINE_IS_OS_FUNCS(14, IGNORE_DEPLOYMENT_TARGET)
#endif

#undef IGNORE_DEPLOYMENT_TARGET
#undef TEST_DEPLOYMENT_TARGET
#undef DEFINE_IS_OS_FUNCS

// This should be infrequently used. It only makes sense to use this to avoid
// codepaths that are very likely to break on future (unreleased, untested,
// unborn) OS releases, or to log when the OS is newer than any known version.
inline bool IsOSLaterThan10_13_DontCallThis() {
return !IsAtMostOS10_13();
inline bool IsOSLaterThan10_14_DontCallThis() {
return !IsAtMostOS10_14();
}

// Retrieve the system's model identifier string from the IOKit registry:
Expand Down
110 changes: 96 additions & 14 deletions base/mac/mac_util_unittest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -136,94 +136,176 @@
int32_t major, minor, bugfix;
base::SysInfo::OperatingSystemVersionNumbers(&major, &minor, &bugfix);

// The patterns here are:
// - FALSE/FALSE/TRUE (it is not the earlier version, it is not "at most" the
// earlier version, it is "at least" the earlier version)
// - TRUE/TRUE/TRUE (it is the same version, it is "at most" the same version,
// it is "at least" the same version)
// - FALSE/TRUE/FALSE (it is not the later version, it is "at most" the later
// version, it is not "at least" the later version)

// TODO(avi): Is there a better way to test this? Maybe with macros? Are
// macros a better way to test this?

if (major == 10) {
if (minor == 9) {
EXPECT_TRUE(IsOS10_9());
EXPECT_TRUE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_FALSE(IsOS10_10());
EXPECT_TRUE(IsAtMostOS10_10());
EXPECT_FALSE(IsAtLeastOS10_10());

EXPECT_FALSE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_FALSE(IsAtLeastOS10_11());

EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());

EXPECT_FALSE(IsOS10_13());
EXPECT_FALSE(IsAtLeastOS10_13());
EXPECT_TRUE(IsAtMostOS10_13());
EXPECT_FALSE(IsOSLaterThan10_13_DontCallThis());
EXPECT_FALSE(IsAtLeastOS10_13());

EXPECT_FALSE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_FALSE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else if (minor == 10) {
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_TRUE(IsOS10_10());
EXPECT_TRUE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());

EXPECT_FALSE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_FALSE(IsAtLeastOS10_11());

EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());

EXPECT_FALSE(IsOS10_13());
EXPECT_FALSE(IsAtLeastOS10_13());
EXPECT_TRUE(IsAtMostOS10_13());
EXPECT_FALSE(IsOSLaterThan10_13_DontCallThis());
EXPECT_FALSE(IsAtLeastOS10_13());

EXPECT_FALSE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_FALSE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else if (minor == 11) {
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());

EXPECT_TRUE(IsOS10_11());
EXPECT_TRUE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());

EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_FALSE(IsAtLeastOS10_12());

EXPECT_FALSE(IsOS10_13());
EXPECT_FALSE(IsAtLeastOS10_13());
EXPECT_TRUE(IsAtMostOS10_13());
EXPECT_FALSE(IsOSLaterThan10_13_DontCallThis());
EXPECT_FALSE(IsAtLeastOS10_13());

EXPECT_FALSE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_FALSE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else if (minor == 12) {
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());

EXPECT_FALSE(IsOS10_11());
EXPECT_FALSE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());

EXPECT_TRUE(IsOS10_12());
EXPECT_TRUE(IsAtMostOS10_12());
EXPECT_TRUE(IsAtLeastOS10_12());

EXPECT_FALSE(IsOS10_13());
EXPECT_FALSE(IsAtLeastOS10_13());
EXPECT_TRUE(IsAtMostOS10_13());
EXPECT_FALSE(IsOSLaterThan10_13_DontCallThis());
EXPECT_FALSE(IsAtLeastOS10_13());

EXPECT_FALSE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_FALSE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else if (minor == 13) {
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());

EXPECT_FALSE(IsOS10_11());
EXPECT_FALSE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());

EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtMostOS10_12());
EXPECT_TRUE(IsAtLeastOS10_12());

EXPECT_TRUE(IsOS10_13());
EXPECT_TRUE(IsAtLeastOS10_13());
EXPECT_TRUE(IsAtMostOS10_13());
EXPECT_FALSE(IsOSLaterThan10_13_DontCallThis());
EXPECT_TRUE(IsAtLeastOS10_13());

EXPECT_FALSE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_FALSE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else if (minor == 14) {
EXPECT_FALSE(IsOS10_9());
EXPECT_FALSE(IsAtMostOS10_9());
EXPECT_TRUE(IsAtLeastOS10_9());

EXPECT_FALSE(IsOS10_10());
EXPECT_FALSE(IsAtMostOS10_10());
EXPECT_TRUE(IsAtLeastOS10_10());

EXPECT_FALSE(IsOS10_11());
EXPECT_FALSE(IsAtMostOS10_11());
EXPECT_TRUE(IsAtLeastOS10_11());

EXPECT_FALSE(IsOS10_12());
EXPECT_FALSE(IsAtMostOS10_12());
EXPECT_TRUE(IsAtLeastOS10_12());

EXPECT_FALSE(IsOS10_13());
EXPECT_FALSE(IsAtMostOS10_13());
EXPECT_TRUE(IsAtLeastOS10_13());

EXPECT_TRUE(IsOS10_14());
EXPECT_TRUE(IsAtMostOS10_14());
EXPECT_TRUE(IsAtLeastOS10_14());

EXPECT_FALSE(IsOSLaterThan10_14_DontCallThis());
} else {
// Not nine, ten, eleven, twelve, or thirteen. Ah, ah, ah.
// Not nine, ten, eleven, twelve, thirteen, or fourteen. Ah, ah, ah.
EXPECT_TRUE(false);
}
} else {
Expand Down

0 comments on commit 17901fb

Please sign in to comment.