📄 mpatrol.h
字号:
#ifndef MP_MPATROL_H#define MP_MPATROL_H/* * mpatrol * A library for controlling and tracing dynamic memory allocations. * Copyright (C) 1997-2002 Graeme S. Roy <graeme.roy@analog.com> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307, USA. *//* * $Id: mpatrol.h,v 1.141 2002/01/08 22:29:59 graeme Exp $ */#include <stdlib.h>#include <string.h>#include <stdarg.h>#if !MP_NOCPLUSPLUS#ifdef __cplusplus#include <new>#endif /* __cplusplus */#endif /* MP_NOCPLUSPLUS */#ifdef NDEBUG#include <mpalloc.h>#endif /* NDEBUG *//* The version of the mpatrol library. The version is of the format vrrff, * where v represents the version number, rr represents the revision number * and ff represents the bug fix count. */#define MPATROL_VERSION 10408/* A macro for representing constant function parameters. */#ifndef MP_CONST#if defined(__STDC__) || defined(__cplusplus)#define MP_CONST const#else /* __STDC__ && __cplusplus */#define MP_CONST#endif /* __STDC__ && __cplusplus */#endif /* MP_CONST *//* A macro for representing a volatile object that may not have any loads * from it or stores to it optimised away. */#ifndef MP_VOLATILE#if defined(__STDC__) || defined(__cplusplus)#define MP_VOLATILE volatile#else /* __STDC__ && __cplusplus */#define MP_VOLATILE#endif /* __STDC__ && __cplusplus */#endif /* MP_VOLATILE *//* A macro for determining the alignment of a type at compile-time. * This resolves to 0 if the compiler has no mechanism for doing this. */#ifndef MP_ALIGN#ifdef __EDG__#define MP_ALIGN(t) __ALIGNOF__(t)#elif defined(__GNUC__)#define MP_ALIGN(t) __alignof__(t)#else /* __EDG__ && __GNUC__ */#define MP_ALIGN(t) 0#endif /* __EDG__ && __GNUC__ */#endif /* MP_ALIGN *//* A macro for determining the current function name. */#ifndef MP_FUNCNAME#if defined(__STDC_VERSION__) && (__STDC_VERSION__ == 199901L)#define MP_FUNCNAME __func__#elif defined(__GNUC__)#define MP_FUNCNAME __PRETTY_FUNCTION__#else /* __STDC_VERSION__ && __GNUC__ */#define MP_FUNCNAME NULL#endif /* __STDC_VERSION__ && __GNUC__ */#endif /* MP_FUNCNAME *//* A macro for defining the visibility of the inline C++ operators. This * should be extern inline so that there is no non-inline definition, but * most compilers do not support this concept yet. */#ifndef MP_INLINE#ifdef __GNUC__#define MP_INLINE extern inline#else /* __GNUC__ */#define MP_INLINE static inline#endif /* __GNUC__ */#endif /* MP_INLINE *//* A macro for disabling the definition of replacement C++ operators. */#ifndef MP_NOCPLUSPLUS#define MP_NOCPLUSPLUS 0#endif /* MP_NOCPLUSPLUS *//* A macro for requiring the use of MP_NEW and MP_DELETE instead of new * and delete in order to use the mpatrol versions of the C++ operators. */#ifndef MP_NONEWDELETE#define MP_NONEWDELETE 0#endif /* MP_NONEWDELETE *//* Options for backwards compatibility with other versions of mallopt(). They * are all currently ignored as they have no meaning when used with mpatrol. */#ifdef M_MXFAST#undef M_MXFAST#endif /* M_MXFAST */#ifdef M_NLBLKS#undef M_NLBLKS#endif /* M_NLBLKS */#ifdef M_GRAIN#undef M_GRAIN#endif /* M_GRAIN */#ifdef M_KEEP#undef M_KEEP#endif /* M_KEEP */#ifdef M_TRIM_THRESHOLD#undef M_TRIM_THRESHOLD#endif /* M_TRIM_THRESHOLD */#ifdef M_TOP_PAD#undef M_TOP_PAD#endif /* M_TOP_PAD */#ifdef M_MMAP_THRESHOLD#undef M_MMAP_THRESHOLD#endif /* M_MMAP_THRESHOLD */#ifdef M_MMAP_MAX#undef M_MMAP_MAX#endif /* M_MMAP_MAX */#ifdef M_CHECK_ACTION#undef M_CHECK_ACTION#endif /* M_CHECK_ACTION */#define M_MXFAST 1#define M_NLBLKS 2#define M_GRAIN 3#define M_KEEP 4#define M_TRIM_THRESHOLD 5#define M_TOP_PAD 6#define M_MMAP_THRESHOLD 7#define M_MMAP_MAX 8#define M_CHECK_ACTION 9/* Options that can be set using mallopt(). They all correspond to their * environment variable option equivalent except for MP_OPT_SETFLAGS and * MP_OPT_UNSETFLAGS. */#define MP_OPT_HELP 0#define MP_OPT_SETFLAGS -1#define MP_OPT_UNSETFLAGS -2#define MP_OPT_ALLOCSTOP -3#define MP_OPT_REALLOCSTOP -4#define MP_OPT_FREESTOP -5#define MP_OPT_ALLOCBYTE -6#define MP_OPT_FREEBYTE -7#define MP_OPT_OFLOWBYTE -8#define MP_OPT_OFLOWSIZE -9#define MP_OPT_DEFALIGN -10#define MP_OPT_LIMIT -11#define MP_OPT_FAILFREQ -12#define MP_OPT_FAILSEED -13#define MP_OPT_UNFREEDABORT -14#define MP_OPT_LOGFILE -15#define MP_OPT_PROFFILE -16#define MP_OPT_TRACEFILE -17#define MP_OPT_PROGFILE -18#define MP_OPT_AUTOSAVE -19#define MP_OPT_CHECKLOWER -20#define MP_OPT_CHECKUPPER -21#define MP_OPT_CHECKFREQ -22#define MP_OPT_NOFREE -23#define MP_OPT_SMALLBOUND -24#define MP_OPT_MEDIUMBOUND -25#define MP_OPT_LARGEBOUND -26/* Flags that can be set or unset using mallopt() and MP_OPT_SETFLAGS or * MP_OPT_UNSETFLAGS respectively. They all correspond to their environment * variable option equivalent except for MP_FLG_PAGEALLOC and MP_FLG_ALLOCUPPER. */#define MP_FLG_CHECKALL (MP_FLG_CHECKALLOCS | MP_FLG_CHECKREALLOCS | \ MP_FLG_CHECKFREES | MP_FLG_CHECKMEMORY)#define MP_FLG_CHECKALLOCS 0x00000001#define MP_FLG_CHECKREALLOCS 0x00000002#define MP_FLG_CHECKFREES 0x00000004#define MP_FLG_CHECKMEMORY 0x00000008#define MP_FLG_LOGALL (MP_FLG_LOGALLOCS | MP_FLG_LOGREALLOCS | \ MP_FLG_LOGFREES | MP_FLG_LOGMEMORY)#define MP_FLG_LOGALLOCS 0x00000010#define MP_FLG_LOGREALLOCS 0x00000020#define MP_FLG_LOGFREES 0x00000040#define MP_FLG_LOGMEMORY 0x00000080#define MP_FLG_SHOWALL (MP_FLG_SHOWMAP | MP_FLG_SHOWSYMBOLS | \ MP_FLG_SHOWFREE | MP_FLG_SHOWFREED | \ MP_FLG_SHOWUNFREED)#define MP_FLG_SHOWMAP 0x00000100#define MP_FLG_SHOWSYMBOLS 0x00000200#define MP_FLG_SHOWFREE 0x00000400#define MP_FLG_SHOWFREED 0x00000800#define MP_FLG_SHOWUNFREED 0x00001000#define MP_FLG_LEAKTABLE 0x00002000#define MP_FLG_ALLOWOFLOW 0x00004000#define MP_FLG_PROF 0x00008000#define MP_FLG_TRACE 0x00010000#define MP_FLG_SAFESIGNALS 0x00020000#define MP_FLG_NOPROTECT 0x00040000#define MP_FLG_CHECKFORK 0x00080000#define MP_FLG_PRESERVE 0x00100000#define MP_FLG_OFLOWWATCH 0x00200000#define MP_FLG_PAGEALLOC 0x00400000#define MP_FLG_ALLOCUPPER 0x00800000#define MP_FLG_USEMMAP 0x01000000#define MP_FLG_USEDEBUG 0x02000000#define MP_FLG_EDIT 0x04000000#define MP_FLG_LIST 0x08000000#define MP_FLG_HTML 0x10000000/* The various options and flags that can be passed to __mp_leaktable(). * Only one of the options must be passed as its second parameter and any * combination of the flags can be passed as its third parameter. */#define MP_LT_ALLOCATED 0#define MP_LT_FREED 1#define MP_LT_UNFREED 2#define MP_LT_COUNTS 1#define MP_LT_BOTTOM 2#ifndef MP_MPALLOC_H/* The type of the allocation failure handler. This is only defined if * mpalloc.h has not already been included. */typedef void *__mp_failhandler;#endif /* MP_MPALLOC_H *//* The types of the prologue, epilogue and low memory handlers. */typedef void (*__mp_prologuehandler)(MP_CONST void *, size_t, size_t, MP_CONST char *, MP_CONST char *, unsigned long, MP_CONST void *);typedef void (*__mp_epiloguehandler)(MP_CONST void *, MP_CONST char *, MP_CONST char *, unsigned long, MP_CONST void *);typedef void (*__mp_nomemoryhandler)(MP_CONST char *, MP_CONST char *, unsigned long, MP_CONST void *);/* The different types of warnings and errors reported by the mpatrol library. */typedef enum __mp_errortype{ MP_ET_NONE, /* no error */ MP_ET_ALLOVF, /* allocation overflow */ MP_ET_ALLZER, /* allocation too small */ MP_ET_BADALN, /* illegal alignment */ MP_ET_FRDCOR, /* freed memory corruption */ MP_ET_FRDOPN, /* illegal operation on freed memory */ MP_ET_FRDOVF, /* freed allocation overflow */ MP_ET_FRECOR, /* free memory corruption */ MP_ET_FREMRK, /* freeing a marked allocation */ MP_ET_FRENUL, /* freeing a NULL pointer */ MP_ET_FREOPN, /* illegal operation on free memory */ MP_ET_ILLMEM, /* illegal memory access */ MP_ET_INCOMP, /* incompatible functions */ MP_ET_MAXALN, /* alignment too large */ MP_ET_MISMAT, /* allocated pointer mismatch */ MP_ET_NOTALL, /* no such allocation */ MP_ET_NULOPN, /* illegal operation on a NULL pointer */ MP_ET_OUTMEM, /* out of memory */ MP_ET_PRVFRD, /* allocation already freed */ MP_ET_RNGOVF, /* range overflow */ MP_ET_RNGOVL, /* range overlap */ MP_ET_RSZNUL, /* reallocating a NULL pointer */ MP_ET_RSZZER, /* reallocation too small */ MP_ET_STROVF, /* string overflow */ MP_ET_ZERALN, /* alignment too small */ MP_ET_MAX}__mp_errortype;/* The different types of memory allocation and operation functions. */typedef enum __mp_alloctype{ MP_AT_MALLOC, /* malloc() */ MP_AT_CALLOC, /* calloc() */ MP_AT_MEMALIGN, /* memalign() */ MP_AT_VALLOC, /* valloc() */ MP_AT_PVALLOC, /* pvalloc() */ MP_AT_ALLOCA, /* alloca() */ MP_AT_STRDUP, /* strdup() */ MP_AT_STRNDUP, /* strndup() */ MP_AT_STRSAVE, /* strsave() */ MP_AT_STRNSAVE, /* strnsave() */ MP_AT_STRDUPA, /* strdupa() */ MP_AT_STRNDUPA, /* strndupa() */ MP_AT_REALLOC, /* realloc() */ MP_AT_REALLOCF, /* reallocf() */ MP_AT_RECALLOC, /* recalloc() */ MP_AT_EXPAND, /* expand() */ MP_AT_FREE, /* free() */ MP_AT_CFREE, /* cfree() */ MP_AT_DEALLOCA, /* dealloca() */ MP_AT_XMALLOC, /* xmalloc() */ MP_AT_XCALLOC, /* xcalloc() */ MP_AT_XSTRDUP, /* xstrdup() */ MP_AT_XREALLOC, /* xrealloc() */ MP_AT_XFREE, /* xfree() */ MP_AT_NEW, /* operator new */ MP_AT_NEWVEC, /* operator new[] */ MP_AT_DELETE, /* operator delete */ MP_AT_DELETEVEC, /* operator delete[] */ MP_AT_MEMSET, /* memset() */ MP_AT_BZERO, /* bzero() */ MP_AT_MEMCCPY, /* memccpy() */ MP_AT_MEMCPY, /* memcpy() */ MP_AT_MEMMOVE, /* memmove() */ MP_AT_BCOPY, /* bcopy() */ MP_AT_MEMCHR, /* memchr() */ MP_AT_MEMMEM, /* memmem() */ MP_AT_MEMCMP, /* memcmp() */ MP_AT_BCMP, /* bcmp() */ MP_AT_MAX}__mp_alloctype;/* The details of a single function in a call stack. */typedef struct __mp_allocstack{ struct __mp_allocstack *next; /* next address node in call stack */ char *name; /* name of function */ void *addr; /* return address in function */}__mp_allocstack;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -