diff --git a/tcmalloc/common.h b/tcmalloc/common.h index 1c9aa2db9..4ef8b9ea2 100644 --- a/tcmalloc/common.h +++ b/tcmalloc/common.h @@ -277,6 +277,10 @@ enum class AllocationAccess { switch (GetMemoryTag(ptr)) { case MemoryTag::kNormalP1: return 1; + case MemoryTag::kSampledOrColdP1: + // Only sampled allocations of security partition 1 under kFull heap + // partitioning are tagged kSampledOrColdP1. + return 1; default: return 0; } diff --git a/tcmalloc/testing/partitioning_test_helper.cc b/tcmalloc/testing/partitioning_test_helper.cc index 77d2a0205..ee784ebd6 100644 --- a/tcmalloc/testing/partitioning_test_helper.cc +++ b/tcmalloc/testing/partitioning_test_helper.cc @@ -82,8 +82,16 @@ int main() { absl::PrintF("sampled_0_tag:%s\n", sampled_0_tag); absl::PrintF("sampled_1_tag:%s\n", sampled_1_tag); - free(sampled_0); - free(sampled_1); + // realloc() keeps the security partition of the old pointer. + void* realloc_0 = realloc(sampled_0, 64); + void* realloc_1 = realloc(sampled_1, 64); + absl::PrintF("realloc_sampled_0_tag:%s\n", + MemoryTagToLabel(GetMemoryTag(realloc_0))); + absl::PrintF("realloc_sampled_1_tag:%s\n", + MemoryTagToLabel(GetMemoryTag(realloc_1))); + + free(realloc_0); + free(realloc_1); } return 0;