Loading...
Searching...
No Matches
omAllocSystem.c File Reference
`#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.

## Macros

#define | OM_ALLOC_SYSTEM_C
#define | OM_MALLOC_FROM_SYSTEM OM_MALLOC_MALLOC
#define | OM_REALLOC_FROM_SYSTEM OM_MALLOC_REALLOC
#define | OM_FREE_TO_SYSTEM OM_MALLOC_FREE
#define | _omSizeOfLargeAddr(addr)
#define | OM_VALLOC_FROM_SYSTEM omEmulateValloc
#define | OM_VFREE_TO_SYSTEM omEmulateVfree
#define | OM_ALIGN_PAGE(addr)

## Functions

void * | omAllocLarge (size_t size)
void * | omReallocLarge (void *old_addr, size_t new_size)
void | omFreeLarge (void *addr)
void * | omAlloc0Large (size_t size)
void * | omRealloc0Large (void *old_addr, size_t new_size)
size_t | omSizeOfLargeAddr (void *addr)
size_t | omSizeOfAddr (const void *addr)
size_t | omSizeWOfAddr (void *addr)
void * | omEmulateValloc (size_t size)
void | omEmulateVfree (void *addr, size_t size)
void * | omAllocFromSystem (size_t size)
void * | omReallocFromSystem (void *addr, size_t newsize)
void * | omReallocSizeFromSystem (void *addr, size_t oldsize, size_t newsize)
void | omFreeToSystem (void *addr)
void | omFreeSizeToSystem (void *addr, size_t size)
void * | _omVallocFromSystem (size_t size, int fail)
void | omVfreeToSystem (void *page, size_t size)

## Macro Definition Documentation

## _omSizeOfLargeAddr

#define _omSizeOfLargeAddr | ( |  | addr | ) |

Value:
(*((size_t*) ((char*) addr - SIZEOF_STRICT_ALIGNMENT)))

Definition at line 79 of file omAllocSystem.c.

## OM_ALIGN_PAGE

#define OM_ALIGN_PAGE | ( |  | addr | ) |

Value:
( ((long)addr + (SIZEOF_SYSTEM_PAGE -1)) & ~(SIZEOF_SYSTEM_PAGE - 1))

Definition at line 157 of file omAllocSystem.c.

## OM_ALLOC_SYSTEM_C

#define OM_ALLOC_SYSTEM_C

Definition at line 8 of file omAllocSystem.c.

## OM_FREE_TO_SYSTEM

#define OM_FREE_TO_SYSTEM OM_MALLOC_FREE

Definition at line 25 of file omAllocSystem.c.

## OM_MALLOC_FROM_SYSTEM

#define OM_MALLOC_FROM_SYSTEM OM_MALLOC_MALLOC

Definition at line 23 of file omAllocSystem.c.

## OM_REALLOC_FROM_SYSTEM

#define OM_REALLOC_FROM_SYSTEM OM_MALLOC_REALLOC

Definition at line 24 of file omAllocSystem.c.

## OM_VALLOC_FROM_SYSTEM

#define OM_VALLOC_FROM_SYSTEM omEmulateValloc

Definition at line 154 of file omAllocSystem.c.

## OM_VFREE_TO_SYSTEM

#define OM_VFREE_TO_SYSTEM omEmulateVfree

Definition at line 155 of file omAllocSystem.c.

## Function Documentation

## _omVallocFromSystem()

void * _omVallocFromSystem | ( | size_t | size,
|  | int | fail )

Definition at line 318 of file omAllocSystem.c.

{
void* page = OM_VALLOC_FROM_SYSTEM(size);
if (page == NULL)
{
OM_MEMORY_LOW_HOOK();
page = OM_VALLOC_FROM_SYSTEM(size);
if (page == NULL)
{
if (fail) return NULL;
else
{
OM_OUT_OF_MEMORY_HOOK();
/* should never get here */
omAssume(0);
exit(1);
}
}
}
#ifndef OM_NDEBUG
if (((unsigned long) page) + size > om_MaxAddr)
om_MaxAddr = ((unsigned long) page) + size;
if (((unsigned long) page) < om_MinAddr)
om_MinAddr = ((unsigned long) page);
#endif
omAssume(omIsAddrPageAligned(page));
om_Info.CurrentBytesFromValloc += size;
if (om_Info.CurrentBytesFromValloc > om_Info.MaxBytesFromValloc)
{
om_Info.MaxBytesFromValloc = om_Info.CurrentBytesFromValloc;
#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
if (om_Info.MaxBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM > om_Info.MaxBytesSystem)
om_Info.MaxBytesSystem = om_Info.MaxBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
#endif
#if defined(HAVE_SBRK) && !defined(OM_HAVE_VALLOC_MMAP) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
if (! om_SbrkInit) om_SbrkInit = (unsigned long) sbrk(0) - size;
if (om_Info.CurrentBytesFromMalloc + om_Info.CurrentBytesFromValloc > om_Info.MaxBytesSbrk)
{
om_Info.MaxBytesSbrk = (unsigned long) sbrk(0) - om_SbrkInit;
omAssume(om_Info.MaxBytesSbrk >= om_Info.CurrentBytesFromMalloc
+ om_Info.CurrentBytesFromValloc);
}
#endif
}
OM_VALLOC_HOOK(size);
return page;
}
size
int size(const CanonicalForm &f, const Variable &v)
int size ( const CanonicalForm & f, const Variable & v )
Definition cf_ops.cc:600
OM_VALLOC_FROM_SYSTEM
#define OM_VALLOC_FROM_SYSTEM
Definition omAllocSystem.c:154
omIsAddrPageAligned
#define omIsAddrPageAligned(addr)
Definition omBinPage.h:16
om_MaxAddr
unsigned long om_MaxAddr
Definition omDebugCheck.c:19
om_MinAddr
unsigned long om_MinAddr
Definition omDebugCheck.c:20
omAssume
#define omAssume(x)
Definition omError.h:85
NULL
#define NULL
Definition omList.c:12
om_SbrkInit
unsigned long om_SbrkInit
Definition omStats.c:18
om_Info
omInfo_t om_Info
Definition omStats.c:16

## omAlloc0Large()

void * omAlloc0Large | ( | size_t | size | ) |

Definition at line 82 of file omAllocSystem.c.

{
void* addr = omAllocLarge(size);
memset(addr, 0, size);
return addr;
}
omAllocLarge
void * omAllocLarge(size_t size)
Definition omAllocSystem.c:48

## omAllocFromSystem()

void * omAllocFromSystem | ( | size_t | size | ) |

Definition at line 194 of file omAllocSystem.c.

{
void* ptr;
ptr = OM_MALLOC_FROM_SYSTEM(size);
if (ptr == NULL)
{
OM_MEMORY_LOW_HOOK();
ptr = OM_MALLOC_FROM_SYSTEM(size);
if (ptr == NULL)
{
OM_OUT_OF_MEMORY_HOOK();
exit(1);
}
}
#if defined(HAVE_MALLOC_SIZE) || defined(HAVE_MALLOC_USABLE_SIZE)
size=_omSizeOfLargeAddr(ptr);
#else
size=omSizeOfAddr(ptr);
#endif
#ifndef OM_NDEBUG
if (((unsigned long) ptr) + size > om_MaxAddr)
om_MaxAddr = ((unsigned long) ptr) + size;
if (((unsigned long) ptr) < om_MinAddr)
om_MinAddr = ((unsigned long) ptr);
#endif
om_Info.CurrentBytesFromMalloc += size;
if (om_Info.CurrentBytesFromMalloc > om_Info.MaxBytesFromMalloc)
{
om_Info.MaxBytesFromMalloc = om_Info.CurrentBytesFromMalloc;
#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
if (om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM > om_Info.MaxBytesSystem)
om_Info.MaxBytesSystem = om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
#endif
#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
if (! om_SbrkInit) om_SbrkInit = (unsigned long) sbrk(0) - size;
if (om_Info.MaxBytesFromMalloc
#ifndef OM_HAVE_VALLOC_MMAP
+ om_Info.CurrentBytesFromValloc
#endif
> om_Info.MaxBytesSbrk)
{
om_Info.MaxBytesSbrk = (unsigned long) sbrk(0) - om_SbrkInit;
}
#endif
}
OM_MALLOC_HOOK(size);
return ptr;
}
omSizeOfAddr
size_t omSizeOfAddr(const void *addr)
Definition omAllocSystem.c:110
_omSizeOfLargeAddr
#define _omSizeOfLargeAddr(addr)
Definition omAllocSystem.c:79
OM_MALLOC_FROM_SYSTEM
#define OM_MALLOC_FROM_SYSTEM
Definition omAllocSystem.c:23

## omAllocLarge()

void * omAllocLarge | ( | size_t | size | ) |

Definition at line 48 of file omAllocSystem.c.

{
char* addr;
size = OM_ALIGN_SIZE(size);
addr = omAllocFromSystem(size + SIZEOF_STRICT_ALIGNMENT);
*((size_t*) addr) = size;
return (void *)(addr + SIZEOF_STRICT_ALIGNMENT);
}
omAllocFromSystem
void * omAllocFromSystem(size_t size)
Definition omAllocSystem.c:194

## omEmulateValloc()

void * omEmulateValloc | ( | size_t | size | ) |

Definition at line 159 of file omAllocSystem.c.

{
void* addr;
size_t padding = SIZEOF_VOIDP;
size = OM_ALIGN_SIZE(size);
while (1)
{
addr = OM_MALLOC_FROM_SYSTEM(size + padding);
if (addr == NULL) return NULL;
if ((OM_ALIGN_PAGE(addr) + SIZEOF_VOIDP) - (long) addr <= padding)
{
void* ret_addr = (void*) OM_ALIGN_PAGE(addr);
*((void**) ((void*) ret_addr + size)) = addr;
return ret_addr;
}
else
{
OM_FREE_TO_SYSTEM(addr);
padding = padding << 1;
}
}
}
OM_ALIGN_PAGE
#define OM_ALIGN_PAGE(addr)
Definition omAllocSystem.c:157
OM_FREE_TO_SYSTEM
#define OM_FREE_TO_SYSTEM
Definition omAllocSystem.c:25

## omEmulateVfree()

void omEmulateVfree | ( | void * | addr,
|  | size_t | size )

Definition at line 182 of file omAllocSystem.c.

{
size = OM_ALIGN_SIZE(size);
OM_FREE_TO_SYSTEM( *((void**) ((void*) addr + size)) );
}

## omFreeLarge()

void omFreeLarge | ( | void * | addr | ) |

Definition at line 73 of file omAllocSystem.c.

{
char* _addr = (char *)addr - SIZEOF_STRICT_ALIGNMENT;
omFreeSizeToSystem(_addr, *((size_t*) _addr) + SIZEOF_STRICT_ALIGNMENT);
}
omFreeSizeToSystem
void omFreeSizeToSystem(void *addr, size_t size)
Definition omAllocSystem.c:311

## omFreeSizeToSystem()

void omFreeSizeToSystem | ( | void * | addr,
|  | size_t | size )

Definition at line 311 of file omAllocSystem.c.

{
OM_FREE_TO_SYSTEM( addr );
om_Info.CurrentBytesFromMalloc -= size;
OM_FREE_HOOK(size);
}

## omFreeToSystem()

void omFreeToSystem | ( | void * | addr | ) |

Definition at line 306 of file omAllocSystem.c.

{
omFreeSizeToSystem(addr, omSizeOfAddr(addr));
}

## omRealloc0Large()

void * omRealloc0Large | ( | void * | old_addr,
|  | size_t | new_size )

Definition at line 89 of file omAllocSystem.c.

{
size_t old_size;
char* new_addr;
omAssume(!omIsBinPageAddr(old_addr));
old_size = omSizeOfLargeAddr(old_addr);
new_addr = omReallocLarge(old_addr, new_size);
new_size = omSizeOfLargeAddr(new_addr);
if (new_size > old_size)
memset(new_addr + old_size, 0, new_size - old_size);
return (void *)new_addr;
}
omSizeOfLargeAddr
size_t omSizeOfLargeAddr(void *addr)
Definition omAllocSystem.c:105
omReallocLarge
void * omReallocLarge(void *old_addr, size_t new_size)
Definition omAllocSystem.c:57
omIsBinPageAddr
#define omIsBinPageAddr(addr)
Definition omBinPage.h:68

## omReallocFromSystem()

void * omReallocFromSystem | ( | void * | addr,
|  | size_t | newsize )

Definition at line 245 of file omAllocSystem.c.

{
return omReallocSizeFromSystem(addr, omSizeOfAddr(addr), newsize);
}
omReallocSizeFromSystem
void * omReallocSizeFromSystem(void *addr, size_t oldsize, size_t newsize)
Definition omAllocSystem.c:250

## omReallocLarge()

void * omReallocLarge | ( | void * | old_addr,
|  | size_t | new_size )

Definition at line 57 of file omAllocSystem.c.

{
char* _old_addr;
char* new_addr;
omAssume(omIsLargeAddr(old_addr));
new_size = OM_ALIGN_SIZE(new_size);
_old_addr = (char *)old_addr - SIZEOF_STRICT_ALIGNMENT;
new_addr = omReallocSizeFromSystem(_old_addr,
*((size_t*) _old_addr) + SIZEOF_STRICT_ALIGNMENT,
new_size + SIZEOF_STRICT_ALIGNMENT);
*((size_t*) new_addr) = new_size;
return (void *)(new_addr + SIZEOF_STRICT_ALIGNMENT);
}

## omReallocSizeFromSystem()

void * omReallocSizeFromSystem | ( | void * | addr,
|  | size_t | oldsize,
|  | size_t | newsize )

Definition at line 250 of file omAllocSystem.c.

{
void* res;
/*oldsize=omSizeOfLargeAddr(addr);*/
res = OM_REALLOC_FROM_SYSTEM(addr, newsize);
if (res == NULL)
{
OM_MEMORY_LOW_HOOK();
/* Can do a realloc again: manpage reads:
"If realloc() fails the original block is left untouched -
it is not freed or moved." */
res = OM_REALLOC_FROM_SYSTEM(addr, newsize);
if (res == NULL)
{
OM_OUT_OF_MEMORY_HOOK();
/* should never get here */
omAssume(0);
exit(1);
}
}
/*newsize=omSizeOfAddr(res);*/
#ifndef OM_NDEBUG
if (((unsigned long) res) + newsize > om_MaxAddr)
om_MaxAddr = ((unsigned long) res) + newsize;
if (((unsigned long) res) < om_MinAddr)
om_MinAddr = ((unsigned long) res);
#endif
om_Info.CurrentBytesFromMalloc += (long) newsize - (long) oldsize;
if (om_Info.CurrentBytesFromMalloc > om_Info.MaxBytesFromMalloc)
{
om_Info.MaxBytesFromMalloc = om_Info.CurrentBytesFromMalloc;
#if defined(OM_HAVE_VALLOC_MMAP) && defined(OM_MALLOC_MAX_BYTES_SYSTEM)
if (om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM > om_Info.MaxBytesSystem)
om_Info.MaxBytesSystem = om_Info.CurrentBytesFromValloc + OM_MALLOC_MAX_BYTES_SYSTEM;
#endif
#if defined(HAVE_SBRK) && !defined(OM_MALLOC_MAX_BYTES_SBRK)
if (om_Info.MaxBytesFromMalloc
#ifndef OM_HAVE_VALLOC_MMAP
+ om_Info.CurrentBytesFromValloc
#endif
> om_Info.MaxBytesSbrk)
{
om_Info.MaxBytesSbrk = (unsigned long) sbrk(0) - om_SbrkInit;
}
#endif
}
OM_REALLOC_HOOK(oldsize, newsize);
return res;
}
res
CanonicalForm res
Definition facAbsFact.cc:60
OM_REALLOC_FROM_SYSTEM
#define OM_REALLOC_FROM_SYSTEM
Definition omAllocSystem.c:24

## omSizeOfAddr()

size_t omSizeOfAddr | ( | const void * | addr | ) |

Definition at line 110 of file omAllocSystem.c.

{
/*if (addr==NULL) return 0; */
return (omIsBinPageAddr(addr) ?
#ifdef OM_HAVE_TRACK
(omIsBinAddrTrackAddr(addr) ? omOutSizeOfTrackAddr((char *)addr) : omSizeOfBinAddr(addr)) :
#else
omSizeOfBinAddr(addr) :
#endif
omSizeOfLargeAddr((char *)addr));
}
omSizeOfBinAddr
#define omSizeOfBinAddr(addr)
Definition omAllocPrivate.h:97
omIsBinAddrTrackAddr
#define omIsBinAddrTrackAddr(addr)
Definition omDebug.h:15

## omSizeOfLargeAddr()

size_t omSizeOfLargeAddr | ( | void * | addr | ) |

Definition at line 105 of file omAllocSystem.c.

{
return _omSizeOfLargeAddr((char *)addr);
}

## omSizeWOfAddr()

size_t omSizeWOfAddr | ( | void * | addr | ) |

Definition at line 123 of file omAllocSystem.c.

{
return (omIsBinPageAddr(addr) ?
#ifdef OM_HAVE_TRACK
(omIsBinAddrTrackAddr(addr) ? omOutSizeOfTrackAddr(addr) >> LOG_SIZEOF_LONG : omSizeWOfBinAddr(addr)) :
#else
omSizeWOfBinAddr(addr) :
#endif
omSizeOfLargeAddr(addr) >> LOG_SIZEOF_LONG);
}
omSizeWOfBinAddr
#define omSizeWOfBinAddr(addr)
Definition omAllocPrivate.h:103

## omVfreeToSystem()

void omVfreeToSystem | ( | void * | page,
|  | size_t | size )

Definition at line 368 of file omAllocSystem.c.

{
omAssume(omIsAddrPageAligned(page));
OM_VFREE_TO_SYSTEM(page, size);
om_Info.CurrentBytesFromValloc -= size;
OM_VFREE_HOOK(size);
}
OM_VFREE_TO_SYSTEM
#define OM_VFREE_TO_SYSTEM
Definition omAllocSystem.c:155