libsir 2.2.5
Standard Incident Reporter
Loading...
Searching...
No Matches
tests_malloc.h
1/*
2 * tests_malloc.h
3 *
4 * Version: 2.2.5
5 *
6 * ----------------------------------------------------------------------------
7 *
8 * SPDX-License-Identifier: MIT
9 *
10 * Copyright (c) 2018-2024 Jeffrey H. Johnson <trnsz@pobox.com>
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a copy of
13 * this software and associated documentation files (the "Software"), to deal in
14 * the Software without restriction, including without limitation the rights to
15 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
16 * the Software, and to permit persons to whom the Software is furnished to do so,
17 * subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included in all
20 * copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
24 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
25 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 *
29 * -----------------------------------------------------------------------------
30 */
31
32#ifndef _SIR_TESTS_MALLOC_H_INCLUDED
33# define _SIR_TESTS_MALLOC_H_INCLUDED
34
35# if defined(MTMALLOC)
36# include <mtmalloc.h>
37# if !defined(DEBUG)
38mallocctl(MTDOUBLEFREE, 0);
39# else
40mallocctl(MTDOUBLEFREE, 1);
41mallocctl(MTINITBUFFER, 1);
42mallocctl(MTDEBUGPATTERN, 1);
43# endif
44# endif
45
46# if !defined(DEBUG_MALLOC_FILL_BYTE)
47# define DEBUG_MALLOC_FILL_BYTE 0x2E
48# endif
49
50# if defined(DUMA)
51# if defined(DUMA_EXPLICIT_INIT)
52duma_init();
53# endif
54# if defined(DUMA_MIN_ALIGNMENT)
55# if DUMA_MIN_ALIGNMENT > 0
56DUMA_SET_ALIGNMENT(DUMA_MIN_ALIGNMENT);
57# endif
58# endif
59DUMA_SET_FILL(DEBUG_MALLOC_FILL_BYTE);
60# endif
61
62# if defined(DEBUG)
63# if defined(__GLIBC__)
64# if !defined(_GNU_SOURCE)
65# define _GNU_SOURCE 1
66# endif
67# if !defined(DUMA)
68# include <malloc.h>
69# endif
70# if GLIBC_VERSION >= 20400 && defined(M_PERTURB)
71mallopt(M_PERTURB, DEBUG_MALLOC_FILL_BYTE);
72# endif
73# if defined(M_CHECK_ACTION)
74mallopt(M_CHECK_ACTION, 3);
75# endif
76# endif
77# endif
78
79# if defined(__WIN__) && defined(DEBUG) && defined(_DEBUG)
80# if defined(_CRTDBG_CHECK_ALWAYS_DF) && \
81 defined(_CRTDBG_DELAY_FREE_MEM_DF) && \
82 defined(_CRTDBG_LEAK_CHECK_DF)
83_CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
84# endif
85# endif
86
87#endif /* !_SIR_TESTS_MALLOC_H_INCLUDED */