blob: c5cd8f81e167ab8a9c1e5673f23939e7227f36f0 [file] [log] [blame]
Jeff Brown501edd22011-10-19 20:35:35 -07001/*
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
26extern "C" {
27#endif
28
29typedef struct map_info {
30 struct map_info* next;
31 uintptr_t start;
32 uintptr_t end;
Jeff Brownf0c58722011-11-03 17:58:44 -070033 bool is_readable;
Jeff Brown501edd22011-10-19 20:35:35 -070034 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. */
40map_info_t* load_map_info_list(pid_t tid);
41
42/* Frees memory map. */
43void free_map_info_list(map_info_t* milist);
44
45/* Finds the memory map that contains the specified address. */
46const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr);
47
Jeff Brownf0c58722011-11-03 17:58:44 -070048/* Returns true if the addr is in an readable map. */
49bool is_readable_map(const map_info_t* milist, uintptr_t addr);
50
51/* Returns true if the addr is in an executable map. */
52bool 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. */
57map_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(). */
61void release_my_map_info_list(map_info_t* milist);
Jeff Brown501edd22011-10-19 20:35:35 -070062
63#ifdef __cplusplus
64}
65#endif
66
67#endif // _CORKSCREW_MAP_INFO_H