blob: 18a6c2c7f71c4ffa7fc5649d80b43dc5dd80f065 [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)
40// BacktraceHeader (Optional: For the allocation backtrace)
Christopher Ferris72df6702016-02-11 15:51:31 -080041// uint8_t data (Optional: Front guard, will be a multiple of MINIMUM_ALIGNMENT_BYTES)
Christopher Ferris63860cb2015-11-16 17:30:32 -080042// allocation data
43// uint8_t data (Optional: End guard)
44//
45// If backtracing is enabled, then both BacktraceHeaders will be present.
46//
47// In the initialization function, offsets into the header will be set
48// for each different header location. The offsets are always from the
49// beginning of the Header section.
50struct Header {
51 uint32_t tag;
52 void* orig_pointer;
53 size_t size;
54 size_t usable_size;
55 size_t real_size() const { return size & ~(1U << 31); }
Christopher Ferris602b88c2017-08-04 13:04:04 -070056 void set_zygote_child_alloc() { size |= 1U << 31; }
57 bool zygote_child_alloc() const { return size & (1U << 31); }
Christopher Ferris63860cb2015-11-16 17:30:32 -080058 static size_t max_size() { return (1U << 31) - 1; }
59} __attribute__((packed));
60
Christopher Ferris63860cb2015-11-16 17:30:32 -080061struct BacktraceHeader {
62 size_t num_frames;
63 uintptr_t frames[0];
64} __attribute__((packed));
65
66constexpr uint32_t DEBUG_TAG = 0x1ee7d00d;
Christopher Ferris7993b802016-01-28 18:35:05 -080067constexpr uint32_t DEBUG_FREE_TAG = 0x1cc7dccd;
Christopher Ferris63860cb2015-11-16 17:30:32 -080068constexpr char LOG_DIVIDER[] = "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***";
69constexpr size_t FREE_TRACK_MEM_BUFFER_SIZE = 4096;
70
71extern const MallocDispatch* g_dispatch;