Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 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 | |
| 25 | #ifdef __cplusplus |
| 26 | extern "C" { |
| 27 | #endif |
| 28 | |
| 29 | typedef struct map_info { |
| 30 | struct map_info* next; |
| 31 | uintptr_t start; |
| 32 | uintptr_t end; |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 33 | bool is_readable; |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 34 | bool is_executable; |
| 35 | void* data; // arbitrary data associated with the map by the user, initially NULL |
| 36 | char name[]; |
| 37 | } map_info_t; |
| 38 | |
| 39 | /* Loads memory map from /proc/<tid>/maps. */ |
| 40 | map_info_t* load_map_info_list(pid_t tid); |
| 41 | |
| 42 | /* Frees memory map. */ |
| 43 | void free_map_info_list(map_info_t* milist); |
| 44 | |
| 45 | /* Finds the memory map that contains the specified address. */ |
| 46 | const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr); |
| 47 | |
Jeff Brown | f0c5872 | 2011-11-03 17:58:44 -0700 | [diff] [blame] | 48 | /* Returns true if the addr is in an readable map. */ |
| 49 | bool is_readable_map(const map_info_t* milist, uintptr_t addr); |
| 50 | |
| 51 | /* Returns true if the addr is in an executable map. */ |
| 52 | bool is_executable_map(const map_info_t* milist, uintptr_t addr); |
| 53 | |
| 54 | /* Acquires a reference to the memory map for this process. |
| 55 | * The result is cached and refreshed automatically. |
| 56 | * Make sure to release the map info when done. */ |
| 57 | map_info_t* acquire_my_map_info_list(); |
| 58 | |
| 59 | /* Releases a reference to the map info for this process that was |
| 60 | * previous acquired using acquire_my_map_info_list(). */ |
| 61 | void release_my_map_info_list(map_info_t* milist); |
Jeff Brown | 501edd2 | 2011-10-19 20:35:35 -0700 | [diff] [blame] | 62 | |
| 63 | #ifdef __cplusplus |
| 64 | } |
| 65 | #endif |
| 66 | |
| 67 | #endif // _CORKSCREW_MAP_INFO_H |