Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/include/bind9/isc
File: mem.h
/*
[0] Fix | Delete
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
[1] Fix | Delete
*
[2] Fix | Delete
* This Source Code Form is subject to the terms of the Mozilla Public
[3] Fix | Delete
* License, v. 2.0. If a copy of the MPL was not distributed with this
[4] Fix | Delete
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
[5] Fix | Delete
*
[6] Fix | Delete
* See the COPYRIGHT file distributed with this work for additional
[7] Fix | Delete
* information regarding copyright ownership.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
#ifndef ISC_MEM_H
[11] Fix | Delete
#define ISC_MEM_H 1
[12] Fix | Delete
[13] Fix | Delete
/*! \file isc/mem.h */
[14] Fix | Delete
[15] Fix | Delete
#include <stdbool.h>
[16] Fix | Delete
#include <stdio.h>
[17] Fix | Delete
[18] Fix | Delete
#include <isc/json.h>
[19] Fix | Delete
#include <isc/lang.h>
[20] Fix | Delete
#include <isc/mutex.h>
[21] Fix | Delete
#include <isc/platform.h>
[22] Fix | Delete
#include <isc/types.h>
[23] Fix | Delete
#include <isc/xml.h>
[24] Fix | Delete
[25] Fix | Delete
ISC_LANG_BEGINDECLS
[26] Fix | Delete
[27] Fix | Delete
#define ISC_MEM_LOWATER 0
[28] Fix | Delete
#define ISC_MEM_HIWATER 1
[29] Fix | Delete
typedef void (*isc_mem_water_t)(void *, int);
[30] Fix | Delete
[31] Fix | Delete
typedef void * (*isc_memalloc_t)(void *, size_t);
[32] Fix | Delete
typedef void (*isc_memfree_t)(void *, void *);
[33] Fix | Delete
[34] Fix | Delete
/*%
[35] Fix | Delete
* Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
[36] Fix | Delete
* allocation and freeing by file and line number.
[37] Fix | Delete
*/
[38] Fix | Delete
#ifndef ISC_MEM_TRACKLINES
[39] Fix | Delete
#define ISC_MEM_TRACKLINES 1
[40] Fix | Delete
#endif
[41] Fix | Delete
[42] Fix | Delete
/*%
[43] Fix | Delete
* Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside
[44] Fix | Delete
* the requested space. This will increase the size of each allocation.
[45] Fix | Delete
*
[46] Fix | Delete
* If we are performing a Coverity static analysis then ISC_MEM_CHECKOVERRUN
[47] Fix | Delete
* can hide bugs that would otherwise discovered so force to zero.
[48] Fix | Delete
*/
[49] Fix | Delete
#ifdef __COVERITY__
[50] Fix | Delete
#undef ISC_MEM_CHECKOVERRUN
[51] Fix | Delete
#define ISC_MEM_CHECKOVERRUN 0
[52] Fix | Delete
#endif
[53] Fix | Delete
#ifndef ISC_MEM_CHECKOVERRUN
[54] Fix | Delete
#define ISC_MEM_CHECKOVERRUN 1
[55] Fix | Delete
#endif
[56] Fix | Delete
[57] Fix | Delete
/*%
[58] Fix | Delete
* Define ISC_MEM_FILL=1 to fill each block of memory returned to the system
[59] Fix | Delete
* with the byte string '0xbe'. This helps track down uninitialized pointers
[60] Fix | Delete
* and the like. On freeing memory, the space is filled with '0xde' for
[61] Fix | Delete
* the same reasons.
[62] Fix | Delete
*
[63] Fix | Delete
* If we are performing a Coverity static analysis then ISC_MEM_FILL
[64] Fix | Delete
* can hide bugs that would otherwise discovered so force to zero.
[65] Fix | Delete
*/
[66] Fix | Delete
#ifdef __COVERITY__
[67] Fix | Delete
#undef ISC_MEM_FILL
[68] Fix | Delete
#define ISC_MEM_FILL 0
[69] Fix | Delete
#endif
[70] Fix | Delete
#ifndef ISC_MEM_FILL
[71] Fix | Delete
#define ISC_MEM_FILL 1
[72] Fix | Delete
#endif
[73] Fix | Delete
[74] Fix | Delete
/*%
[75] Fix | Delete
* Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic
[76] Fix | Delete
* name so that the leaking pool can be more readily identified in
[77] Fix | Delete
* case of a memory leak.
[78] Fix | Delete
*/
[79] Fix | Delete
#ifndef ISC_MEMPOOL_NAMES
[80] Fix | Delete
#define ISC_MEMPOOL_NAMES 1
[81] Fix | Delete
#endif
[82] Fix | Delete
[83] Fix | Delete
LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
[84] Fix | Delete
LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
[85] Fix | Delete
[86] Fix | Delete
/*@{*/
[87] Fix | Delete
#define ISC_MEM_DEBUGTRACE 0x00000001U
[88] Fix | Delete
#define ISC_MEM_DEBUGRECORD 0x00000002U
[89] Fix | Delete
#define ISC_MEM_DEBUGUSAGE 0x00000004U
[90] Fix | Delete
#define ISC_MEM_DEBUGSIZE 0x00000008U
[91] Fix | Delete
#define ISC_MEM_DEBUGCTX 0x00000010U
[92] Fix | Delete
#define ISC_MEM_DEBUGALL 0x0000001FU
[93] Fix | Delete
/*!<
[94] Fix | Delete
* The variable isc_mem_debugging holds a set of flags for
[95] Fix | Delete
* turning certain memory debugging options on or off at
[96] Fix | Delete
* runtime. It is initialized to the value ISC_MEM_DEGBUGGING,
[97] Fix | Delete
* which is 0 by default but may be overridden at compile time.
[98] Fix | Delete
* The following flags can be specified:
[99] Fix | Delete
*
[100] Fix | Delete
* \li #ISC_MEM_DEBUGTRACE
[101] Fix | Delete
* Log each allocation and free to isc_lctx.
[102] Fix | Delete
*
[103] Fix | Delete
* \li #ISC_MEM_DEBUGRECORD
[104] Fix | Delete
* Remember each allocation, and match them up on free.
[105] Fix | Delete
* Crash if a free doesn't match an allocation.
[106] Fix | Delete
*
[107] Fix | Delete
* \li #ISC_MEM_DEBUGUSAGE
[108] Fix | Delete
* If a hi_water mark is set, print the maximum inuse memory
[109] Fix | Delete
* every time it is raised once it exceeds the hi_water mark.
[110] Fix | Delete
*
[111] Fix | Delete
* \li #ISC_MEM_DEBUGSIZE
[112] Fix | Delete
* Check the size argument being passed to isc_mem_put() matches
[113] Fix | Delete
* that passed to isc_mem_get().
[114] Fix | Delete
*
[115] Fix | Delete
* \li #ISC_MEM_DEBUGCTX
[116] Fix | Delete
* Check the mctx argument being passed to isc_mem_put() matches
[117] Fix | Delete
* that passed to isc_mem_get().
[118] Fix | Delete
*/
[119] Fix | Delete
/*@}*/
[120] Fix | Delete
[121] Fix | Delete
#if ISC_MEM_TRACKLINES
[122] Fix | Delete
#define _ISC_MEM_FILELINE , __FILE__, __LINE__
[123] Fix | Delete
#define _ISC_MEM_FLARG , const char *, unsigned int
[124] Fix | Delete
#else
[125] Fix | Delete
#define _ISC_MEM_FILELINE
[126] Fix | Delete
#define _ISC_MEM_FLARG
[127] Fix | Delete
#endif
[128] Fix | Delete
[129] Fix | Delete
/*!
[130] Fix | Delete
* Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
[131] Fix | Delete
* implementation in preference to the system one. The internal malloc()
[132] Fix | Delete
* is very space-efficient, and quite fast on uniprocessor systems. It
[133] Fix | Delete
* performs poorly on multiprocessor machines.
[134] Fix | Delete
* JT: we can overcome the performance issue on multiprocessor machines
[135] Fix | Delete
* by carefully separating memory contexts.
[136] Fix | Delete
*/
[137] Fix | Delete
[138] Fix | Delete
#ifndef ISC_MEM_USE_INTERNAL_MALLOC
[139] Fix | Delete
#define ISC_MEM_USE_INTERNAL_MALLOC 1
[140] Fix | Delete
#endif
[141] Fix | Delete
[142] Fix | Delete
/*
[143] Fix | Delete
* Flags for isc_mem_create2()calls.
[144] Fix | Delete
*/
[145] Fix | Delete
#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */
[146] Fix | Delete
#define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */
[147] Fix | Delete
#if ISC_MEM_USE_INTERNAL_MALLOC
[148] Fix | Delete
#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL
[149] Fix | Delete
#else
[150] Fix | Delete
#define ISC_MEMFLAG_DEFAULT 0
[151] Fix | Delete
#endif
[152] Fix | Delete
[153] Fix | Delete
[154] Fix | Delete
/*%<
[155] Fix | Delete
* We use either isc___mem (three underscores) or isc__mem (two) depending on
[156] Fix | Delete
* whether it's for BIND9's internal purpose (with -DBIND9) or generic export
[157] Fix | Delete
* library.
[158] Fix | Delete
*/
[159] Fix | Delete
#define ISCMEMFUNC(sfx) isc__mem_ ## sfx
[160] Fix | Delete
#define ISCMEMPOOLFUNC(sfx) isc__mempool_ ## sfx
[161] Fix | Delete
[162] Fix | Delete
#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s) _ISC_MEM_FILELINE)
[163] Fix | Delete
#define isc_mem_allocate(c, s) ISCMEMFUNC(allocate)((c), (s) _ISC_MEM_FILELINE)
[164] Fix | Delete
#define isc_mem_reallocate(c, p, s) ISCMEMFUNC(reallocate)((c), (p), (s) _ISC_MEM_FILELINE)
[165] Fix | Delete
#define isc_mem_strdup(c, p) ISCMEMFUNC(strdup)((c), (p) _ISC_MEM_FILELINE)
[166] Fix | Delete
#define isc_mempool_get(c) ISCMEMPOOLFUNC(get)((c) _ISC_MEM_FILELINE)
[167] Fix | Delete
[168] Fix | Delete
/*%
[169] Fix | Delete
* isc_mem_putanddetach() is a convenience function for use where you
[170] Fix | Delete
* have a structure with an attached memory context.
[171] Fix | Delete
*
[172] Fix | Delete
* Given:
[173] Fix | Delete
*
[174] Fix | Delete
* \code
[175] Fix | Delete
* struct {
[176] Fix | Delete
* ...
[177] Fix | Delete
* isc_mem_t *mctx;
[178] Fix | Delete
* ...
[179] Fix | Delete
* } *ptr;
[180] Fix | Delete
*
[181] Fix | Delete
* isc_mem_t *mctx;
[182] Fix | Delete
*
[183] Fix | Delete
* isc_mem_putanddetach(&ptr->mctx, ptr, sizeof(*ptr));
[184] Fix | Delete
* \endcode
[185] Fix | Delete
*
[186] Fix | Delete
* is the equivalent of:
[187] Fix | Delete
*
[188] Fix | Delete
* \code
[189] Fix | Delete
* mctx = NULL;
[190] Fix | Delete
* isc_mem_attach(ptr->mctx, &mctx);
[191] Fix | Delete
* isc_mem_detach(&ptr->mctx);
[192] Fix | Delete
* isc_mem_put(mctx, ptr, sizeof(*ptr));
[193] Fix | Delete
* isc_mem_detach(&mctx);
[194] Fix | Delete
* \endcode
[195] Fix | Delete
*/
[196] Fix | Delete
[197] Fix | Delete
/*% memory and memory pool methods */
[198] Fix | Delete
typedef struct isc_memmethods {
[199] Fix | Delete
void (*attach)(isc_mem_t *source, isc_mem_t **targetp);
[200] Fix | Delete
void (*detach)(isc_mem_t **mctxp);
[201] Fix | Delete
void (*destroy)(isc_mem_t **mctxp);
[202] Fix | Delete
void *(*memget)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
[203] Fix | Delete
void (*memput)(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG);
[204] Fix | Delete
void (*memputanddetach)(isc_mem_t **mctxp, void *ptr,
[205] Fix | Delete
size_t size _ISC_MEM_FLARG);
[206] Fix | Delete
void *(*memallocate)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
[207] Fix | Delete
void *(*memreallocate)(isc_mem_t *mctx, void *ptr,
[208] Fix | Delete
size_t size _ISC_MEM_FLARG);
[209] Fix | Delete
char *(*memstrdup)(isc_mem_t *mctx, const char *s _ISC_MEM_FLARG);
[210] Fix | Delete
void (*memfree)(isc_mem_t *mctx, void *ptr _ISC_MEM_FLARG);
[211] Fix | Delete
void (*setdestroycheck)(isc_mem_t *mctx, bool flag);
[212] Fix | Delete
void (*setwater)(isc_mem_t *ctx, isc_mem_water_t water,
[213] Fix | Delete
void *water_arg, size_t hiwater, size_t lowater);
[214] Fix | Delete
void (*waterack)(isc_mem_t *ctx, int flag);
[215] Fix | Delete
size_t (*inuse)(isc_mem_t *mctx);
[216] Fix | Delete
size_t (*maxinuse)(isc_mem_t *mctx);
[217] Fix | Delete
size_t (*total)(isc_mem_t *mctx);
[218] Fix | Delete
bool (*isovermem)(isc_mem_t *mctx);
[219] Fix | Delete
isc_result_t (*mpcreate)(isc_mem_t *mctx, size_t size,
[220] Fix | Delete
isc_mempool_t **mpctxp);
[221] Fix | Delete
} isc_memmethods_t;
[222] Fix | Delete
[223] Fix | Delete
typedef struct isc_mempoolmethods {
[224] Fix | Delete
void (*destroy)(isc_mempool_t **mpctxp);
[225] Fix | Delete
void *(*get)(isc_mempool_t *mpctx _ISC_MEM_FLARG);
[226] Fix | Delete
void (*put)(isc_mempool_t *mpctx, void *mem _ISC_MEM_FLARG);
[227] Fix | Delete
unsigned int (*getallocated)(isc_mempool_t *mpctx);
[228] Fix | Delete
void (*setmaxalloc)(isc_mempool_t *mpctx, unsigned int limit);
[229] Fix | Delete
void (*setfreemax)(isc_mempool_t *mpctx, unsigned int limit);
[230] Fix | Delete
void (*setname)(isc_mempool_t *mpctx, const char *name);
[231] Fix | Delete
void (*associatelock)(isc_mempool_t *mpctx, isc_mutex_t *lock);
[232] Fix | Delete
void (*setfillcount)(isc_mempool_t *mpctx, unsigned int limit);
[233] Fix | Delete
} isc_mempoolmethods_t;
[234] Fix | Delete
[235] Fix | Delete
/*%
[236] Fix | Delete
* This structure is actually just the common prefix of a memory context
[237] Fix | Delete
* implementation's version of an isc_mem_t.
[238] Fix | Delete
* \brief
[239] Fix | Delete
* Direct use of this structure by clients is forbidden. mctx implementations
[240] Fix | Delete
* may change the structure. 'magic' must be ISCAPI_MCTX_MAGIC for any of the
[241] Fix | Delete
* isc_mem_ routines to work. mctx implementations must maintain all mctx
[242] Fix | Delete
* invariants.
[243] Fix | Delete
*/
[244] Fix | Delete
struct isc_mem {
[245] Fix | Delete
unsigned int impmagic;
[246] Fix | Delete
unsigned int magic;
[247] Fix | Delete
isc_memmethods_t *methods;
[248] Fix | Delete
};
[249] Fix | Delete
[250] Fix | Delete
#define ISCAPI_MCTX_MAGIC ISC_MAGIC('A','m','c','x')
[251] Fix | Delete
#define ISCAPI_MCTX_VALID(m) ((m) != NULL && \
[252] Fix | Delete
(m)->magic == ISCAPI_MCTX_MAGIC)
[253] Fix | Delete
[254] Fix | Delete
/*%
[255] Fix | Delete
* This is the common prefix of a memory pool context. The same note as
[256] Fix | Delete
* that for the mem structure applies.
[257] Fix | Delete
*/
[258] Fix | Delete
struct isc_mempool {
[259] Fix | Delete
unsigned int impmagic;
[260] Fix | Delete
unsigned int magic;
[261] Fix | Delete
isc_mempoolmethods_t *methods;
[262] Fix | Delete
};
[263] Fix | Delete
[264] Fix | Delete
#define ISCAPI_MPOOL_MAGIC ISC_MAGIC('A','m','p','l')
[265] Fix | Delete
#define ISCAPI_MPOOL_VALID(mp) ((mp) != NULL && \
[266] Fix | Delete
(mp)->magic == ISCAPI_MPOOL_MAGIC)
[267] Fix | Delete
[268] Fix | Delete
#define isc_mem_put(c, p, s) \
[269] Fix | Delete
do { \
[270] Fix | Delete
ISCMEMFUNC(put)((c), (p), (s) _ISC_MEM_FILELINE); \
[271] Fix | Delete
(p) = NULL; \
[272] Fix | Delete
} while (0)
[273] Fix | Delete
#define isc_mem_putanddetach(c, p, s) \
[274] Fix | Delete
do { \
[275] Fix | Delete
ISCMEMFUNC(putanddetach)((c), (p), (s) _ISC_MEM_FILELINE); \
[276] Fix | Delete
(p) = NULL; \
[277] Fix | Delete
} while (0)
[278] Fix | Delete
#define isc_mem_free(c, p) \
[279] Fix | Delete
do { \
[280] Fix | Delete
ISCMEMFUNC(free)((c), (p) _ISC_MEM_FILELINE); \
[281] Fix | Delete
(p) = NULL; \
[282] Fix | Delete
} while (0)
[283] Fix | Delete
#define isc_mempool_put(c, p) \
[284] Fix | Delete
do { \
[285] Fix | Delete
ISCMEMPOOLFUNC(put)((c), (p) _ISC_MEM_FILELINE); \
[286] Fix | Delete
(p) = NULL; \
[287] Fix | Delete
} while (0)
[288] Fix | Delete
[289] Fix | Delete
/*@{*/
[290] Fix | Delete
isc_result_t
[291] Fix | Delete
isc_mem_create(size_t max_size, size_t target_size,
[292] Fix | Delete
isc_mem_t **mctxp);
[293] Fix | Delete
[294] Fix | Delete
isc_result_t
[295] Fix | Delete
isc_mem_create2(size_t max_size, size_t target_size,
[296] Fix | Delete
isc_mem_t **mctxp, unsigned int flags);
[297] Fix | Delete
[298] Fix | Delete
isc_result_t
[299] Fix | Delete
isc_mem_createx(size_t max_size, size_t target_size,
[300] Fix | Delete
isc_memalloc_t memalloc, isc_memfree_t memfree,
[301] Fix | Delete
void *arg, isc_mem_t **mctxp);
[302] Fix | Delete
[303] Fix | Delete
isc_result_t
[304] Fix | Delete
isc_mem_createx2(size_t max_size, size_t target_size,
[305] Fix | Delete
isc_memalloc_t memalloc, isc_memfree_t memfree,
[306] Fix | Delete
void *arg, isc_mem_t **mctxp, unsigned int flags);
[307] Fix | Delete
[308] Fix | Delete
/*!<
[309] Fix | Delete
* \brief Create a memory context.
[310] Fix | Delete
*
[311] Fix | Delete
* 'max_size' and 'target_size' are tuning parameters. When
[312] Fix | Delete
* ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
[313] Fix | Delete
* will be satisfied by getting blocks of size 'target_size' from the
[314] Fix | Delete
* system allocator and breaking them up into pieces; larger allocations
[315] Fix | Delete
* will use the system allocator directly. If 'max_size' and/or
[316] Fix | Delete
* 'target_size' are zero, default values will be * used. When
[317] Fix | Delete
* ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
[318] Fix | Delete
*
[319] Fix | Delete
* 'max_size' is also used to size the statistics arrays and the array
[320] Fix | Delete
* used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting
[321] Fix | Delete
* 'max_size' too low can have detrimental effects on performance.
[322] Fix | Delete
*
[323] Fix | Delete
* A memory context created using isc_mem_createx() will obtain
[324] Fix | Delete
* memory from the system by calling 'memalloc' and 'memfree',
[325] Fix | Delete
* passing them the argument 'arg'. A memory context created
[326] Fix | Delete
* using isc_mem_create() will use the standard library malloc()
[327] Fix | Delete
* and free().
[328] Fix | Delete
*
[329] Fix | Delete
* If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
[330] Fix | Delete
* will be accessed without locking. The user who creates the context must
[331] Fix | Delete
* ensure there be no race. Since this can be a source of bug, it is generally
[332] Fix | Delete
* inadvisable to use this flag unless the user is very sure about the race
[333] Fix | Delete
* condition and the access to the object is highly performance sensitive.
[334] Fix | Delete
*
[335] Fix | Delete
* Requires:
[336] Fix | Delete
* mctxp != NULL && *mctxp == NULL */
[337] Fix | Delete
/*@}*/
[338] Fix | Delete
[339] Fix | Delete
/*@{*/
[340] Fix | Delete
void
[341] Fix | Delete
isc_mem_attach(isc_mem_t *, isc_mem_t **);
[342] Fix | Delete
void
[343] Fix | Delete
isc_mem_detach(isc_mem_t **);
[344] Fix | Delete
/*!<
[345] Fix | Delete
* \brief Attach to / detach from a memory context.
[346] Fix | Delete
*
[347] Fix | Delete
* This is intended for applications that use multiple memory contexts
[348] Fix | Delete
* in such a way that it is not obvious when the last allocations from
[349] Fix | Delete
* a given context has been freed and destroying the context is safe.
[350] Fix | Delete
*
[351] Fix | Delete
* Most applications do not need to call these functions as they can
[352] Fix | Delete
* simply create a single memory context at the beginning of main()
[353] Fix | Delete
* and destroy it at the end of main(), thereby guaranteeing that it
[354] Fix | Delete
* is not destroyed while there are outstanding allocations.
[355] Fix | Delete
*/
[356] Fix | Delete
/*@}*/
[357] Fix | Delete
[358] Fix | Delete
void
[359] Fix | Delete
isc_mem_destroy(isc_mem_t **);
[360] Fix | Delete
/*%<
[361] Fix | Delete
* Destroy a memory context.
[362] Fix | Delete
*/
[363] Fix | Delete
[364] Fix | Delete
isc_result_t
[365] Fix | Delete
isc_mem_ondestroy(isc_mem_t *ctx,
[366] Fix | Delete
isc_task_t *task,
[367] Fix | Delete
isc_event_t **event);
[368] Fix | Delete
/*%<
[369] Fix | Delete
* Request to be notified with an event when a memory context has
[370] Fix | Delete
* been successfully destroyed.
[371] Fix | Delete
*/
[372] Fix | Delete
[373] Fix | Delete
void
[374] Fix | Delete
isc_mem_stats(isc_mem_t *mctx, FILE *out);
[375] Fix | Delete
/*%<
[376] Fix | Delete
* Print memory usage statistics for 'mctx' on the stream 'out'.
[377] Fix | Delete
*/
[378] Fix | Delete
[379] Fix | Delete
void
[380] Fix | Delete
isc_mem_setdestroycheck(isc_mem_t *mctx,
[381] Fix | Delete
bool on);
[382] Fix | Delete
/*%<
[383] Fix | Delete
* If 'on' is true, 'mctx' will check for memory leaks when
[384] Fix | Delete
* destroyed and abort the program if any are present.
[385] Fix | Delete
*/
[386] Fix | Delete
[387] Fix | Delete
/*@{*/
[388] Fix | Delete
void
[389] Fix | Delete
isc_mem_setquota(isc_mem_t *, size_t);
[390] Fix | Delete
size_t
[391] Fix | Delete
isc_mem_getquota(isc_mem_t *);
[392] Fix | Delete
/*%<
[393] Fix | Delete
* Set/get the memory quota of 'mctx'. This is a hard limit
[394] Fix | Delete
* on the amount of memory that may be allocated from mctx;
[395] Fix | Delete
* if it is exceeded, allocations will fail.
[396] Fix | Delete
*/
[397] Fix | Delete
/*@}*/
[398] Fix | Delete
[399] Fix | Delete
size_t
[400] Fix | Delete
isc_mem_inuse(isc_mem_t *mctx);
[401] Fix | Delete
/*%<
[402] Fix | Delete
* Get an estimate of the amount of memory in use in 'mctx', in bytes.
[403] Fix | Delete
* This includes quantization overhead, but does not include memory
[404] Fix | Delete
* allocated from the system but not yet used.
[405] Fix | Delete
*/
[406] Fix | Delete
[407] Fix | Delete
size_t
[408] Fix | Delete
isc_mem_maxinuse(isc_mem_t *mctx);
[409] Fix | Delete
/*%<
[410] Fix | Delete
* Get an estimate of the largest amount of memory that has been in
[411] Fix | Delete
* use in 'mctx' at any time.
[412] Fix | Delete
*/
[413] Fix | Delete
[414] Fix | Delete
size_t
[415] Fix | Delete
isc_mem_total(isc_mem_t *mctx);
[416] Fix | Delete
/*%<
[417] Fix | Delete
* Get the total amount of memory in 'mctx', in bytes, including memory
[418] Fix | Delete
* not yet used.
[419] Fix | Delete
*/
[420] Fix | Delete
[421] Fix | Delete
bool
[422] Fix | Delete
isc_mem_isovermem(isc_mem_t *mctx);
[423] Fix | Delete
/*%<
[424] Fix | Delete
* Return true iff the memory context is in "over memory" state, i.e.,
[425] Fix | Delete
* a hiwater mark has been set and the used amount of memory has exceeds
[426] Fix | Delete
* the mark.
[427] Fix | Delete
*/
[428] Fix | Delete
[429] Fix | Delete
void
[430] Fix | Delete
isc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,
[431] Fix | Delete
size_t hiwater, size_t lowater);
[432] Fix | Delete
/*%<
[433] Fix | Delete
* Set high and low water marks for this memory context.
[434] Fix | Delete
*
[435] Fix | Delete
* When the memory usage of 'mctx' exceeds 'hiwater',
[436] Fix | Delete
* '(water)(water_arg, #ISC_MEM_HIWATER)' will be called. 'water' needs to
[437] Fix | Delete
* call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowledge the state
[438] Fix | Delete
* change. 'water' may be called multiple times.
[439] Fix | Delete
*
[440] Fix | Delete
* When the usage drops below 'lowater', 'water' will again be called, this
[441] Fix | Delete
* time with #ISC_MEM_LOWATER. 'water' need to calls isc_mem_waterack() with
[442] Fix | Delete
* #ISC_MEM_LOWATER to acknowledge the change.
[443] Fix | Delete
*
[444] Fix | Delete
* static void
[445] Fix | Delete
* water(void *arg, int mark) {
[446] Fix | Delete
* struct foo *foo = arg;
[447] Fix | Delete
*
[448] Fix | Delete
* LOCK(&foo->marklock);
[449] Fix | Delete
* if (foo->mark != mark) {
[450] Fix | Delete
* foo->mark = mark;
[451] Fix | Delete
* ....
[452] Fix | Delete
* isc_mem_waterack(foo->mctx, mark);
[453] Fix | Delete
* }
[454] Fix | Delete
* UNLOCK(&foo->marklock);
[455] Fix | Delete
* }
[456] Fix | Delete
*
[457] Fix | Delete
* If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are
[458] Fix | Delete
* ignored and the state is reset.
[459] Fix | Delete
*
[460] Fix | Delete
* Requires:
[461] Fix | Delete
*
[462] Fix | Delete
* 'water' is not NULL.
[463] Fix | Delete
* hi_water >= lo_water
[464] Fix | Delete
*/
[465] Fix | Delete
[466] Fix | Delete
void
[467] Fix | Delete
isc_mem_waterack(isc_mem_t *ctx, int mark);
[468] Fix | Delete
/*%<
[469] Fix | Delete
* Called to acknowledge changes in signaled by calls to 'water'.
[470] Fix | Delete
*/
[471] Fix | Delete
[472] Fix | Delete
void
[473] Fix | Delete
isc_mem_printactive(isc_mem_t *mctx, FILE *file);
[474] Fix | Delete
/*%<
[475] Fix | Delete
* Print to 'file' all active memory in 'mctx'.
[476] Fix | Delete
*
[477] Fix | Delete
* Requires ISC_MEM_DEBUGRECORD to have been set.
[478] Fix | Delete
*/
[479] Fix | Delete
[480] Fix | Delete
void
[481] Fix | Delete
isc_mem_printallactive(FILE *file);
[482] Fix | Delete
/*%<
[483] Fix | Delete
* Print to 'file' all active memory in all contexts.
[484] Fix | Delete
*
[485] Fix | Delete
* Requires ISC_MEM_DEBUGRECORD to have been set.
[486] Fix | Delete
*/
[487] Fix | Delete
[488] Fix | Delete
void
[489] Fix | Delete
isc_mem_checkdestroyed(FILE *file);
[490] Fix | Delete
/*%<
[491] Fix | Delete
* Check that all memory contexts have been destroyed.
[492] Fix | Delete
* Prints out those that have not been.
[493] Fix | Delete
* Fatally fails if there are still active contexts.
[494] Fix | Delete
*/
[495] Fix | Delete
[496] Fix | Delete
unsigned int
[497] Fix | Delete
isc_mem_references(isc_mem_t *ctx);
[498] Fix | Delete
/*%<
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function