59 lines
2.0 KiB
C
59 lines
2.0 KiB
C
|
|
// hakmem_syscall.h - System call wrapper (bypasses LD_PRELOAD)
|
||
|
|
//
|
||
|
|
// Purpose: Direct libc access via dlsym to avoid LD_PRELOAD recursion
|
||
|
|
//
|
||
|
|
// Box Theory - Layer 3 (Syscall Layer):
|
||
|
|
// This module implements "Box 3" in the 3-layer architecture:
|
||
|
|
// Box 1 (API) → Box 2 (Core) → Box 3 (Syscall - THIS MODULE)
|
||
|
|
// ↑ Bypasses LD_PRELOAD!
|
||
|
|
//
|
||
|
|
// Design Philosophy:
|
||
|
|
// - Use dlsym(RTLD_NEXT, "malloc") to get real libc functions
|
||
|
|
// - Completely bypass LD_PRELOAD wrappers (no recursion possible)
|
||
|
|
// - No guard needed (g_in_internal_malloc removed!)
|
||
|
|
// - Called ONLY by Box 2 (hakmem core) for internal allocations
|
||
|
|
//
|
||
|
|
// Usage:
|
||
|
|
// - Slab/Page allocation in Tiny/Mid/Large pools
|
||
|
|
// - Learner policy allocation
|
||
|
|
// - Any hakmem internal structure
|
||
|
|
//
|
||
|
|
// Safety:
|
||
|
|
// - Must call hkm_syscall_init() BEFORE any allocation
|
||
|
|
// - Will abort() if dlsym fails
|
||
|
|
//
|
||
|
|
// License: MIT
|
||
|
|
// Date: 2025-10-24
|
||
|
|
|
||
|
|
#ifndef HAKMEM_SYSCALL_H
|
||
|
|
#define HAKMEM_SYSCALL_H
|
||
|
|
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
// Initialize syscall layer (dlsym to get real libc functions)
|
||
|
|
// Must be called from hak_init() before any allocation
|
||
|
|
// This function is idempotent (safe to call multiple times)
|
||
|
|
void hkm_syscall_init(void);
|
||
|
|
|
||
|
|
// Direct libc malloc (bypasses LD_PRELOAD completely)
|
||
|
|
// Returns: Pointer to allocated memory, or NULL on failure
|
||
|
|
// Usage: Internal allocations ONLY (Slab/Page/Learner)
|
||
|
|
//
|
||
|
|
// Example:
|
||
|
|
// TinySlab* slab = (TinySlab*)hkm_libc_malloc(sizeof(TinySlab));
|
||
|
|
void* hkm_libc_malloc(size_t size);
|
||
|
|
|
||
|
|
// Direct libc calloc (bypasses LD_PRELOAD completely)
|
||
|
|
// Returns: Pointer to zero-initialized memory, or NULL on failure
|
||
|
|
void* hkm_libc_calloc(size_t nmemb, size_t size);
|
||
|
|
|
||
|
|
// Direct libc free (bypasses LD_PRELOAD completely)
|
||
|
|
// Args: ptr - pointer to free (can be NULL)
|
||
|
|
void hkm_libc_free(void* ptr);
|
||
|
|
|
||
|
|
// Direct libc realloc (bypasses LD_PRELOAD completely)
|
||
|
|
// Returns: Pointer to reallocated memory, or NULL on failure
|
||
|
|
void* hkm_libc_realloc(void* ptr, size_t size);
|
||
|
|
|
||
|
|
#endif // HAKMEM_SYSCALL_H
|