@@ -53,44 +53,6 @@ static bool s_log_malloc = false;
5353static bool s_scrub_malloc = true ;
5454static bool s_scrub_free = true ;
5555static bool s_profiling = false ;
56- static bool s_in_userspace_emulator = false ;
57-
58- ALWAYS_INLINE static void ue_notify_malloc (void const * ptr, size_t size)
59- {
60- if (s_in_userspace_emulator)
61- syscall (SC_emuctl, 1 , size, (FlatPtr)ptr);
62- }
63-
64- ALWAYS_INLINE static void ue_notify_free (void const * ptr)
65- {
66- if (s_in_userspace_emulator)
67- syscall (SC_emuctl, 2 , (FlatPtr)ptr, 0 );
68- }
69-
70- ALWAYS_INLINE static void ue_notify_realloc (void const * ptr, size_t size)
71- {
72- if (s_in_userspace_emulator)
73- syscall (SC_emuctl, 3 , size, (FlatPtr)ptr);
74- }
75-
76- ALWAYS_INLINE static void ue_notify_chunk_size_changed (void const * block, size_t chunk_size)
77- {
78- if (s_in_userspace_emulator)
79- syscall (SC_emuctl, 4 , chunk_size, (FlatPtr)block);
80- }
81-
82- struct MemoryAuditingSuppressor {
83- ALWAYS_INLINE MemoryAuditingSuppressor ()
84- {
85- if (s_in_userspace_emulator)
86- syscall (SC_emuctl, 7 );
87- }
88- ALWAYS_INLINE ~MemoryAuditingSuppressor ()
89- {
90- if (s_in_userspace_emulator)
91- syscall (SC_emuctl, 8 );
92- }
93- };
9456
9557struct MallocStats {
9658 size_t number_of_malloc_calls;
@@ -348,20 +310,15 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
348310 new (block) BigAllocationBlock (real_size);
349311 }
350312
351- void * ptr = reinterpret_cast <void *>(round_up_to_power_of_two (reinterpret_cast <uintptr_t >(&block->m_slot [0 ]), align));
352-
353- ue_notify_malloc (ptr, size);
354- return ptr;
313+ return reinterpret_cast <void *>(round_up_to_power_of_two (reinterpret_cast <uintptr_t >(&block->m_slot [0 ]), align));
355314 }
356315 }
357316#endif
358317 auto * block = (BigAllocationBlock*)TRY (os_alloc (real_size, " malloc: BigAllocationBlock" ));
359318 g_malloc_stats.number_of_big_allocs ++;
360319 new (block) BigAllocationBlock (real_size);
361320
362- void * ptr = reinterpret_cast <void *>(round_up_to_power_of_two (reinterpret_cast <uintptr_t >(&block->m_slot [0 ]), align));
363- ue_notify_malloc (ptr, size);
364- return ptr;
321+ return reinterpret_cast <void *>(round_up_to_power_of_two (reinterpret_cast <uintptr_t >(&block->m_slot [0 ]), align));
365322 }
366323
367324 ChunkedBlock* block = nullptr ;
@@ -381,7 +338,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
381338 block = s_hot_empty_blocks[--s_hot_empty_block_count];
382339 if (block->m_size != good_size) {
383340 new (block) ChunkedBlock (good_size);
384- ue_notify_chunk_size_changed (block, good_size);
385341 char buffer[64 ];
386342 snprintf (buffer, sizeof (buffer), " malloc: ChunkedBlock(%zu)" , good_size);
387343 set_mmap_name (block, ChunkedBlock::block_size, buffer);
@@ -407,7 +363,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
407363 if (this_block_was_purged)
408364 g_malloc_stats.number_of_cold_empty_block_purge_hits ++;
409365 new (block) ChunkedBlock (good_size);
410- ue_notify_chunk_size_changed (block, good_size);
411366 }
412367 allocator->usable_blocks .append (*block);
413368 }
@@ -438,7 +393,6 @@ static ErrorOr<void*> malloc_impl(size_t size, size_t align, CallerWillInitializ
438393 if (s_scrub_malloc && caller_will_initialize_memory == CallerWillInitializeMemory::No)
439394 memset (ptr, MALLOC_SCRUB_BYTE, block->m_size );
440395
441- ue_notify_malloc (ptr, size);
442396 return ptr;
443397}
444398
@@ -538,7 +492,6 @@ static void free_impl(void* ptr)
538492// https://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html
539493void * malloc (size_t size)
540494{
541- MemoryAuditingSuppressor suppressor;
542495 auto ptr_or_error = malloc_impl (size, 16 , CallerWillInitializeMemory::No);
543496
544497 if (ptr_or_error.is_error ()) {
@@ -555,17 +508,14 @@ void* malloc(size_t size)
555508// https://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html
556509void free (void * ptr)
557510{
558- MemoryAuditingSuppressor suppressor;
559511 if (s_profiling)
560512 perf_event (PERF_EVENT_FREE, reinterpret_cast <FlatPtr>(ptr), 0 );
561- ue_notify_free (ptr);
562513 free_impl (ptr);
563514}
564515
565516// https://pubs.opengroup.org/onlinepubs/9699919799/functions/calloc.html
566517void * calloc (size_t count, size_t size)
567518{
568- MemoryAuditingSuppressor suppressor;
569519 if (Checked<size_t >::multiplication_would_overflow (count, size)) {
570520 errno = ENOMEM;
571521 return nullptr ;
@@ -585,7 +535,6 @@ void* calloc(size_t count, size_t size)
585535// https://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_memalign.html
586536int posix_memalign (void ** memptr, size_t alignment, size_t size)
587537{
588- MemoryAuditingSuppressor suppressor;
589538 auto ptr_or_error = malloc_impl (size, alignment, CallerWillInitializeMemory::No);
590539
591540 if (ptr_or_error.is_error ())
@@ -597,7 +546,6 @@ int posix_memalign(void** memptr, size_t alignment, size_t size)
597546
598547void * aligned_alloc (size_t alignment, size_t size)
599548{
600- MemoryAuditingSuppressor suppressor;
601549 auto ptr_or_error = malloc_impl (size, alignment, CallerWillInitializeMemory::No);
602550
603551 if (ptr_or_error.is_error ()) {
@@ -610,7 +558,6 @@ void* aligned_alloc(size_t alignment, size_t size)
610558
611559size_t malloc_size (void const * ptr)
612560{
613- MemoryAuditingSuppressor suppressor;
614561 if (!ptr)
615562 return 0 ;
616563 void * page_base = (void *)((FlatPtr)ptr & ChunkedBlock::block_mask);
@@ -632,7 +579,6 @@ size_t malloc_good_size(size_t size)
632579
633580void * realloc (void * ptr, size_t size)
634581{
635- MemoryAuditingSuppressor suppressor;
636582 if (!ptr)
637583 return malloc (size);
638584 if (!size) {
@@ -643,7 +589,6 @@ void* realloc(void* ptr, size_t size)
643589 auto existing_allocation_size = malloc_size (ptr);
644590
645591 if (size <= existing_allocation_size) {
646- ue_notify_realloc (ptr, size);
647592 return ptr;
648593 }
649594 auto * new_ptr = malloc (size);
@@ -656,14 +601,6 @@ void* realloc(void* ptr, size_t size)
656601
657602void __malloc_init ()
658603{
659- s_in_userspace_emulator = (int )syscall (SC_emuctl, 0 ) != -ENOSYS;
660- if (s_in_userspace_emulator) {
661- // Don't bother scrubbing memory if we're running in UE since it
662- // keeps track of heap memory anyway.
663- s_scrub_malloc = false ;
664- s_scrub_free = false ;
665- }
666-
667604 if (secure_getenv (" LIBC_NOSCRUB_MALLOC" ))
668605 s_scrub_malloc = false ;
669606 if (secure_getenv (" LIBC_NOSCRUB_FREE" ))
0 commit comments