Skip to content

Commit fa3d924

Browse files
committed
run clang format, fix commented code, dont flush caches unless root is locked
1 parent 9990c7d commit fa3d924

4 files changed

Lines changed: 13 additions & 6 deletions

File tree

include/iso_alloc_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ INTERNAL_HIDDEN INLINE void insert_free_bit_slot(iso_alloc_zone *zone, int64_t b
532532
INTERNAL_HIDDEN INLINE void write_canary(iso_alloc_zone *zone, void *p);
533533
INTERNAL_HIDDEN INLINE void populate_thread_caches(iso_alloc_zone *zone);
534534
INTERNAL_HIDDEN INLINE size_t next_pow2(size_t sz);
535+
INTERNAL_HIDDEN INLINE void _flush_thread_caches(void);
535536
INTERNAL_HIDDEN iso_alloc_zone *is_zone_usable(iso_alloc_zone *zone, size_t size);
536537
INTERNAL_HIDDEN iso_alloc_zone *iso_find_zone_fit(size_t size);
537538
INTERNAL_HIDDEN iso_alloc_zone *iso_new_zone(size_t size, bool internal);

src/iso_alloc.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ __attribute__((constructor(FIRST_CTOR))) void iso_alloc_ctor(void) {
426426
}
427427

428428
INTERNAL_HIDDEN void flush_thread_caches() {
429+
LOCK_ROOT();
430+
_flush_thread_caches();
431+
UNLOCK_ROOT();
432+
}
433+
434+
INTERNAL_HIDDEN INLINE void _flush_thread_caches() {
429435
#if THREAD_SUPPORT && THREAD_CACHE
430436
/* The thread zone cache can be invalidated */
431437
memset(thread_zone_cache, 0x0, sizeof(thread_zone_cache));
@@ -467,7 +473,7 @@ INTERNAL_HIDDEN void _iso_alloc_destroy_zone(iso_alloc_zone *zone) {
467473
LOCK_ROOT();
468474
UNMASK_ZONE_PTRS(zone);
469475
UNPOISON_ZONE(zone);
470-
flush_thread_caches();
476+
_flush_thread_caches();
471477

472478
if(zone->internally_managed == false) {
473479
#if NEVER_REUSE_ZONES || FUZZ_MODE
@@ -522,7 +528,7 @@ INTERNAL_HIDDEN void _iso_alloc_destroy_zone(iso_alloc_zone *zone) {
522528
__attribute__((destructor(LAST_DTOR))) void iso_alloc_dtor(void) {
523529
LOCK_ROOT();
524530

525-
flush_thread_caches();
531+
_flush_thread_caches();
526532

527533
#if HEAP_PROFILER
528534
_iso_output_profile();
@@ -812,7 +818,7 @@ INTERNAL_HIDDEN iso_alloc_zone *is_zone_usable(iso_alloc_zone *zone, size_t size
812818
UNMASK_ZONE_PTRS(zone);
813819

814820
/* If the cache for this zone is empty we should
815-
* refill it to make future allocations faster
821+
* refill it to make future allocations faster
816822
* for all threads */
817823
if(zone->free_bit_slot_cache_usable >= zone->free_bit_slot_cache_index) {
818824
fill_free_bit_slot_cache(zone);
@@ -1176,7 +1182,7 @@ INTERNAL_HIDDEN void *_iso_alloc(iso_alloc_zone *zone, size_t size) {
11761182
#if THREAD_SUPPORT && THREAD_CACHE
11771183
if(LIKELY(zone == NULL) && size <= SMALL_SZ_MAX) {
11781184
for(int32_t i = 0; i < THREAD_CHUNK_CACHE_SZ; i++) {
1179-
if(thread_chunk_cache[i].chunk != NULL && thread_chunk_cache[i].chunk_size >= size){ //(size << WASTED_SZ_MULTIPLIER_SHIFT)) {
1185+
if(thread_chunk_cache[i].chunk != NULL && thread_chunk_cache[i].chunk_size >= (size << WASTED_SZ_MULTIPLIER_SHIFT)) {
11801186
void *p = thread_chunk_cache[i].chunk;
11811187
thread_chunk_cache[i].chunk = NULL;
11821188
thread_chunk_cache[i].chunk_size = 0;

src/iso_alloc_search.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ INTERNAL_HIDDEN void _iso_alloc_search_stack(uint8_t *stack_start) {
6767
* decides on values that are unlikely to be pointers
6868
* into zone user pages */
6969
if(*(int64_t *) current <= tps || *(int64_t *) current >= max_ptr || (*(int64_t *) current & 0xffffff) == 0) {
70-
//LOG("Ignoring pointer start=%p end=%p stack_ptr=%p value=%lx", stack_start, stack_end, current, *(int64_t *)current);
70+
// LOG("Ignoring pointer start=%p end=%p stack_ptr=%p value=%lx", stack_start, stack_end, current, *(int64_t *)current);
7171
current--;
7272
continue;
7373
}

src/malloc_hook.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* iso_alloc interfaces directly. These hook points are
1111
* useful because they allow us to use iso_alloc even in
1212
* existing and closed source programs that call malloc/free
13-
*/
13+
*/
1414
#if MALLOC_HOOK
1515

1616
EXTERNAL_API void *__libc_malloc(size_t s) {

0 commit comments

Comments
 (0)