1/* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17/* Process memory map. */ 18 19#ifndef _CORKSCREW_MAP_INFO_H 20#define _CORKSCREW_MAP_INFO_H 21 22#include <sys/types.h> 23#include <stdbool.h> 24#include <stdint.h> 25 26#ifdef __cplusplus 27extern "C" { 28#endif 29 30typedef struct map_info { 31 struct map_info* next; 32 uintptr_t start; 33 uintptr_t end; 34 bool is_readable; 35 bool is_executable; 36 void* data; // arbitrary data associated with the map by the user, initially NULL 37 char name[]; 38} map_info_t; 39 40/* Loads memory map from /proc/<tid>/maps. */ 41map_info_t* load_map_info_list(pid_t tid); 42 43/* Frees memory map. */ 44void free_map_info_list(map_info_t* milist); 45 46/* Finds the memory map that contains the specified address. */ 47const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr); 48 49/* Returns true if the addr is in an readable map. */ 50bool is_readable_map(const map_info_t* milist, uintptr_t addr); 51 52/* Returns true if the addr is in an executable map. */ 53bool is_executable_map(const map_info_t* milist, uintptr_t addr); 54 55/* Acquires a reference to the memory map for this process. 56 * The result is cached and refreshed automatically. 57 * Make sure to release the map info when done. */ 58map_info_t* acquire_my_map_info_list(); 59 60/* Releases a reference to the map info for this process that was 61 * previous acquired using acquire_my_map_info_list(). */ 62void release_my_map_info_list(map_info_t* milist); 63 64#ifdef __cplusplus 65} 66#endif 67 68#endif // _CORKSCREW_MAP_INFO_H 69