blob: 7280ea7b72669a44f0f73ca17ba845aae60741c2 [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
Elliott Hughescbc80ba2018-02-13 14:26:29 -080029#pragma once
Christopher Ferris63860cb2015-11-16 17:30:32 -080030
31#include <stdint.h>
32
33#include <private/bionic_malloc_dispatch.h>
34
35// Allocations that require a header include a variable length header.
36// This is the order that data structures will be found. If an optional
37// part of the header does not exist, the other parts of the header
38// will still be in this order.
39// Header (Required)
Christopher Ferris72df6702016-02-11 15:51:31 -080040// uint8_t data (Optional: Front guard, will be a multiple of MINIMUM_ALIGNMENT_BYTES)
Christopher Ferris63860cb2015-11-16 17:30:32 -080041// allocation data
42// uint8_t data (Optional: End guard)
43//
Christopher Ferris63860cb2015-11-16 17:30:32 -080044// In the initialization function, offsets into the header will be set
45// for each different header location. The offsets are always from the
46// beginning of the Header section.
47struct Header {
48 uint32_t tag;
49 void* orig_pointer;
50 size_t size;
51 size_t usable_size;
Christopher Ferris63860cb2015-11-16 17:30:32 -080052} __attribute__((packed));
53
Christopher Ferris63860cb2015-11-16 17:30:32 -080054struct BacktraceHeader {
55 size_t num_frames;
56 uintptr_t frames[0];
57} __attribute__((packed));
58
59constexpr uint32_t DEBUG_TAG = 0x1ee7d00d;
Christopher Ferris7993b802016-01-28 18:35:05 -080060constexpr uint32_t DEBUG_FREE_TAG = 0x1cc7dccd;
Christopher Ferris63860cb2015-11-16 17:30:32 -080061constexpr char LOG_DIVIDER[] = "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***";
62constexpr size_t FREE_TRACK_MEM_BUFFER_SIZE = 4096;
63
64extern const MallocDispatch* g_dispatch;
Christopher Ferris93bdd6a2018-04-05 11:12:38 -070065
66void BacktraceAndLog();