8 #ifndef OM_ALLOC_PRIVATE_H 9 #define OM_ALLOC_PRIVATE_H 30 #define SIZEOF_OM_BIN_PAGE_HEADER (5*SIZEOF_VOIDP + SIZEOF_LONG) 31 #define SIZEOF_OM_BIN_PAGE (SIZEOF_SYSTEM_PAGE - SIZEOF_OM_BIN_PAGE_HEADER) 64 #define omGetTopBinOfPage(page) \ 65 ((omBin) ( ((unsigned long) ((page)->bin_sticky)) & ~((unsigned long)SIZEOF_VOIDP - 1))) 66 #define omGetStickyOfPage(page) \ 67 (((unsigned long) ((page)->bin_sticky)) & ((unsigned long)SIZEOF_VOIDP-1)) 68 #define omSetTopBinOfPage(page, bin) \ 69 (page)->bin_sticky= (void*)((unsigned long)bin + omGetStickyOfPage(page)) 70 #define omSetStickyOfPage(page, sticky) \ 71 (page)->bin_sticky = (void*)(((unsigned long)sticky & ((unsigned long)SIZEOF_VOIDP-1)) + \ 72 (unsigned long)omGetTopBinOfPage(page)) 73 #define omSetTopBinAndStickyOfPage(page, bin, sticky) \ 74 (page)->bin_sticky= (void*)(((unsigned long)sticky & (SIZEOF_VOIDP-1)) \ 77 #define omGetTopBinOfAddr(addr) \ 78 omGetTopBinOfPage(((omBinPage) omGetPageOfAddr(addr))) 79 #define omGetBinOfAddr(addr) omGetBinOfPage(omGetBinPageOfAddr(addr)) 81 #ifndef OM_GENERATE_INC 84 #ifdef OM_ALIGNMENT_NEEDS_WORK 85 extern omBin om_Size2AlignedBin[];
93 #ifdef OM_INTERNAL_DEBUG 96 #define omSizeOfBinAddr(addr) _omSizeOfBinAddr(addr) 99 #define omSizeWOfBin(bin_ptr) ((bin_ptr)->sizeW) 101 #define _omSizeOfBinAddr(addr) ((omSizeWOfBinAddr(addr)) << LOG_SIZEOF_LONG) 102 #define omSizeWOfBinAddr(addr) ((omGetTopBinOfAddr(addr))->sizeW) 114 #define __omTypeAllocFromNonEmptyPage(type, addr, page) \ 117 ((page)->used_blocks)++; \ 118 addr = (type)((page)->current); \ 119 (page)->current = *((void**) (page)->current); \ 123 #define __omFreeToPage(addr, page) \ 126 if ((page)->used_blocks > 0L) \ 128 *((void**) (addr)) = (page)->current; \ 129 ((page)->used_blocks)--; \ 130 (page)->current = (addr); \ 134 omFreeToPageFault(page, addr); \ 142 #define __omTypeAllocBin(type, addr, bin) \ 145 register omBinPage __om_page = (bin)->current_page; \ 146 if (__om_page->current != NULL) \ 147 __omTypeAllocFromNonEmptyPage(type, addr, __om_page); \ 149 addr = (type) omAllocBinFromFullPage(bin); \ 153 #define __omTypeAlloc0Bin(type, addr, bin) \ 156 __omTypeAllocBin(type, addr, bin); \ 157 omMemsetW(addr, 0, (bin)->sizeW); \ 162 #define __omFreeBinAddr(addr) \ 165 register void* __om_addr = (void*) (addr); \ 166 register omBinPage __om_page = omGetBinPageOfAddr(__om_addr); \ 167 __omFreeToPage(__om_addr, __om_page); \ 171 #define __omTypeReallocBin(old_addr, old_bin, new_type, new_addr, new_bin) \ 174 if (old_bin != new_bin) \ 176 size_t old_sizeW = (omIsNormalBinPageAddr(old_addr) ? old_bin->sizeW : omSizeWOfAddr(old_addr)); \ 177 __omTypeAllocBin(new_type, new_addr, new_bin); \ 178 omMemcpyW(new_addr, old_addr, (new_bin->sizeW > old_sizeW ? old_sizeW : new_bin->sizeW)); \ 179 __omFreeBinAddr(old_addr); \ 183 new_addr = (new_type) old_addr; \ 189 #define __omTypeRealloc0Bin(old_addr, old_bin, new_type, new_addr, new_bin) \ 192 if (old_bin != new_bin) \ 194 size_t old_sizeW = (omIsNormalBinPageAddr(old_addr) ? old_bin->sizeW : omSizeWOfAddr(old_addr)); \ 195 __omTypeAllocBin(new_type, new_addr, new_bin); \ 196 omMemcpyW(new_addr, old_addr, (new_bin->sizeW > old_sizeW ? old_sizeW : new_bin->sizeW)); \ 197 if (new_bin->sizeW > old_sizeW) \ 198 omMemsetW((void**)new_addr + old_sizeW, 0, new_bin->sizeW - old_sizeW); \ 199 __omFreeBinAddr(old_addr); \ 203 new_addr = (new_type) old_addr; \ 210 #define omSmallSize2Bin(size) om_Size2Bin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT] 212 #define __omTypeAlloc(type, addr, size) \ 215 size_t __size = size; \ 216 if (__size <= OM_MAX_BLOCK_SIZE) \ 218 omBin __om_bin = omSmallSize2Bin(__size); \ 219 __omTypeAllocBin(type, addr, __om_bin); \ 223 addr = (type) omAllocLarge(__size); \ 228 #define __omTypeAlloc0(type, addr, size) \ 231 size_t __size = size; \ 232 if (__size <= OM_MAX_BLOCK_SIZE) \ 234 omBin __om_bin = omSmallSize2Bin(__size); \ 235 __omTypeAlloc0Bin(type, addr, __om_bin); \ 239 addr = (type) omAlloc0Large(__size); \ 244 #ifdef OM_ALIGNMENT_NEEDS_WORK 245 #define omSmallSize2AlignedBin(size) om_Size2AlignedBin[((size) -1)>>LOG_SIZEOF_OM_ALIGNMENT] 247 #define __omTypeAllocAligned(type, addr, size) \ 250 size_t __size = size; \ 251 if (__size <= OM_MAX_BLOCK_SIZE) \ 253 omBin __om_bin = omSmallSize2AlignedBin(__size); \ 254 __omTypeAllocBin(type, addr, __om_bin); \ 258 addr = (type) omAllocLarge(__size); \ 263 #define __omTypeAlloc0Aligned(type, addr, size) \ 266 size_t __size = size; \ 267 if (__size <= OM_MAX_BLOCK_SIZE) \ 269 omBin __om_bin = omSmallSize2AlignedBin(__size); \ 270 __omTypeAlloc0Bin(type, addr, __om_bin); \ 274 addr = (type) omAlloc0Large(__size); \ 279 #define __omTypeAllocAligned __omTypeAlloc 280 #define __omTypeAlloc0Aligned __omTypeAlloc0 283 #define __omFreeSize(addr, size) \ 286 if ((size <= OM_MAX_BLOCK_SIZE) || omIsBinPageAddr(addr)) \ 288 __omFreeBinAddr(addr); \ 297 #define __omFree(addr) \ 300 if (omIsBinPageAddr(addr)) \ 302 __omFreeBinAddr(addr); \ 313 #define ___omTypeRealloc(old_addr, new_type, new_addr, new_size, SIZE_2_BIN, REALLOC_BIN, flags) \ 316 size_t __new_size = new_size; \ 317 if (__new_size <= OM_MAX_BLOCK_SIZE && omIsBinPageAddr(old_addr)) \ 319 omBin __old_bin = omGetBinOfAddr(old_addr); \ 320 omBin __new_bin = SIZE_2_BIN(__new_size); \ 321 REALLOC_BIN(old_addr, __old_bin, new_type, new_addr, __new_bin); \ 325 new_addr = (new_type) omDoRealloc(old_addr, __new_size, flags); \ 330 #define ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, SIZE_2_BIN, REALLOC_BIN, flags) \ 333 size_t __new_size = new_size; \ 334 if (__new_size <= OM_MAX_BLOCK_SIZE && old_size <= OM_MAX_BLOCK_SIZE) \ 336 omBin __old_bin = omGetBinOfAddr(old_addr); \ 337 omBin __new_bin = SIZE_2_BIN(__new_size); \ 338 REALLOC_BIN(old_addr, __old_bin, new_type, new_addr, __new_bin); \ 342 new_addr = (new_type) omDoRealloc(old_addr, __new_size, flags); \ 347 #define __omTypeRealloc(old_addr, new_type, new_addr, new_size) \ 348 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeReallocBin, 0) 349 #define __omTypeRealloc0(old_addr, new_type, new_addr, new_size) \ 350 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeRealloc0Bin, 1) 351 #define __omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size) \ 352 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeReallocBin, 0) 353 #define __omTypeRealloc0Size(old_addr, old_size, new_type, new_addr, new_size) \ 354 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2Bin, __omTypeRealloc0Bin, 1) 356 #ifdef OM_ALIGNMENT_NEEDS_WORK 357 #define __omTypeReallocAligned(old_addr, new_type, new_addr, new_size) \ 358 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeReallocBin, 2) 359 #define __omTypeRealloc0Aligned(old_addr, new_type, new_addr, new_size) \ 360 ___omTypeRealloc(old_addr, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeRealloc0Bin, 3) 361 #define __omTypeReallocAlignedSize(old_addr, old_size, new_type, new_addr, new_size) \ 362 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeReallocBin, 2) 363 #define __omTypeRealloc0AlignedSize(old_addr, old_size, new_type, new_addr, new_size) \ 364 ___omTypeReallocSize(old_addr, old_size, new_type, new_addr, new_size, omSmallSize2AlignedBin, __omTypeRealloc0Bin, 3) 366 #define __omTypeReallocAligned __omTypeRealloc 367 #define __omTypeRealloc0Aligned __omTypeRealloc0 368 #define __omTypeReallocAlignedSize __omTypeReallocSize 369 #define __omTypeRealloc0AlignedSize __omTypeRealloc0Size
void omFreeToPageFault(omBinPage page, void *addr)
void * omAllocBinFromFullPage(omBin bin)
omBinPage_t om_ZeroPage[]
void * omDoRealloc(void *old_addr, size_t new_size, int flags)
omBinPageRegion_t * omBinPageRegion
#define omSizeOfBinAddr(addr)
int status int void size_t count int const void size_t count const char int flags