138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1997-2001, 2004-2013, 2015, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley */
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#ifndef ISC_MEM_H
4cafb28abcaa2a485c7aac1696213435538b92edBob Halley#define ISC_MEM_H 1
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
29747dfe5e073a299b3681e01f5c55540f8bfed7Mark Andrews/*! \file isc/mem.h */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley#include <stdio.h>
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt#include <isc/json.h>
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/lang.h>
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/mutex.h>
c4958494a98a59ce25e9fecad76a9ab0e36cc59fDanny Mayer#include <isc/platform.h>
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff#include <isc/types.h>
96ea71632887c58a9d00f47eb318bf76b35903c3Mark Andrews#include <isc/xml.h>
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
7aacbd685b2107670e4179689abec9cb82d972abBob HalleyISC_LANG_BEGINDECLS
7aacbd685b2107670e4179689abec9cb82d972abBob Halley
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews#define ISC_MEM_LOWATER 0
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews#define ISC_MEM_HIWATER 1
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewstypedef void (*isc_mem_water_t)(void *, int);
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halleytypedef void * (*isc_memalloc_t)(void *, size_t);
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halleytypedef void (*isc_memfree_t)(void *, void *);
ac70da9a2710aa9f343d2f720eb1bdd4191a79caBob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEM_TRACKLINES=1 to turn on detailed tracing of memory
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * allocation and freeing by file and line number.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_TRACKLINES
50a8312c9f682004e21ffb2d58ec2064a244a9c7Andreas Gustafsson#define ISC_MEM_TRACKLINES 1
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson * Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * the requested space. This will increase the size of each allocation.
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews *
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews * If we are performing a Coverity static analysis then ISC_MEM_CHECKOVERRUN
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews * can hide bugs that would otherwise discovered so force to zero.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#ifdef __COVERITY__
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#undef ISC_MEM_CHECKOVERRUN
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#define ISC_MEM_CHECKOVERRUN 0
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#endif
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_CHECKOVERRUN
073bd4c4bcc2f2597521578dc6ae0f49a065626cMark Andrews#define ISC_MEM_CHECKOVERRUN 1
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEM_FILL=1 to fill each block of memory returned to the system
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * with the byte string '0xbe'. This helps track down uninitialized pointers
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * and the like. On freeing memory, the space is filled with '0xde' for
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff * the same reasons.
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews *
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews * If we are performing a Coverity static analysis then ISC_MEM_FILL
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews * can hide bugs that would otherwise discovered so force to zero.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#ifdef __COVERITY__
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#undef ISC_MEM_FILL
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#define ISC_MEM_FILL 0
b292230ab8dd33480dabad2b3615dcce5dd70c35Mark Andrews#endif
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEM_FILL
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#define ISC_MEM_FILL 1
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * name so that the leaking pool can be more readily identified in
18159f6f6053de21e433f2194ca4f89b96926c09Andreas Gustafsson * case of a memory leak.
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff */
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#ifndef ISC_MEMPOOL_NAMES
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#define ISC_MEMPOOL_NAMES 1
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
c4958494a98a59ce25e9fecad76a9ab0e36cc59fDanny MayerLIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging;
5a505fc4c2e99842052d9409790c7da0b5663bceMukund SivaramanLIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags;
5a505fc4c2e99842052d9409790c7da0b5663bceMukund Sivaraman
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define ISC_MEM_DEBUGTRACE 0x00000001U
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define ISC_MEM_DEBUGRECORD 0x00000002U
950d71eee32cb7c6ef9f659154f77bbf5a2cdce6Mark Andrews#define ISC_MEM_DEBUGUSAGE 0x00000004U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGSIZE 0x00000008U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGCTX 0x00000010U
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews#define ISC_MEM_DEBUGALL 0x0000001FU
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * The variable isc_mem_debugging holds a set of flags for
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * turning certain memory debugging options on or off at
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * runtime. It is initialized to the value ISC_MEM_DEGBUGGING,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * which is 0 by default but may be overridden at compile time.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * The following flags can be specified:
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGTRACE
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Log each allocation and free to isc_lctx.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGRECORD
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Remember each allocation, and match them up on free.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * Crash if a free doesn't match an allocation.
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \li #ISC_MEM_DEBUGUSAGE
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * If a hi_water mark is set, print the maximum inuse memory
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson * every time it is raised once it exceeds the hi_water mark.
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews *
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * \li #ISC_MEM_DEBUGSIZE
1425217e5c3a2cbab7f8344e600e0c16047289ffMark Andrews * Check the size argument being passed to isc_mem_put() matches
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * that passed to isc_mem_get().
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews *
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * \li #ISC_MEM_DEBUGCTX
1425217e5c3a2cbab7f8344e600e0c16047289ffMark Andrews * Check the mctx argument being passed to isc_mem_put() matches
d4d68515d23668cfe804ab2a174a7e427decedd8Mark Andrews * that passed to isc_mem_get().
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
c52e5c8ed1e2a3a90b912d3e4cb5da9dc32d85f7Andreas Gustafsson#if ISC_MEM_TRACKLINES
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FILELINE , __FILE__, __LINE__
5388178e8aa12c263286caa394491903cbf9806eMark Andrews#define _ISC_MEM_FLARG , const char *, unsigned int
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#else
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FILELINE
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define _ISC_MEM_FLARG
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#endif
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews/*!
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc()
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * implementation in preference to the system one. The internal malloc()
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * is very space-efficient, and quite fast on uniprocessor systems. It
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * performs poorly on multiprocessor machines.
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * JT: we can overcome the performance issue on multiprocessor machines
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * by carefully separating memory contexts.
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#ifndef ISC_MEM_USE_INTERNAL_MALLOC
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEM_USE_INTERNAL_MALLOC 1
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#endif
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉/*
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * Flags for isc_mem_create2()calls.
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 */
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉#define ISC_MEMFLAG_NOLOCK 0x00000001 /* no lock is necessary */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_INTERNAL 0x00000002 /* use internal malloc */
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#if ISC_MEM_USE_INTERNAL_MALLOC
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#else
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#define ISC_MEMFLAG_DEFAULT 0
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews#endif
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
457144a0c69e0aa242386f35498e41dc8bfc1610Tatuya JINMEI 神明達哉/*%<
457144a0c69e0aa242386f35498e41dc8bfc1610Tatuya JINMEI 神明達哉 * We use either isc___mem (three underscores) or isc__mem (two) depending on
457144a0c69e0aa242386f35498e41dc8bfc1610Tatuya JINMEI 神明達哉 * whether it's for BIND9's internal purpose (with -DBIND9) or generic export
166c4c6c5bafd25283b797979f77d780856fef30Evan Hunt * library.
457144a0c69e0aa242386f35498e41dc8bfc1610Tatuya JINMEI 神明達哉 */
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define ISCMEMFUNC(sfx) isc__mem_ ## sfx
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define ISCMEMPOOLFUNC(sfx) isc__mempool_ ## sfx
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define isc_mem_get(c, s) ISCMEMFUNC(get)((c), (s) _ISC_MEM_FILELINE)
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define isc_mem_allocate(c, s) ISCMEMFUNC(allocate)((c), (s) _ISC_MEM_FILELINE)
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define isc_mem_reallocate(c, p, s) ISCMEMFUNC(reallocate)((c), (p), (s) _ISC_MEM_FILELINE)
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define isc_mem_strdup(c, p) ISCMEMFUNC(strdup)((c), (p) _ISC_MEM_FILELINE)
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt#define isc_mempool_get(c) ISCMEMPOOLFUNC(get)((c) _ISC_MEM_FILELINE)
54ef500660da1f4e8d4e14e737fa81c4c881ac0aBrian Wellington
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater/*%
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * isc_mem_putanddetach() is a convenience function for use where you
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * have a structure with an attached memory context.
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * Given:
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \code
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * struct {
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * ...
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_t *mctx;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * ...
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * } *ptr;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_t *mctx;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_putanddetach(&ptr->mctx, ptr, sizeof(*ptr));
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \endcode
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * is the equivalent of:
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \code
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * mctx = NULL;
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_attach(ptr->mctx, &mctx);
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_detach(&ptr->mctx);
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_put(mctx, ptr, sizeof(*ptr));
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews * isc_mem_detach(&mctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \endcode
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews */
6c6bed90cb5b51a90530b7d488b2696626a8fafcMark Andrews
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*% memory and memory pool methods */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉typedef struct isc_memmethods {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*attach)(isc_mem_t *source, isc_mem_t **targetp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*detach)(isc_mem_t **mctxp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*destroy)(isc_mem_t **mctxp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void *(*memget)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*memput)(isc_mem_t *mctx, void *ptr, size_t size _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*memputanddetach)(isc_mem_t **mctxp, void *ptr,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 size_t size _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void *(*memallocate)(isc_mem_t *mctx, size_t size _ISC_MEM_FLARG);
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt void *(*memreallocate)(isc_mem_t *mctx, void *ptr,
e7c38ca9635e73c9a928bbab9c73c2abbd499f8bEvan Hunt size_t size _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 char *(*memstrdup)(isc_mem_t *mctx, const char *s _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*memfree)(isc_mem_t *mctx, void *ptr _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setdestroycheck)(isc_mem_t *mctx, isc_boolean_t flag);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setwater)(isc_mem_t *ctx, isc_mem_water_t water,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void *water_arg, size_t hiwater, size_t lowater);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*waterack)(isc_mem_t *ctx, int flag);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 size_t (*inuse)(isc_mem_t *mctx);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt size_t (*maxinuse)(isc_mem_t *mctx);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt size_t (*total)(isc_mem_t *mctx);
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 isc_boolean_t (*isovermem)(isc_mem_t *mctx);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_result_t (*mpcreate)(isc_mem_t *mctx, size_t size,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mempool_t **mpctxp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉} isc_memmethods_t;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉typedef struct isc_mempoolmethods {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*destroy)(isc_mempool_t **mpctxp);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void *(*get)(isc_mempool_t *mpctx _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*put)(isc_mempool_t *mpctx, void *mem _ISC_MEM_FLARG);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int (*getallocated)(isc_mempool_t *mpctx);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setmaxalloc)(isc_mempool_t *mpctx, unsigned int limit);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setfreemax)(isc_mempool_t *mpctx, unsigned int limit);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setname)(isc_mempool_t *mpctx, const char *name);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*associatelock)(isc_mempool_t *mpctx, isc_mutex_t *lock);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 void (*setfillcount)(isc_mempool_t *mpctx, unsigned int limit);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉} isc_mempoolmethods_t;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*%
823ca3c14f1596341bdd50707c01f3b529b75b4aAutomatic Updater * This structure is actually just the common prefix of a memory context
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * implementation's version of an isc_mem_t.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * \brief
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Direct use of this structure by clients is forbidden. mctx implementations
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * may change the structure. 'magic' must be ISCAPI_MCTX_MAGIC for any of the
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * isc_mem_ routines to work. mctx implementations must maintain all mctx
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * invariants.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉struct isc_mem {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int impmagic;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int magic;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_memmethods_t *methods;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉};
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#define ISCAPI_MCTX_MAGIC ISC_MAGIC('A','m','c','x')
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#define ISCAPI_MCTX_VALID(m) ((m) != NULL && \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 (m)->magic == ISCAPI_MCTX_MAGIC)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*%
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * This is the common prefix of a memory pool context. The same note as
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * that for the mem structure applies.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉struct isc_mempool {
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int impmagic;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 unsigned int magic;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mempoolmethods_t *methods;
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉};
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#define ISCAPI_MPOOL_MAGIC ISC_MAGIC('A','m','p','l')
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉#define ISCAPI_MPOOL_VALID(mp) ((mp) != NULL && \
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 (mp)->magic == ISCAPI_MPOOL_MAGIC)
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_put(c, p, s) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt ISCMEMFUNC(put)((c), (p), (s) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews#define isc_mem_putanddetach(c, p, s) \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews do { \
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt ISCMEMFUNC(putanddetach)((c), (p), (s) _ISC_MEM_FILELINE); \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews (p) = NULL; \
1162a4e02a6594dbb4f57fd288a5d20ab467e4d7Mark Andrews } while (0)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mem_free(c, p) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt ISCMEMFUNC(free)((c), (p) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff#define isc_mempool_put(c, p) \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff do { \
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan Hunt ISCMEMPOOLFUNC(put)((c), (p) _ISC_MEM_FILELINE); \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff (p) = NULL; \
bfab56849df65a2d4295b256808a66985cfa9d98Michael Graff } while (0)
138d22b316c7cd10eaa9df2ee0e3ec712a077153Bob Halley
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_create(size_t max_size, size_t target_size,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_mem_t **mctxp);
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_result_t
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_mem_create2(size_t max_size, size_t target_size,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 isc_mem_t **mctxp, unsigned int flags);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_createx(size_t max_size, size_t target_size,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_memalloc_t memalloc, isc_memfree_t memfree,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson void *arg, isc_mem_t **mctxp);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterisc_result_t
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉isc_mem_createx2(size_t max_size, size_t target_size,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 isc_memalloc_t memalloc, isc_memfree_t memfree,
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 void *arg, isc_mem_t **mctxp, unsigned int flags);
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief Create a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
1d625775ee265ec4d5237ae3a315789ad0957bd5Andreas Gustafsson * 'max_size' and 'target_size' are tuning parameters. When
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * ISC_MEMFLAG_INTERNAL is set, allocations smaller than 'max_size'
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * will be satisfied by getting blocks of size 'target_size' from the
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * system allocator and breaking them up into pieces; larger allocations
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * will use the system allocator directly. If 'max_size' and/or
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * 'target_size' are zero, default values will be * used. When
016c0a82f1ce3fe4d362d7c9cf8de4377ffaf5a9Mark Andrews * ISC_MEMFLAG_INTERNAL is not set, 'target_size' is ignored.
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews *
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews * 'max_size' is also used to size the statistics arrays and the array
f558c8988e776466f8ff3edc6a288d34dff75dc7Francis Dupont * used to record active memory when ISC_MEM_DEBUGRECORD is set. Setting
e0806ab5eda9add79044ccf17e55c49bae35d2e2Mark Andrews * 'max_size' too low can have detrimental effects on performance.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * A memory context created using isc_mem_createx() will obtain
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * memory from the system by calling 'memalloc' and 'memfree',
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * passing them the argument 'arg'. A memory context created
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * using isc_mem_create() will use the standard library malloc()
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * and free().
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * If ISC_MEMFLAG_NOLOCK is set in 'flags', the corresponding memory context
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * will be accessed without locking. The user who creates the context must
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * ensure there be no race. Since this can be a source of bug, it is generally
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * inadvisable to use this flag unless the user is very sure about the race
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 * condition and the access to the object is highly performance sensitive.
5597be9bb88de138dfec9fa9176708443813925eTatuya JINMEI 神明達哉 *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Requires:
1d625775ee265ec4d5237ae3a315789ad0957bd5Andreas Gustafsson * mctxp != NULL && *mctxp == NULL */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_attach(isc_mem_t *, isc_mem_t **);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_detach(isc_mem_t **);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * \brief Attach to / detach from a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * This is intended for applications that use multiple memory contexts
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * in such a way that it is not obvious when the last allocations from
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * a given context has been freed and destroying the context is safe.
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater *
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Most applications do not need to call these functions as they can
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * simply create a single memory context at the beginning of main()
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * and destroy it at the end of main(), thereby guaranteeing that it
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * is not destroyed while there are outstanding allocations.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_destroy(isc_mem_t **);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Destroy a memory context.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterisc_result_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_ondestroy(isc_mem_t *ctx,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_task_t *task,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_event_t **event);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Request to be notified with an event when a memory context has
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * been successfully destroyed.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_stats(isc_mem_t *mctx, FILE *out);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Print memory usage statistics for 'mctx' on the stream 'out'.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_setdestroycheck(isc_mem_t *mctx,
6d858e75d4f411e89485ec702ce1e118e1ead53cAndreas Gustafsson isc_boolean_t on);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein * If 'on' is ISC_TRUE, 'mctx' will check for memory leaks when
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * destroyed and abort the program if any are present.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@{*/
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_setquota(isc_mem_t *, size_t);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatersize_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_getquota(isc_mem_t *);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Set/get the memory quota of 'mctx'. This is a hard limit
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * on the amount of memory that may be allocated from mctx;
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * if it is exceeded, allocations will fail.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*@}*/
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatersize_t
8096fe1df5abfef957b934a1d1c5e97eaa246434Danny Mayerisc_mem_inuse(isc_mem_t *mctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Get an estimate of the amount of memory in use in 'mctx', in bytes.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * This includes quantization overhead, but does not include memory
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * allocated from the system but not yet used.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntsize_t
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntisc_mem_maxinuse(isc_mem_t *mctx);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt/*%<
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Get an estimate of the largest amount of memory that has been in
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * use in 'mctx' at any time.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt */
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntsize_t
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntisc_mem_total(isc_mem_t *mctx);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt/*%<
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * Get the total amount of memory in 'mctx', in bytes, including memory
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt * not yet used.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt */
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉isc_boolean_t
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉isc_mem_isovermem(isc_mem_t *mctx);
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉/*%<
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * Return true iff the memory context is in "over memory" state, i.e.,
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * a hiwater mark has been set and the used amount of memory has exceeds
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 * the mark.
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉 */
27fe1966c948ba0c1c9d0d831ea3d8bf32d052acTatuya JINMEI 神明達哉
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsvoid
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrewsisc_mem_setwater(isc_mem_t *mctx, isc_mem_water_t water, void *water_arg,
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews size_t hiwater, size_t lowater);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater * Set high and low water marks for this memory context.
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updater *
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * When the memory usage of 'mctx' exceeds 'hiwater',
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * '(water)(water_arg, #ISC_MEM_HIWATER)' will be called. 'water' needs to
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * call isc_mem_waterack() with #ISC_MEM_HIWATER to acknowledge the state
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * change. 'water' may be called multiple times.
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews *
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * When the usage drops below 'lowater', 'water' will again be called, this
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * time with #ISC_MEM_LOWATER. 'water' need to calls isc_mem_waterack() with
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * #ISC_MEM_LOWATER to acknowledge the change.
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews *
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * static void
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * water(void *arg, int mark) {
43581a71ab34a68227c4fc78b263cb7e09168f81Mark Andrews * struct foo *foo = arg;
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews *
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * LOCK(&foo->marklock);
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * if (foo->mark != mark) {
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * foo->mark = mark;
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * ....
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * isc_mem_waterack(foo->mctx, mark);
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * }
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * UNLOCK(&foo->marklock);
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews * }
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews *
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * If 'water' is NULL then 'water_arg', 'hi_water' and 'lo_water' are
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * ignored and the state is reset.
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence *
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews * Requires:
50a3152b7088546418c8edc0c89eeaf48560b035Andreas Gustafsson *
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * 'water' is not NULL.
65640f401a22971de16c01e9a9547d95c55ed45eDavid Lawrence * hi_water >= lo_water
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews */
3a34b87c878990c6303358efd22265c2c5980c65Mark Andrews
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrewsvoid
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrewsisc_mem_waterack(isc_mem_t *ctx, int mark);
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews/*%<
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * Called to acknowledge changes in signaled by calls to 'water'.
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews */
9a7d202077fae00fbdca610d8a8d90689e30f331Mark Andrews
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsvoid
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsisc_mem_printactive(isc_mem_t *mctx, FILE *file);
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews/*%<
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Print to 'file' all active memory in 'mctx'.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews *
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Requires ISC_MEM_DEBUGRECORD to have been set.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews */
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsvoid
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsisc_mem_printallactive(FILE *file);
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews/*%<
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Print to 'file' all active memory in all contexts.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews *
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Requires ISC_MEM_DEBUGRECORD to have been set.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews */
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsvoid
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrewsisc_mem_checkdestroyed(FILE *file);
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews/*%<
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Check that all memory contexts have been destroyed.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Prints out those that have not been.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews * Fatally fails if there are still active contexts.
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews */
e9733bc599f30033ffe7af69f5fca254fb59d46eMark Andrews
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrewsunsigned int
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrewsisc_mem_references(isc_mem_t *ctx);
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrews/*%<
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrews * Return the current reference count.
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrews */
f5d0f495847eb4eb9f0058e73051f855800bee0bMark Andrews
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsvoid
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsisc_mem_setname(isc_mem_t *ctx, const char *name, void *tag);
cffe96e26744abcf33494837b234219046a631d8Mark Andrews/*%<
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Name 'ctx'.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Notes:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li Only the first 15 characters of 'name' will be copied.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li 'tag' is for debugging purposes only.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Requires:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li 'ctx' is a valid ctx.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews */
cffe96e26744abcf33494837b234219046a631d8Mark Andrews
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsconst char *
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsisc_mem_getname(isc_mem_t *ctx);
cffe96e26744abcf33494837b234219046a631d8Mark Andrews/*%<
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Get the name of 'ctx', as previously set using isc_mem_setname().
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Requires:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li 'ctx' is a valid ctx.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Returns:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li A non-NULL pointer to a null-terminated string.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * If the ctx has not been named, the string is
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * empty.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews */
cffe96e26744abcf33494837b234219046a631d8Mark Andrews
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsvoid *
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsisc_mem_gettag(isc_mem_t *ctx);
cffe96e26744abcf33494837b234219046a631d8Mark Andrews/*%<
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Get the tag value for 'task', as previously set using isc_mem_setname().
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Requires:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li 'ctx' is a valid ctx.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Notes:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li This function is for debugging purposes only.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Requires:
cffe96e26744abcf33494837b234219046a631d8Mark Andrews *\li 'ctx' is a valid task.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews */
cffe96e26744abcf33494837b234219046a631d8Mark Andrews
cffe96e26744abcf33494837b234219046a631d8Mark Andrews#ifdef HAVE_LIBXML2
bbf31e6b623af575138669bdd7031232867b9166Mark Andrewsint
cffe96e26744abcf33494837b234219046a631d8Mark Andrewsisc_mem_renderxml(xmlTextWriterPtr writer);
cffe96e26744abcf33494837b234219046a631d8Mark Andrews/*%<
cffe96e26744abcf33494837b234219046a631d8Mark Andrews * Render all contexts' statistics and status in XML for writer.
cffe96e26744abcf33494837b234219046a631d8Mark Andrews */
cffe96e26744abcf33494837b234219046a631d8Mark Andrews#endif /* HAVE_LIBXML2 */
cffe96e26744abcf33494837b234219046a631d8Mark Andrews
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt#ifdef HAVE_JSON
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Huntisc_result_t
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Huntisc_mem_renderjson(json_object *memobj);
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt/*%<
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt * Render all contexts' statistics and status in JSON.
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt */
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt#endif /* HAVE_JSON */
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt
feb067b25a8e33db62e2a7bf2e83bbb7f6eee845Evan Hunt
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff/*
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff * Memory pools
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_result_t
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_create(isc_mem_t *mctx, size_t size, isc_mempool_t **mpctxp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Create a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mctx is a valid memory context.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li size > 0
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctxp != NULL and *mpctxp == NULL
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Defaults:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li maxalloc = UINT_MAX
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li freemax = 1
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li fillcount = 1
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_NOMEMORY -- not enough memory to create pool
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li #ISC_R_SUCCESS -- all is well.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffvoid
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_destroy(isc_mempool_t **mpctxp);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Destroy a memory pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctxp != NULL && *mpctxp is a valid pool.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li The pool has no un"put" allocations outstanding
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graffvoid
87cafc5e70f79f2586d067fbdd64f61bbab069d2David Lawrenceisc_mempool_setname(isc_mempool_t *mpctx, const char *name);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff * Associate a name with a memory pool. At most 15 characters may be used.
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff *
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff * Requires:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctx is a valid pool.
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li name != NULL;
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff */
78b2f25c9afee0d16f2e75882d9763abcb0872e5Michael Graff
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffvoid
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graffisc_mempool_associatelock(isc_mempool_t *mpctx, isc_mutex_t *lock);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * Associate a lock with this memory pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * This lock is used when getting or putting items using this memory pool,
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * and it is also used to set or get internal state via the isc_mempool_get*()
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * and isc_mempool_set*() set of functions.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
0ef59d22882fc5d28f4683fdbe88aefd8eaad6f3Francis Dupont * Multiple pools can each share a single lock. For instance, if "manager"
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * type object contained pools for various sizes of events, and each of
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * these pools used a common lock. Note that this lock must NEVER be used
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * by other than mempool routines once it is given to a pool, since that can
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * easily cause double locking.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * Requires:
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li mpctpx is a valid pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li lock != NULL.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li No previous lock is assigned to this pool.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff *
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li The lock is initialized before calling this function via the normal
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff * means of doing that.
50dfb7ee4ada4c9aa30bd18c1b5d9b04be765669Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff/*
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * The following functions get/set various parameters. Note that due to
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the unlocked nature of pools these are potentially random values unless
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the imposed externally provided locking protocols are followed.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Also note that the quota limits will not always take immediate effect.
0fd03d2a66102f8d9bd7acea4e7db73ecaa0cb52Michael Graff * For instance, setting "maxalloc" to a number smaller than the currently
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * allocated count is permitted. New allocations will be refused until
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * the count drops below this threshold.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * All functions require (in addition to other requirements):
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * mpctx is a valid memory pool
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfreemax(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setfreemax(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfreecount(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns current size of the free list.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getmaxalloc(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*!<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setmaxalloc(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the maximum allowed number of allocations.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li limit > 0
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getallocated(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the number of items allocated from this pool.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceunsigned int
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_getfillcount(isc_mempool_t *mpctx);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Returns the number of items allocated as a block from the parent memory
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * context when the free list is empty.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrencevoid
c7f22f83aac9e61dafee191cad040e9c42652cc8David Lawrenceisc_mempool_setfillcount(isc_mempool_t *mpctx, unsigned int limit);
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*%<
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Sets the fillcount.
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff *
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff * Additional requirements:
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein *\li limit > 0
f28a94af2179ff7592d732e409d006582e9af7c3Michael Graff */
eb7ef395d27b1104f684e21836f200c052736d07Michael Graff
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson/*
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson * Pseudo-private functions for use via macros. Do not call directly.
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson */
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid *
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(get)(isc_mem_t *, size_t _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(putanddetach)(isc_mem_t **, void *, size_t _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(put)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid *
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(allocate)(isc_mem_t *, size_t _ISC_MEM_FLARG);
77d90dc2b51e672111be97e7920862c97f446c4dTatuya JINMEI 神明達哉void *
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(reallocate)(isc_mem_t *, void *, size_t _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(free)(isc_mem_t *, void * _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updaterchar *
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMFUNC(strdup)(isc_mem_t *, const char *_ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid *
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMPOOLFUNC(get)(isc_mempool_t * _ISC_MEM_FLARG);
2f012d936b5ccdf6520c96a4de23721dc58a2221Automatic Updatervoid
82629edf81d6ce977440eb5ce3314cdeb0fa14daEvan HuntISCMEMPOOLFUNC(put)(isc_mempool_t *, void * _ISC_MEM_FLARG);
c674a8d5e7d202ada2bb617e5bb98b1859dc5a62Andreas Gustafsson
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*%<
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * See isc_mem_create2() above.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉typedef isc_result_t
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉(*isc_memcreatefunc_t)(size_t init_max_size, size_t target_size,
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 isc_mem_t **ctxp, unsigned int flags);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉isc_result_t
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉isc_mem_register(isc_memcreatefunc_t createfunc);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*%<
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * Register a new memory management implementation and add it to the list of
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * supported implementations. This function must be called when a different
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * memory management library is used than the one contained in the ISC library.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉isc_result_t
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉isc__mem_register(void);
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉/*%<
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * A short cut function that specifies the memory management module in the ISC
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * library for isc_mem_register(). An application that uses the ISC library
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * usually do not have to care about this function: it would call
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 * isc_lib_register(), which internally calls this function.
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉 */
307d2084502eddc7ce921e5ce439aec3531d90e0Tatuya JINMEI 神明達哉
7aacbd685b2107670e4179689abec9cb82d972abBob HalleyISC_LANG_ENDDECLS
7aacbd685b2107670e4179689abec9cb82d972abBob Halley
54a2e7e8a21ee765f41bd995101995613bff9e8cDavid Lawrence#endif /* ISC_MEM_H */