Loading...
--- libmalloc/libmalloc-657.80.3/src/malloc_exclaves.c
+++ libmalloc/libmalloc-792.1.1/src/malloc_exclaves.c
@@ -27,6 +27,9 @@
#define MAX_MALLOC_ZONES 2
+#define DEFAULT_MALLOC_ZONE_STRING "DefaultXzoneZone"
+#define DEFAULT_SANITIZER_ZONE_STRING "DefaultWrapperSanitizerZone"
+
MALLOC_NOEXPORT
unsigned int phys_ncpus = 0;
@@ -38,6 +41,8 @@
malloc_zone_t ** __unsafe_indexable malloc_zones = _malloc_zones;
bool malloc_sanitizer_enabled = false;
+
+
#if __LIBLIBC_F_ASAN_INSTRUMENTATION
static struct malloc_sanitizer_poison malloc_poison_default = {
.heap_allocate_poison = __asan_poison_heap_memory_alloc,
@@ -141,15 +146,19 @@
logical_ncpus = _liblibc_plat_num_cpus;
phys_ncpus = _liblibc_plat_num_cpus;
+
const unsigned malloc_debug_flags = MALLOC_ABORT_ON_CORRUPTION |
MALLOC_ABORT_ON_ERROR;
- mfm_initialize();
- _malloc_zone_register(xzm_main_malloc_zone_create(malloc_debug_flags,
- NULL, args, NULL), true);
+ malloc_zone_t *xzone = xzm_main_malloc_zone_create(malloc_debug_flags,
+ NULL, args, NULL);
+ _malloc_zone_register(xzone, true);
+ malloc_set_zone_name(xzone, DEFAULT_MALLOC_ZONE_STRING);
#if __LIBLIBC_F_ASAN_INSTRUMENTATION
if ((malloc_sanitizer_enabled = sanitizer_should_enable())) {
- _malloc_zone_register(sanitizer_create_zone(_malloc_zones[0]), true);
+ malloc_zone_t *sanitizer = sanitizer_create_zone(xzone);
+ _malloc_zone_register(sanitizer, true);
+ malloc_set_zone_name(sanitizer, DEFAULT_SANITIZER_ZONE_STRING);
}
#endif // __LIBLIBC_F_ASAN_INSTRUMENTATION
}
@@ -283,7 +292,7 @@
// excludes 0 == alignment
// relies on sizeof(void *) being a power of two.
- if (alignment < sizeof(void *) ||
+ if (alignment < MALLOC_ZONE_MALLOC_DEFAULT_ALIGN ||
0 != (alignment & (alignment - 1))) {
err = EINVAL;
goto out;
@@ -319,8 +328,8 @@
MALLOC_NOINLINE
void * __sized_by_or_null(size)
-malloc_zone_malloc_with_options_np(malloc_zone_t *zone, size_t align,
- size_t size, malloc_options_np_t options)
+malloc_zone_malloc_with_options(malloc_zone_t *zone, size_t align,
+ size_t size, malloc_zone_malloc_options_t options)
{
if (os_unlikely((align != 0) && (!powerof2(align) ||
((size & (align-1)) != 0)))) { // equivalent to (size % align != 0)
@@ -335,17 +344,25 @@
return zone->malloc_with_options(zone, align, size, options);
}
- if (align) {
+ if (align > MALLOC_ZONE_MALLOC_DEFAULT_ALIGN) {
void *ptr = zone->memalign(zone, align, size);
- if (ptr && (options & MALLOC_NP_OPTION_CLEAR)) {
+ if (ptr && (options & MALLOC_ZONE_MALLOC_OPTION_CLEAR)) {
memset(ptr, 0, size);
}
return ptr;
- } else if (options & MALLOC_NP_OPTION_CLEAR) {
+ } else if (options & MALLOC_ZONE_MALLOC_OPTION_CLEAR) {
return zone->calloc(zone, 1, size);
} else {
return zone->malloc(zone, size);
}
+}
+
+MALLOC_NOINLINE
+void * __sized_by_or_null(size)
+malloc_zone_malloc_with_options_np(malloc_zone_t *zone, size_t align,
+ size_t size, malloc_options_np_t options)
+{
+ return malloc_zone_malloc_with_options(zone, align, size, options);
}
boolean_t
@@ -409,9 +426,7 @@
zone = _find_registered_zone(ptr, &size, known_non_default);
if (!zone) {
- malloc_report(MALLOC_REPORT_DEBUG | MALLOC_REPORT_NOLOG,
- "*** error for object %p: pointer being freed was not allocated\n",
- ptr);
+ malloc_report_pointer_was_not_allocated(MALLOC_REPORT_CRASH, ptr);
} else if (zone->free_definite_size) {
malloc_zone_free_definite_size(zone,
__unsafe_forge_bidi_indexable(void *, ptr, size), size);
@@ -483,9 +498,8 @@
} else {
zone = _find_registered_zone(old_ptr, NULL, false);
if (!zone) {
- malloc_report(MALLOC_REPORT_CRASH,
- "*** error for object %p: pointer being realloc'd was not allocated\n",
- in_ptr);
+ malloc_report_pointer_was_not_allocated(MALLOC_REPORT_CRASH,
+ in_ptr);
} else {
retval = malloc_zone_realloc(zone, old_ptr, new_size);
}
@@ -562,7 +576,7 @@
// the test made in malloc_zone_memalign to vet each request. Only if
// that test fails and returns NULL, do we arrive here to detect the
// bogus alignment and give the required EINVAL return.
- if (alignment < sizeof(void *) || // excludes 0 == alignment
+ if (alignment < MALLOC_ZONE_MALLOC_DEFAULT_ALIGN || // excludes 0 == alignment
0 != (alignment & (alignment - 1))) { // relies on sizeof(void *)
// being a power of two.
return EINVAL;