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