blob: ac620adfe5e882bb66cdf62859907a053f458a78 [file] [log] [blame]
Christopher Ferris63860cb2015-11-16 17:30:32 -08001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29#ifndef MALLOC_DEBUG_CONFIG_H
30#define MALLOC_DEBUG_CONFIG_H
31
32#include <stdint.h>
33
Christopher Ferris7bd01782016-04-20 12:30:58 -070034#include <string>
35
Christopher Ferris63860cb2015-11-16 17:30:32 -080036constexpr uint64_t FRONT_GUARD = 0x1;
37constexpr uint64_t REAR_GUARD = 0x2;
38constexpr uint64_t BACKTRACE = 0x4;
39constexpr uint64_t FILL_ON_ALLOC = 0x8;
40constexpr uint64_t FILL_ON_FREE = 0x10;
41constexpr uint64_t EXPAND_ALLOC = 0x20;
42constexpr uint64_t FREE_TRACK = 0x40;
43constexpr uint64_t TRACK_ALLOCS = 0x80;
44constexpr uint64_t LEAK_TRACK = 0x100;
Christopher Ferris7bd01782016-04-20 12:30:58 -070045constexpr uint64_t RECORD_ALLOCS = 0x200;
Christopher Ferris63860cb2015-11-16 17:30:32 -080046
Christopher Ferris72df6702016-02-11 15:51:31 -080047// In order to guarantee posix compliance, set the minimum alignment
48// to 8 bytes for 32 bit systems and 16 bytes for 64 bit systems.
49#if defined(__LP64__)
50constexpr size_t MINIMUM_ALIGNMENT_BYTES = 16;
51#else
52constexpr size_t MINIMUM_ALIGNMENT_BYTES = 8;
53#endif
54
Christopher Ferris55a89a42016-04-07 17:14:53 -070055// If one or more of these options is set, then a special header is needed.
56constexpr uint64_t HEADER_OPTIONS = FRONT_GUARD | REAR_GUARD | BACKTRACE | FREE_TRACK | LEAK_TRACK;
Christopher Ferris63860cb2015-11-16 17:30:32 -080057
58struct Config {
59 bool SetFromProperties();
60
61 size_t front_guard_bytes = 0;
62 size_t rear_guard_bytes = 0;
63
64 bool backtrace_enable_on_signal = false;
65 int backtrace_signal = 0;
66 bool backtrace_enabled = false;
67 size_t backtrace_frames = 0;
68
69 size_t fill_on_alloc_bytes = 0;
70 size_t fill_on_free_bytes = 0;
71
72 size_t expand_alloc_bytes = 0;
73
74 size_t free_track_allocations = 0;
Christopher Ferris7993b802016-01-28 18:35:05 -080075 size_t free_track_backtrace_num_frames = 0;
Christopher Ferris63860cb2015-11-16 17:30:32 -080076
Christopher Ferris7bd01782016-04-20 12:30:58 -070077 int record_allocs_signal = 0;
78 size_t record_allocs_num_entries = 0;
79 std::string record_allocs_file;
80
Christopher Ferris63860cb2015-11-16 17:30:32 -080081 uint64_t options = 0;
82 uint8_t fill_alloc_value;
83 uint8_t fill_free_value;
84 uint8_t front_guard_value;
85 uint8_t rear_guard_value;
86};
87
88#endif // MALLOC_DEBUG_CONFIG_H