blob: 14bfad67db6bc0c7a936b97694fcc80df852e1d4 [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>
Elliott Hughes420a7fa2012-05-17 18:28:01 -070024#include <stdint.h>
Jeff Brown501edd22011-10-19 20:35:35 -070025
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;
Jeff Brownf0c58722011-11-03 17:58:44 -070034 bool is_readable;
Elliott Hughesd1420be2013-01-03 13:39:57 -080035 bool is_writable;
Jeff Brown501edd22011-10-19 20:35:35 -070036 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. */
42map_info_t* load_map_info_list(pid_t tid);
43
44/* Frees memory map. */
45void free_map_info_list(map_info_t* milist);
46
47/* Finds the memory map that contains the specified address. */
48const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr);
49
Elliott Hughesd1420be2013-01-03 13:39:57 -080050/* Returns true if the addr is in a readable map. */
Jeff Brownf0c58722011-11-03 17:58:44 -070051bool is_readable_map(const map_info_t* milist, uintptr_t addr);
Elliott Hughesd1420be2013-01-03 13:39:57 -080052/* Returns true if the addr is in a writable map. */
53bool is_writable_map(const map_info_t* milist, uintptr_t addr);
Jeff Brownf0c58722011-11-03 17:58:44 -070054/* Returns true if the addr is in an executable map. */
55bool 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. */
60map_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(). */
64void release_my_map_info_list(map_info_t* milist);
Jeff Brown501edd22011-10-19 20:35:35 -070065
Elliott Hughes89054052012-06-13 14:21:23 -070066/* Flushes the cached memory map so the next call to
67 * acquire_my_map_info_list() gets fresh data. */
68void flush_my_map_info_list();
69
Jeff Brown501edd22011-10-19 20:35:35 -070070#ifdef __cplusplus
71}
72#endif
73
74#endif // _CORKSCREW_MAP_INFO_H