mem.c revision 18d0b5e54be891a1aa938c165b6d439859121ec8
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * Copyright (C) 2004, 2005 Internet Systems Consortium, Inc. ("ISC")
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * Copyright (C) 1997-2003 Internet Software Consortium.
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * Permission to use, copy, modify, and distribute this software for any
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * purpose with or without fee is hereby granted, provided that the above
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * copyright notice and this permission notice appear in all copies.
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * PERFORMANCE OF THIS SOFTWARE.
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt/* $Id: mem.c,v 1.123 2005/07/12 01:00:18 marka Exp $ */
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt#define MCTXLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) LOCK(l)
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt#define MCTXUNLOCK(m, l) if (((m)->flags & ISC_MEMFLAG_NOLOCK) == 0) UNLOCK(l)
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan HuntLIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING;
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt * Constants.
98922b2b2b024dcca25be7c220cf3b16b1e6c4b5Evan Hunt#define ALIGNMENT_SIZE 8 /*%< must be a power of 2 */
unsigned int count;
#define FLARG_PASS
#define FLARG
struct element {
} size_info;
struct stats {
unsigned long gets;
unsigned long totalgets;
unsigned long blocks;
unsigned long freefrags;
struct isc_mem {
unsigned int magic;
unsigned int flags;
void * arg;
unsigned int references;
void * water_arg;
unsigned char ** basic_table;
unsigned int basic_table_count;
unsigned int basic_table_size;
unsigned char * lowest;
unsigned char * highest;
unsigned int memalloc_failures;
struct isc_mempool {
#if ! ISC_MEM_TRACKLINES
#define ADD_TRACE(a, b, c, d, e)
#define DELETE_TRACE(a, b, c, d, e)
#define ADD_TRACE(a, b, c, d, e) \
ISC_MEM_DEBUGRECORD)) != 0 && \
b != NULL) \
add_trace_entry(a, b, c, d, e); \
goto next;
for (i = 0; i < DEBUGLIST_COUNT; i++) {
next:
for (i = 0; i < DEBUGLIST_COUNT; i++) {
static inline size_t
static inline size_t
if (size == 0)
return (ALIGNMENT_SIZE);
static inline isc_boolean_t
void *new;
unsigned char **table;
unsigned int table_size;
return (ISC_FALSE);
table_size * sizeof(unsigned char *));
return (ISC_FALSE);
return (ISC_FALSE);
return (ISC_TRUE);
static inline isc_boolean_t
int i, frags;
void *new;
return (ISC_FALSE);
if (total_size > 0) {
return (ISC_TRUE);
void *ret;
goto done;
goto done;
goto done;
return (NULL);
done:
#if ISC_MEM_FILL
return (ret);
unsigned char *cp;
cp++;
size++;
#if ISC_MEM_FILL
#if ISC_MEM_FILL
char *ret;
#if ISC_MEM_FILL
# if ISC_MEM_CHECKOVERRUN
return (ret);
#if ISC_MEM_FILL
if (size == 0U)
return (ISC_R_NOMEMORY);
return (result);
if (init_max_size == 0U)
goto error;
if (target_size == 0)
sizeof(element *));
goto error;
goto error;
return (ISC_R_SUCCESS);
return (result);
if (want_destroy)
if (want_destroy)
if (want_destroy)
return (res);
void *ptr;
if (call_water)
return (ptr);
if (call_water)
const char *format;
for (j = 0; j < DEBUGLIST_COUNT; j++)
if (!found)
size_t i;
const struct stats *s;
return (NULL);
si++;
if (call_water)
return (si);
if (call_water)
char *ns;
return (ns);
return (quota);
return (inuse);
return (ISC_R_NOMEMORY);
return (ISC_R_SUCCESS);
goto out;
goto out;
goto out;
out:
return (item);
unsigned int freemax;
return (freemax);
unsigned int freecount;
return (freecount);
unsigned int maxalloc;
return (maxalloc);
unsigned int allocated;
return (allocated);
unsigned int fillcount;
return (fillcount);