[PATCH] D54045: Introduce `sanitizer_malloc_introspect_t` for Darwin which is a sub-class of Darwin's `malloc_introspection_t` and use it when setting up the malloc zone.
Dan Liew via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 2 12:23:53 PDT 2018
delcypher created this revision.
delcypher added reviewers: kubamracek, george.karpenkov, vitalybuka.
Herald added a subscriber: Sanitizers.
Currently `sanitizer_malloc_introspection_t` just adds a version field
which is used to version the allocator ABI. The current allocator ABI
version is returned by the new `GetMallocZoneAllocatorEnumerationVersion()` function.
The motivation behind this change is to allow external processes to
determine the allocator ABI of a sanitized process.
rdar://problem/45284065
Repository:
rCRT Compiler Runtime
https://reviews.llvm.org/D54045
Files:
lib/sanitizer_common/sanitizer_malloc_introspection_t.h
lib/sanitizer_common/sanitizer_malloc_mac.inc
Index: lib/sanitizer_common/sanitizer_malloc_mac.inc
===================================================================
--- lib/sanitizer_common/sanitizer_malloc_mac.inc
+++ lib/sanitizer_common/sanitizer_malloc_mac.inc
@@ -25,14 +25,24 @@
#include "interception/interception.h"
#include "sanitizer_common/sanitizer_mac.h"
+#include "sanitizer_common/sanitizer_malloc_introspection_t.h"
// Similar code is used in Google Perftools,
// https://github.com/gperftools/gperftools.
namespace __sanitizer {
+
extern malloc_zone_t sanitizer_zone;
+
+u64 GetMallocZoneAllocatorEnumerationVersion() {
+ // This represents the current allocator ABI version.
+ // This field should be incremented every time the Allocator
+ // ABI changes in a way that breaks allocator enumeration.
+ return 0;
}
+} // namespace __sanitizer
+
INTERCEPTOR(malloc_zone_t *, malloc_create_zone,
vm_size_t start_size, unsigned zone_flags) {
COMMON_MALLOC_ENTER();
@@ -303,7 +313,7 @@
namespace COMMON_MALLOC_NAMESPACE {
void InitMallocZoneFields() {
- static malloc_introspection_t sanitizer_zone_introspection;
+ static sanitizer_malloc_introspection_t sanitizer_zone_introspection;
// Ok to use internal_memset, these places are not performance-critical.
internal_memset(&sanitizer_zone_introspection, 0,
sizeof(sanitizer_zone_introspection));
@@ -318,6 +328,10 @@
sanitizer_zone_introspection.statistics = &mi_statistics;
sanitizer_zone_introspection.zone_locked = &mi_zone_locked;
+ // Set current allocator enumeration version.
+ sanitizer_zone_introspection.allocator_enumeration_version =
+ GetMallocZoneAllocatorEnumerationVersion();
+
internal_memset(&sanitizer_zone, 0, sizeof(malloc_zone_t));
// Use version 6 for OSX >= 10.6.
Index: lib/sanitizer_common/sanitizer_malloc_introspection_t.h
===================================================================
--- /dev/null
+++ lib/sanitizer_common/sanitizer_malloc_introspection_t.h
@@ -0,0 +1,38 @@
+//===-- sanitizer_malloc_introspect_t.h -------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Provides a sub class of the Darwin malloc_introspection_t struct type so
+// that Sanitizer specific fields can be stored.
+//
+//===----------------------------------------------------------------------===//
+#ifndef SANITIZER_MALLOC_INTROSPECT_T_H
+#define SANITIZER_MALLOC_INTROSPECT_T_H
+#include "sanitizer_common/sanitizer_platform.h"
+
+#if SANITIZER_MAC
+#include <malloc/malloc.h>
+#include "sanitizer_common/sanitizer_internal_defs.h"
+
+namespace __sanitizer {
+
+struct sanitizer_malloc_introspection_t : public malloc_introspection_t {
+ // IMPORTANT: Do not change the order, alignment, or types of these fields to
+ // maintain binary compatibility. You should only add fields to this struct.
+
+ // Used to track changes to the allocator that will affect
+ // zone enumeration.
+ u64 allocator_enumeration_version;
+};
+
+u64 GetMallocZoneAllocatorEnumerationVersion();
+
+} // namespace __sanitizer
+
+#endif
+#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54045.172415.patch
Type: text/x-patch
Size: 3335 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181102/60e2abc1/attachment.bin>
More information about the llvm-commits
mailing list