1 /* Copyright (C) 2007-2010 The Android Open Source Project 2 ** 3 ** This software is licensed under the terms of the GNU General Public 4 ** License version 2, as published by the Free Software Foundation, and 5 ** may be copied, distributed, and modified under those terms. 6 ** 7 ** This program is distributed in the hope that it will be useful, 8 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ** GNU General Public License for more details. 11 */ 12 13 /* 14 * Contains declarations of structures and routines that implement a red-black 15 * tree (a map) of module memory mapping ranges in the guest system. The map is 16 * organized in such a way, that each entry in the map describes a virtual 17 * address range that belongs to a mapped execution module in the guest system. 18 * Map considers two ranges to be equal if their address ranges intersect in 19 * any part. 20 */ 21 22 #ifndef QEMU_MEMCHECK_MEMCHECK_MMRANGE_MAP_H 23 #define QEMU_MEMCHECK_MEMCHECK_MMRANGE_MAP_H 24 25 /* This file should compile iff qemu is built with memory checking 26 * configuration turned on. */ 27 #ifndef CONFIG_MEMCHECK 28 #error CONFIG_MEMCHECK is not defined. 29 #endif // CONFIG_MEMCHECK 30 31 #include "sys-tree.h" 32 #include "memcheck_common.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 /* Memory mapping range map. */ 39 typedef struct MMRangeMap { 40 /* Head of the map. */ 41 struct MMRangeMapEntry* rbh_root; 42 } MMRangeMap; 43 44 // ============================================================================= 45 // Map API 46 // ============================================================================= 47 48 /* Initializes the map. 49 * Param: 50 * map - Map to initialize. 51 */ 52 void mmrangemap_init(MMRangeMap* map); 53 54 /* Inserts new (or replaces existing) entry in the map. 55 * Insertion, or replacement is controlled by the value, passed to this routine 56 * with 'replaced' parameter. If this parameter is NULL, insertion will fail if 57 * a matching entry already exists in the map. If 'replaced' parameter is not 58 * NULL, and a matching entry exists in the map, content of the existing entry 59 * will be copied to the descriptor, addressed by 'replace' parameter, existing 60 * entry will be removed from the map, and new entry will be inserted. 61 * Param: 62 * map - Map where to insert new, or replace existing entry. 63 * desc - Descriptor to insert to the map. 64 * replaced - If not NULL, upon return from this routine contains descriptor 65 * that has been replaced in the map with the new entry. Note that if this 66 * routine returns with value other than RBT_MAP_RESULT_ENTRY_REPLACED, 67 * content of the 'replaced' buffer is not defined, as no replacement has 68 * actually occurred. 69 * Return 70 * See RBTMapResult for the return codes. 71 */ 72 RBTMapResult mmrangemap_insert(MMRangeMap* map, 73 const MMRangeDesc* desc, 74 MMRangeDesc* replaced); 75 76 /* Finds an entry in the map that matches the given address. 77 * Param: 78 * map - Map where to search for an entry. 79 * start - Starting address of a mapping range. 80 * end - Ending address of a mapping range. 81 * Return: 82 * Pointer to the descriptor found in a map entry, or NULL if no matching 83 * entry has been found in the map. 84 */ 85 MMRangeDesc* mmrangemap_find(const MMRangeMap* map, 86 target_ulong start, 87 target_ulong end); 88 89 /* Pulls (finds and removes) an entry from the map that matches the given 90 * address. 91 * Param: 92 * map - Map where to search for an entry. 93 * start - Starting address of a mapping range. 94 * end - Ending address of a mapping range. 95 * pulled - Upon successful return contains descriptor data pulled from the 96 * map. 97 * Return: 98 * Zero if a descriptor that matches the given address has been pulled, or 1 99 * if no matching entry has been found in the map. 100 */ 101 int mmrangemap_pull(MMRangeMap* map, 102 target_ulong start, 103 target_ulong end, 104 MMRangeDesc* pulled); 105 106 /* Copies content of one memory map to another. 107 * Param: 108 * to - Map where to copy entries to. 109 * from - Map where to copy entries from. 110 * Return: 111 * Zero on success, or -1 on error. 112 */ 113 int mmrangemap_copy(MMRangeMap* to, const MMRangeMap* from); 114 115 /* Empties the map. 116 * Param: 117 * map - Map to empty. 118 * Return: 119 * Number of entries removed from the map. 120 */ 121 int mmrangemap_empty(MMRangeMap* map); 122 123 #ifdef __cplusplus 124 }; /* end of extern "C" */ 125 #endif 126 127 #endif // QEMU_MEMCHECK_MEMCHECK_MMRANGE_MAP_H 128