summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/utils/corkscrew/map_info.h
blob: dc2275e38d66891f276ef6f1d6b260f4ba739f8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* Process memory map. */

#ifndef _CORKSCREW_MAP_INFO_H
#define _CORKSCREW_MAP_INFO_H

#include <sys/types.h>
#include <stdbool.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

	typedef struct
	{
		struct map_info* next;
		uintptr_t start;
		uintptr_t end;
		bool is_readable;
		bool is_writable;
		bool is_executable;
		void* data; // arbitrary data associated with the map by the user, initially NULL
		char name[];
	} map_info_t;

	/* Loads memory map from /proc/<tid>/maps. */
	map_info_t* load_map_info_list(pid_t tid);

	/* Frees memory map. */
	void free_map_info_list(map_info_t* milist);

	/* Finds the memory map that contains the specified address. */
	const map_info_t* find_map_info(const map_info_t* milist, uintptr_t addr);

	/* Returns true if the addr is in a readable map. */
	bool is_readable_map(const map_info_t* milist, uintptr_t addr);
	/* Returns true if the addr is in a writable map. */
	bool is_writable_map(const map_info_t* milist, uintptr_t addr);
	/* Returns true if the addr is in an executable map. */
	bool is_executable_map(const map_info_t* milist, uintptr_t addr);

	/* Acquires a reference to the memory map for this process.
	 * The result is cached and refreshed automatically.
	 * Make sure to release the map info when done. */
	map_info_t* acquire_my_map_info_list();

	/* Releases a reference to the map info for this process that was
	 * previous acquired using acquire_my_map_info_list(). */
	void release_my_map_info_list(map_info_t* milist);

	/* Flushes the cached memory map so the next call to
	 * acquire_my_map_info_list() gets fresh data. */
	void flush_my_map_info_list();

#ifdef __cplusplus
}
#endif

#endif // _CORKSCREW_MAP_INFO_H