8#ifndef OM_ALLOC_PRIVATE_H
9#define OM_ALLOC_PRIVATE_H
31#define SIZEOF_OM_BIN_PAGE_HEADER (5*SIZEOF_VOIDP + SIZEOF_LONG)
32#define SIZEOF_OM_BIN_PAGE (SIZEOF_SYSTEM_PAGE - SIZEOF_OM_BIN_PAGE_HEADER)
65#define omGetTopBinOfPage(page) \
66 ((omBin) ( ((unsigned long) ((page)->bin_sticky)) & ~((unsigned long)SIZEOF_VOIDP - 1)))
67#define omGetStickyOfPage(page) \
68 (((unsigned long) ((page)->bin_sticky)) & ((unsigned long)SIZEOF_VOIDP-1))
69#define omSetTopBinOfPage(page, bin) \
70 (page)->bin_sticky= (void*)((unsigned long)bin + omGetStickyOfPage(page))
71#define omSetStickyOfPage(page, sticky) \
72 (page)->bin_sticky = (void*)(((unsigned long)sticky & ((unsigned long)SIZEOF_VOIDP-1)) + \
73 (unsigned long)omGetTopBinOfPage(page))
74#define omSetTopBinAndStickyOfPage(page, bin, sticky) \
75 (page)->bin_sticky= (void*)(((unsigned long)sticky & (SIZEOF_VOIDP-1)) \
78#define omGetTopBinOfAddr(addr) \
79 omGetTopBinOfPage(((omBinPage) omGetPageOfAddr(addr)))
80#define omGetBinOfAddr(addr) omGetBinOfPage(omGetBinPageOfAddr(addr))
82#ifndef OM_GENERATE_INC
85#ifdef OM_ALIGNMENT_NEEDS_WORK
86extern omBin om_Size2AlignedBin[];
94#ifdef OM_INTERNAL_DEBUG
97#define omSizeOfBinAddr(addr) _omSizeOfBinAddr(addr)
100#define omSizeWOfBin(bin_ptr) ((bin_ptr)->sizeW)
102#define _omSizeOfBinAddr(addr) ((omSizeWOfBinAddr(addr)) << LOG_SIZEOF_LONG)
103#define omSizeWOfBinAddr(addr) ((omGetTopBinOfAddr(addr))->sizeW)
115#define __omTypeAllocFromNonEmptyPage(type, addr, page) \
118 ((page)->used_blocks)++; \
119 addr = (type)((page)->current); \
120 (page)->current = *((void**) (page)->current); \
124#define __omFreeToPage(addr, page) \
127 if ((page)->used_blocks > 0L) \
129 *((void**) (addr)) = (page)->current; \
130 ((page)->used_blocks)--; \
131 (page)->current = (addr); \
135 omFreeToPageFault(page, addr); \
143#define __omTypeAllocBin(type, addr, bin) \
146 REGISTER omBinPage __om_page = (bin)->current_page; \
147 if (__om_page->current != NULL) \
148 __omTypeAllocFromNonEmptyPage(type, addr, __om_page); \
150 addr = (type) omAllocBinFromFullPage(bin); \
154#define __omTypeAlloc0Bin(type, addr, bin) \
157 __omTypeAllocBin(type, addr, bin); \
158 omMemsetW(addr, 0, (bin)->sizeW); \
163#define __omFreeBinAddr(addr) \
166 REGISTER void* __om_addr = (void*) (addr); \
167 REGISTER omBinPage __om_page = omGetBinPageOfAddr(__om_addr); \
168 __omFreeToPage(__om_addr, __om_page); \
172#define __omTypeReallocBin(old_addr, old_bin, new_type, new_addr, new_bin) \
175 if (old_bin != new_bin) \
177 size_t old_sizeW = (omIsNormalBinPageAddr(old_addr) ? old_bin->sizeW : omSizeWOfAddr(old_addr)); \
178 __omTypeAllocBin(new_type, new_addr, new_bin); \
179 omMemcpyW(new_addr, old_addr, (new_bin->sizeW > old_sizeW ? old_sizeW : new_bin->sizeW)); \
180 __omFreeBinAddr(old_addr); \
184 new_addr = (new_type) old_addr; \
190#define __omTypeRealloc0Bin(old_addr, old_bin, new_type, new_addr, new_bin) \
193 if (old_bin != new_bin) \
195 size_t old_sizeW = (omIsNormalBinPageAddr(old_addr) ? old_bin->sizeW : omSizeWOfAddr(old_addr)); \
196 __omTypeAllocBin(new_type, new_addr, new_bin); \
197 omMemcpyW(new_addr, old_addr, (new_bin->sizeW > old_sizeW ? old_sizeW : new_bin->sizeW)); \
198 if (new_bin->sizeW > old_sizeW) \
199 omMemsetW((void**)new_addr + old_sizeW, 0, new_bin->sizeW - old_sizeW); \
200 __omFreeBinAddr(old_addr); \
204 new_addr = (new_type) old_addr; \
211#define omSmallSize2Bin(size) om_Size2Bin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT]
213#define __omTypeAlloc(type, addr, size) \
216 size_t __size = size; \
217 if (__size <= OM_MAX_BLOCK_SIZE) \
219 omBin __om_bin = omSmallSize2Bin(__size); \
220 __omTypeAllocBin(type, addr, __om_bin); \
224 addr = (type) omAllocLarge(__size); \
229#define __omTypeAlloc0(type, addr, size) \
232 size_t __size = size; \
233 if (__size <= OM_MAX_BLOCK_SIZE) \
235 omBin __om_bin = omSmallSize2Bin(__size); \
236 __omTypeAlloc0Bin(type, addr, __om_bin); \
240 addr = (type) omAlloc0Large(__size); \
245#ifdef OM_ALIGNMENT_NEEDS_WORK
246#define omSmallSize2AlignedBin(size) om_Size2AlignedBin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT]
248#define __omTypeAllocAligned(type, addr, size) \
251 size_t __size = size; \
252 if (__size <= OM_MAX_BLOCK_SIZE) \
254 omBin __om_bin = omSmallSize2AlignedBin(__size); \
255 __omTypeAllocBin(type, addr, __om_bin); \
259 addr = (type) omAllocLarge(__size); \
264#define __omTypeAlloc0Aligned(type, addr, size) \
267 size_t __size = size; \
268 if (__size <= OM_MAX_BLOCK_SIZE) \
270 omBin __om_bin = omSmallSize2AlignedBin(__size); \
271 __omTypeAlloc0Bin(type, addr, __om_bin); \
275 addr = (type) omAlloc0Large(__size); \
280#define __omTypeAllocAligned __omTypeAlloc
281#define __omTypeAlloc0Aligned __omTypeAlloc0
284#define __omFreeSize(addr, size) \
287 if ((size <= OM_MAX_BLOCK_SIZE) || omIsBinPageAddr(addr)) \
289 __omFreeBinAddr(addr); \
298#define __omFree(addr) \
301 if (omIsBinPageAddr(addr)) \
303 __omFreeBinAddr(addr); \
314#define ___omTypeRealloc(old_addr, new_type, new_addr, new_size, SIZE_2_BIN, REALLOC_BIN, flags) \
317 size_t __new_size = new_size; \
318 if (__new_size <= OM_MAX_BLOCK_SIZE && omIsBinPageAddr(old_addr)) \
320 omBin __old_bin = omGetBinOfAddr(old_addr); \
321 omBin __new_bin = SIZE_2_BIN(__new_size); \
322 REALLOC_BIN(old_addr, __old_bin, new_type, new_addr, __new_bin); \
326 new_addr = (new_type) omDoRealloc(old_addr, __new_size, flags); \
331#define ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, SIZE_2_BIN, REALLOC_BIN, flags) \
334 size_t __new_size = new_size; \
335 if (__new_size <= OM_MAX_BLOCK_SIZE && old_size <= OM_MAX_BLOCK_SIZE) \
337 omBin __old_bin = omGetBinOfAddr(old_addr); \
338 omBin __new_bin = SIZE_2_BIN(__new_size); \
339 REALLOC_BIN(old_addr, __old_bin, new_type, new_addr, __new_bin); \
343 new_addr = (new_type) omDoRealloc(old_addr, __new_size, flags); \
348#define __omTypeRealloc(old_addr, new_type, new_addr, new_size) \
349 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeReallocBin, 0)
350#define __omTypeRealloc0(old_addr, new_type, new_addr, new_size) \
351 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeRealloc0Bin, 1)
352#define __omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size) \
353 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeReallocBin, 0)
354#define __omTypeRealloc0Size(old_addr, old_size, new_type, new_addr, new_size) \
355 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeRealloc0Bin, 1)
357#ifdef OM_ALIGNMENT_NEEDS_WORK
358#define __omTypeReallocAligned(old_addr, new_type, new_addr, new_size) \
359 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeReallocBin, 2)
360#define __omTypeRealloc0Aligned(old_addr, new_type, new_addr, new_size) \
361 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeRealloc0Bin, 3)
362#define __omTypeReallocAlignedSize(old_addr, old_size, new_type, new_addr, new_size) \
363 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeReallocBin, 2)
364#define __omTypeRealloc0AlignedSize(old_addr, old_size, new_type, new_addr, new_size) \
365 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeRealloc0Bin, 3)
367#define __omTypeReallocAligned __omTypeRealloc
368#define __omTypeRealloc0Aligned __omTypeRealloc0
369#define __omTypeReallocAlignedSize __omTypeReallocSize
370#define __omTypeRealloc0AlignedSize __omTypeRealloc0Size
omBinPage_t om_ZeroPage[]
void * omAllocBinFromFullPage(omBin bin)
void * omDoRealloc(void *old_addr, size_t new_size, int flags)
#define omSizeOfBinAddr(addr)
void omFreeToPageFault(omBinPage page, void *addr)
omBinPageRegion_t * omBinPageRegion
int status int void size_t count int const void size_t count const char int flags