1 /* 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 #pragma once 30 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 // uint8_t data (Optional: Front guard, will be a multiple of MINIMUM_ALIGNMENT_BYTES) 41 // allocation data 42 // uint8_t data (Optional: End guard) 43 // 44 // 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. 47 struct Header { 48 uint32_t tag; 49 void* orig_pointer; 50 size_t size; 51 size_t usable_size; 52 } __attribute__((packed)); 53 54 struct BacktraceHeader { 55 size_t num_frames; 56 uintptr_t frames[0]; 57 } __attribute__((packed)); 58 59 constexpr uint32_t DEBUG_TAG = 0x1ee7d00d; 60 constexpr uint32_t DEBUG_FREE_TAG = 0x1cc7dccd; 61 constexpr char LOG_DIVIDER[] = "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***"; 62 constexpr size_t FREE_TRACK_MEM_BUFFER_SIZE = 4096; 63 64 extern const MallocDispatch* g_dispatch; 65