#include <unistd.h>
#include <limits.h>
#include "omConfig.h"
#include "omDefaultConfig.h"
#include "omMalloc.h"
#include "omalloc.h"
#include <string.h>
Go to the source code of this file.
◆ _omSizeOfLargeAddr
#define _omSizeOfLargeAddr |
( |
|
addr | ) |
(*((size_t*) ((char*) addr - SIZEOF_STRICT_ALIGNMENT))) |
◆ OM_ALIGN_PAGE
#define OM_ALIGN_PAGE |
( |
|
addr | ) |
( ((long)addr + (SIZEOF_SYSTEM_PAGE -1)) & ~(SIZEOF_SYSTEM_PAGE - 1)) |
◆ OM_ALLOC_SYSTEM_C
#define OM_ALLOC_SYSTEM_C |
◆ OM_FREE_TO_SYSTEM
◆ OM_MALLOC_FROM_SYSTEM
◆ OM_REALLOC_FROM_SYSTEM
◆ OM_VALLOC_FROM_SYSTEM
◆ OM_VFREE_TO_SYSTEM
◆ _omVallocFromSystem()
void * _omVallocFromSystem |
( |
size_t |
size, |
|
|
int |
fail |
|
) |
| |
Definition at line 318 of file omAllocSystem.c.
319{
322 {
323 OM_MEMORY_LOW_HOOK();
326 {
327 if (fail)
return NULL;
328 else
329 {
330 OM_OUT_OF_MEMORY_HOOK();
331
333 exit(1);
334 }
335 }
336 }
337
338#ifndef OM_NDEBUG
343#endif
344
348 {
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;
353#endif
354#if defined(HAVE_SBRK) && !defined(OM_HAVE_VALLOC_MMAP) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
357 {
360 +
om_Info.CurrentBytesFromValloc);
361 }
362#endif
363 }
364 OM_VALLOC_HOOK(
size);
365 return page;
366}
#define OM_VALLOC_FROM_SYSTEM
#define omIsAddrPageAligned(addr)
unsigned long om_SbrkInit
◆ omAlloc0Large()
void * omAlloc0Large |
( |
size_t |
size | ) |
|
Definition at line 82 of file omAllocSystem.c.
83{
85 memset(addr, 0,
size);
86 return addr;
87}
void * omAllocLarge(size_t size)
◆ omAllocFromSystem()
void * omAllocFromSystem |
( |
size_t |
size | ) |
|
Definition at line 194 of file omAllocSystem.c.
195{
196 void* ptr;
197
200 {
201 OM_MEMORY_LOW_HOOK();
204 {
205 OM_OUT_OF_MEMORY_HOOK();
206 exit(1);
207 }
208 }
209#if defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE)
211#else
213#endif
214#ifndef OM_NDEBUG
219#endif
220
223 {
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;
228#endif
229#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
232#ifndef OM_HAVE_VALLOC_MMAP
233 +
om_Info.CurrentBytesFromValloc
234#endif
236 {
238 }
239#endif
240 }
241 OM_MALLOC_HOOK(
size);
242 return ptr;
243}
size_t omSizeOfAddr(const void *addr)
#define _omSizeOfLargeAddr(addr)
#define OM_MALLOC_FROM_SYSTEM
◆ omAllocLarge()
void * omAllocLarge |
( |
size_t |
size | ) |
|
Definition at line 48 of file omAllocSystem.c.
49{
50 char* addr;
53 *((
size_t*) addr) =
size;
54 return (void *)(addr + SIZEOF_STRICT_ALIGNMENT);
55}
void * omAllocFromSystem(size_t size)
◆ omEmulateValloc()
void * omEmulateValloc |
( |
size_t |
size | ) |
|
Definition at line 159 of file omAllocSystem.c.
160{
161 void* addr;
162 size_t padding = SIZEOF_VOIDP;
164 while (1)
165 {
168 if ((
OM_ALIGN_PAGE(addr) + SIZEOF_VOIDP) - (
long) addr <= padding)
169 {
171 *((
void**) ((
void*) ret_addr +
size)) = addr;
172 return ret_addr;
173 }
174 else
175 {
177 padding = padding << 1;
178 }
179 }
180}
#define OM_ALIGN_PAGE(addr)
#define OM_FREE_TO_SYSTEM
◆ omEmulateVfree()
void omEmulateVfree |
( |
void * |
addr, |
|
|
size_t |
size |
|
) |
| |
◆ omFreeLarge()
void omFreeLarge |
( |
void * |
addr | ) |
|
Definition at line 73 of file omAllocSystem.c.
74{
75 char* _addr = (char *)addr - SIZEOF_STRICT_ALIGNMENT;
77}
void omFreeSizeToSystem(void *addr, size_t size)
◆ omFreeSizeToSystem()
void omFreeSizeToSystem |
( |
void * |
addr, |
|
|
size_t |
size |
|
) |
| |
◆ omFreeToSystem()
void omFreeToSystem |
( |
void * |
addr | ) |
|
◆ omRealloc0Large()
void * omRealloc0Large |
( |
void * |
old_addr, |
|
|
size_t |
new_size |
|
) |
| |
Definition at line 89 of file omAllocSystem.c.
90{
91 size_t old_size;
92 char* new_addr;
93
95
97
100 if (new_size > old_size)
101 memset(new_addr + old_size, 0, new_size - old_size);
102 return (void *)new_addr;
103}
size_t omSizeOfLargeAddr(void *addr)
void * omReallocLarge(void *old_addr, size_t new_size)
#define omIsBinPageAddr(addr)
◆ omReallocFromSystem()
void * omReallocFromSystem |
( |
void * |
addr, |
|
|
size_t |
newsize |
|
) |
| |
Definition at line 245 of file omAllocSystem.c.
246{
248}
void * omReallocSizeFromSystem(void *addr, size_t oldsize, size_t newsize)
◆ omReallocLarge()
void * omReallocLarge |
( |
void * |
old_addr, |
|
|
size_t |
new_size |
|
) |
| |
Definition at line 57 of file omAllocSystem.c.
58{
59 char* _old_addr;
60 char* new_addr;
61
63
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);
71}
◆ omReallocSizeFromSystem()
void * omReallocSizeFromSystem |
( |
void * |
addr, |
|
|
size_t |
oldsize, |
|
|
size_t |
newsize |
|
) |
| |
Definition at line 250 of file omAllocSystem.c.
251{
253
254
257 {
258 OM_MEMORY_LOW_HOOK();
259
260
261
264 {
265 OM_OUT_OF_MEMORY_HOOK();
266
268 exit(1);
269 }
270 }
271
272
273#ifndef OM_NDEBUG
278#endif
279
280 om_Info.CurrentBytesFromMalloc += (long) newsize - (
long) oldsize;
281
282
284 {
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;
289#endif
290#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
292#ifndef OM_HAVE_VALLOC_MMAP
293 +
om_Info.CurrentBytesFromValloc
294#endif
296 {
298 }
299#endif
300 }
301
302 OM_REALLOC_HOOK(oldsize, newsize);
304}
#define OM_REALLOC_FROM_SYSTEM
◆ omSizeOfAddr()
size_t omSizeOfAddr |
( |
const void * |
addr | ) |
|
Definition at line 110 of file omAllocSystem.c.
111{
112
113
115#ifdef OM_HAVE_TRACK
117#else
119#endif
121}
#define omSizeOfBinAddr(addr)
#define omIsBinAddrTrackAddr(addr)
◆ omSizeOfLargeAddr()
size_t omSizeOfLargeAddr |
( |
void * |
addr | ) |
|
◆ omSizeWOfAddr()
size_t omSizeWOfAddr |
( |
void * |
addr | ) |
|
Definition at line 123 of file omAllocSystem.c.
124{
125
127#ifdef OM_HAVE_TRACK
129#else
131#endif
133}
#define omSizeWOfBinAddr(addr)
◆ omVfreeToSystem()
void omVfreeToSystem |
( |
void * |
page, |
|
|
size_t |
size |
|
) |
| |