diff options
| author | Kacper <kacper@mail.openlinux.dev> | 2025-12-15 18:24:54 +0100 |
|---|---|---|
| committer | Kacper <kacper@mail.openlinux.dev> | 2025-12-15 18:24:54 +0100 |
| commit | 69e6fe89fa9baafeca3e3515bb50897cd8ee7c35 (patch) | |
| tree | 489046ce167b8b20d205f87f4ae1f4b680c19b43 /lib/libc/stdlib/free.c | |
| parent | 0d5bffe9d2caadc1215c875e560c52bca5161c54 (diff) | |
Add getauxval and cleanup libc startup
Diffstat (limited to 'lib/libc/stdlib/free.c')
| -rw-r--r-- | lib/libc/stdlib/free.c | 34 |
1 files changed, 13 insertions, 21 deletions
diff --git a/lib/libc/stdlib/free.c b/lib/libc/stdlib/free.c index ab656633..4afc800e 100644 --- a/lib/libc/stdlib/free.c +++ b/lib/libc/stdlib/free.c @@ -12,15 +12,14 @@ void free(void *ptr) return; } - LIBC_LOCK(libc.lock.malloc); + LIBC_LOCK(__libc.lock.malloc); struct page *p = __malloc_pvec; int found_in_pages = 0; while (p) { if ((uintptr_t)ptr >= (uintptr_t)p->heap && - (uintptr_t)ptr < (uintptr_t)(p->heap + (p->block.size * - p->block.count))) { + (uintptr_t)ptr < (uintptr_t)(p->heap + (p->block.size * p->block.count))) { size_t offset = (uintptr_t)ptr - (uintptr_t)p->heap; size_t index = offset / p->block.size; size_t byte_index = index / 8; @@ -42,14 +41,12 @@ void free(void *ptr) if (p == __malloc_pvec) __malloc_pvec = p->next; - munmap(p, (p->flags == PAGE_SMALL) ? - SMALL_PAGE_SIZE : - (p->flags == PAGE_MEDIUM) ? - MEDIUM_PAGE_SIZE : - LARGE_PAGE_SIZE); + munmap(p, (p->flags == PAGE_SMALL) ? SMALL_PAGE_SIZE : + (p->flags == PAGE_MEDIUM) ? MEDIUM_PAGE_SIZE : + LARGE_PAGE_SIZE); } - LIBC_UNLOCK(libc.lock.malloc); + LIBC_UNLOCK(__libc.lock.malloc); return; } p = p->next; @@ -61,11 +58,8 @@ void free(void *ptr) p = __malloc_pvec; while (p) { if ((uintptr_t)potential_orig >= (uintptr_t)p->heap && - (uintptr_t)potential_orig < - (uintptr_t)(p->heap + - (p->block.size * p->block.count))) { - size_t offset = - (uintptr_t)potential_orig - (uintptr_t)p->heap; + (uintptr_t)potential_orig < (uintptr_t)(p->heap + (p->block.size * p->block.count))) { + size_t offset = (uintptr_t)potential_orig - (uintptr_t)p->heap; size_t index = offset / p->block.size; size_t byte_index = index / 8; size_t bit_index = index % 8; @@ -85,18 +79,16 @@ void free(void *ptr) if (p == __malloc_pvec) __malloc_pvec = p->next; - munmap(p, (p->flags == PAGE_SMALL) ? - SMALL_PAGE_SIZE : - (p->flags == PAGE_MEDIUM) ? - MEDIUM_PAGE_SIZE : - LARGE_PAGE_SIZE); + munmap(p, (p->flags == PAGE_SMALL) ? SMALL_PAGE_SIZE : + (p->flags == PAGE_MEDIUM) ? MEDIUM_PAGE_SIZE : + LARGE_PAGE_SIZE); } - LIBC_UNLOCK(libc.lock.malloc); + LIBC_UNLOCK(__libc.lock.malloc); return; } p = p->next; } - LIBC_UNLOCK(libc.lock.malloc); + LIBC_UNLOCK(__libc.lock.malloc); } |
