diff options
| author | Scott Gasch <[email protected]> | 2026-09-13 12:06:21 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2026-09-13 12:06:21 -0700 |
| commit | d2699c47d6d0abf0f018e5ba37d4f1bfe05ecd33 (patch) | |
| tree | e8d450b234aa7202a17484e02a82297f479ea74b /src/unix.c | |
| parent | ddf932b885e08a47c88a66c3888f127f1c9d31c2 (diff) | |
Remove SystemAllocateMemory's hidden 4-byte tag-header scheme.
The HEAP/MMAP tag word written just before every allocated pointer (to
let SystemFreeMemory dispatch to free() vs munmap()) unconditionally
shifted every allocation 4 bytes off whatever alignment malloc actually
provided. The mmap path was permanently dead code (if (0), condition
commented out) -- malloc is the only allocator ever used -- so the tag
was pure overhead with no benefit, and it was silently defeating
g_pHashTable's deliberate 4-entries-per-cache-line (16 bytes x 4 = 64
bytes) layout: verified via lldb that the table was consistently
offset by exactly 4 bytes from a 64-byte boundary before this change,
and is now consistently 64-byte aligned across multiple runs.
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01C9r36BydPnfpyYLFhkTo6d
Diffstat (limited to 'src/unix.c')
| -rw-r--r-- | src/unix.c | 115 |
1 files changed, 3 insertions, 112 deletions
@@ -31,10 +31,6 @@ Revision History: #include <signal.h> #include <errno.h> -#define SYS_MAX_HEAP_ALLOC_SIZE_BYTES 0xfff -#define HEAP 0x48656170 -#define MMAP 0x4d6d6170 - pthread_mutex_t g_SystemLock; #define LOCK_SYSTEM pthread_mutex_lock(&g_SystemLock) #define UNLOCK_SYSTEM pthread_mutex_unlock(&g_SystemLock) @@ -518,68 +514,6 @@ Return value: } -static void * -_SystemCallMmap(ULONG dwSizeBytes) -/** - -Routine description: - - Wrapper around mmap. - -Parameters: - - ULONG dwSizeBytes - -Return value: - - static void - -**/ -{ - void *pMem = mmap(0, - (size_t)dwSizeBytes, - PROT_READ | PROT_WRITE, - MAP_ANON, - -1, - 0); - if (MAP_FAILED == pMem) - { - UtilPanic(UNEXPECTED_SYSTEM_CALL_FAILURE, - NULL, "mmap", (void *)(size_t)errno, (void *)(size_t)dwSizeBytes, - __FILE__, __LINE__); - } - (void)madvise(pMem, dwSizeBytes, MADV_RANDOM | MADV_WILLNEED); - return(pMem); -} - - -static void -_SystemCallMunmap(void *pMem) -/** - -Routine description: - - Wrapper around munmap - -Parameters: - - void *pMem - -Return value: - - static void - -**/ -{ - if (0 != munmap(pMem, (size_t)-1)) - { - UtilPanic(UNEXPECTED_SYSTEM_CALL_FAILURE, - NULL, "munmap", (void *)(size_t)errno, pMem, - __FILE__, __LINE__); - } -} - - static void *_SystemCallMalloc(ULONG dwSizeBytes) /** @@ -671,32 +605,7 @@ Return value: **/ { - DWORD *p; - - if (0) // (dwSizeBytes > SYS_MAX_HEAP_ALLOC_SIZE_BYTES) - { - p = _SystemCallMmap(dwSizeBytes + sizeof(DWORD)); - if (NULL == p) - { - UtilPanic(UNEXPECTED_SYSTEM_CALL_FAILURE, - NULL, "mmap", (void *)(size_t)errno, NULL, - __FILE__, __LINE__); - } - *p = MMAP; - p += 1; - } - else - { - p = _SystemCallMalloc(dwSizeBytes + sizeof(DWORD)); - if (NULL == p) - { - UtilPanic(UNEXPECTED_SYSTEM_CALL_FAILURE, - NULL, "malloc", (void *)(size_t)errno, NULL, - __FILE__, __LINE__); - } - *p = HEAP; - p += 1; - } + void *p = _SystemCallMalloc(dwSizeBytes); #ifdef DEBUG MarkAllocHashEntry(p, dwSizeBytes); #endif @@ -704,7 +613,7 @@ Return value: return(p); } -void +void SystemFreeMemory(void *pMemory) /** @@ -722,28 +631,10 @@ Return value: **/ { - DWORD *p = pMemory; - - p -= 1; #ifdef DEBUG ReleaseAllocHashEntry(pMemory); #endif - if (*p == HEAP) - { - _SystemCallFree(p); - } - else if (*p == MMAP) - { - _SystemCallMunmap(p); - } -#ifdef DEBUG - else - { - UtilPanic(SHOULD_NOT_GET_HERE, - NULL, NULL, NULL, NULL, - __FILE__, __LINE__); - } -#endif + _SystemCallFree(pMemory); } |
