7#ifndef OM_ALLOC_SYSTEM_C
8#define OM_ALLOC_SYSTEM_C
17#include "omDefaultConfig.h"
23#define OM_MALLOC_FROM_SYSTEM OM_MALLOC_MALLOC
24#define OM_REALLOC_FROM_SYSTEM OM_MALLOC_REALLOC
25#define OM_FREE_TO_SYSTEM OM_MALLOC_FREE
34#if defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE)
38 #elif defined(HAVE_MALLOC_MALLOC_H)
39 #include <malloc/malloc.h>
43#if defined(HAVE_MALLOC_SIZE)
44 #define _omSizeOfLargeAddr(addr) (malloc_size(addr))
45#elif defined(HAVE_MALLOC_USABLE_SIZE)
46 #define _omSizeOfLargeAddr(addr) (malloc_usable_size(addr))
53 *((
size_t*) addr) =
size;
54 return (
void *)(addr + SIZEOF_STRICT_ALIGNMENT);
64 new_size = OM_ALIGN_SIZE(new_size);
65 _old_addr = (
char *)old_addr - SIZEOF_STRICT_ALIGNMENT;
67 *((
size_t*) _old_addr) + SIZEOF_STRICT_ALIGNMENT,
68 new_size + SIZEOF_STRICT_ALIGNMENT);
69 *((
size_t*) new_addr) = new_size;
70 return (
void *)(new_addr + SIZEOF_STRICT_ALIGNMENT);
75 char* _addr = (
char *)addr - SIZEOF_STRICT_ALIGNMENT;
79#define _omSizeOfLargeAddr(addr) (*((size_t*) ((char*) addr - SIZEOF_STRICT_ALIGNMENT)))
85 memset(addr, 0,
size);
100 if (new_size > old_size)
101 memset(new_addr + old_size, 0, new_size - old_size);
102 return (
void *)new_addr;
140#ifdef OM_HAVE_VALLOC_MMAP
144#define OM_VALLOC_FROM_SYSTEM omVallocMmap
145#define OM_VFREE_TO_SYSTEM omVfreeMmap
147#elif defined(OM_HAVE_VALLOC_MALLOC)
149#define OM_VALLOC_FROM_SYSTEM OM_MALLOC_VALLOC
150#define OM_VFREE_TO_SYSTEM OM_MALLOC_VFREE
154#define OM_VALLOC_FROM_SYSTEM omEmulateValloc
155#define OM_VFREE_TO_SYSTEM omEmulateVfree
157#define OM_ALIGN_PAGE(addr) ( ((long)addr + (SIZEOF_SYSTEM_PAGE -1)) & ~(SIZEOF_SYSTEM_PAGE - 1))
162 size_t padding = SIZEOF_VOIDP;
168 if ((
OM_ALIGN_PAGE(addr) + SIZEOF_VOIDP) - (
long) addr <= padding)
171 *((
void**) ((
void*) ret_addr +
size)) = addr;
177 padding = padding << 1;
201 OM_MEMORY_LOW_HOOK();
205 OM_OUT_OF_MEMORY_HOOK();
209#if defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE)
225#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
226 if (
om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM >
om_Info.MaxBytesSystem)
227 om_Info.MaxBytesSystem =
om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
229#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
232#ifndef OM_HAVE_VALLOC_MMAP
233 +
om_Info.CurrentBytesFromValloc
241 OM_MALLOC_HOOK(
size);
258 OM_MEMORY_LOW_HOOK();
265 OM_OUT_OF_MEMORY_HOOK();
280 om_Info.CurrentBytesFromMalloc += (long) newsize - (
long) oldsize;
286#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
287 if (
om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM >
om_Info.MaxBytesSystem)
288 om_Info.MaxBytesSystem =
om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
290#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
292#ifndef OM_HAVE_VALLOC_MMAP
293 +
om_Info.CurrentBytesFromValloc
302 OM_REALLOC_HOOK(oldsize, newsize);
323 OM_MEMORY_LOW_HOOK();
327 if (fail)
return NULL;
330 OM_OUT_OF_MEMORY_HOOK();
350#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
351 if (
om_Info.MaxBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM >
om_Info.MaxBytesSystem)
352 om_Info.MaxBytesSystem =
om_Info.MaxBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
354#if defined(HAVE_SBRK) && !defined(OM_HAVE_VALLOC_MMAP) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
360 +
om_Info.CurrentBytesFromValloc);
364 OM_VALLOC_HOOK(
size);
#define omSizeOfBinAddr(addr)
#define omSizeWOfBinAddr(addr)
void * _omVallocFromSystem(size_t size, int fail)
void * omAllocFromSystem(size_t size)
void omEmulateVfree(void *addr, size_t size)
void * omReallocFromSystem(void *addr, size_t newsize)
void * omEmulateValloc(size_t size)
void omVfreeToSystem(void *page, size_t size)
size_t omSizeOfLargeAddr(void *addr)
#define OM_REALLOC_FROM_SYSTEM
void omFreeLarge(void *addr)
void * omRealloc0Large(void *old_addr, size_t new_size)
void omFreeSizeToSystem(void *addr, size_t size)
#define OM_ALIGN_PAGE(addr)
#define OM_VFREE_TO_SYSTEM
void * omReallocLarge(void *old_addr, size_t new_size)
size_t omSizeOfAddr(const void *addr)
#define OM_FREE_TO_SYSTEM
void omFreeToSystem(void *addr)
void * omAllocLarge(size_t size)
#define _omSizeOfLargeAddr(addr)
void * omReallocSizeFromSystem(void *addr, size_t oldsize, size_t newsize)
#define OM_MALLOC_FROM_SYSTEM
#define OM_VALLOC_FROM_SYSTEM
void * omAlloc0Large(size_t size)
#define omIsBinPageAddr(addr)
#define omIsAddrPageAligned(addr)
#define omIsBinAddrTrackAddr(addr)
unsigned long om_SbrkInit