xref: /qemu/include/user/page-protection.h (revision 513823e7521a09ed7ad1e32e6454bac3b2cbf52d)
1 /*
2  * QEMU page protection declarations.
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  * SPDX-License-Identifier: LGPL-2.1+
7  */
8 #ifndef USER_PAGE_PROTECTION_H
9 #define USER_PAGE_PROTECTION_H
10 
11 #ifndef CONFIG_USER_ONLY
12 #error Cannot include this header from system emulation
13 #endif
14 
15 #include "cpu-param.h"
16 #include "exec/target_long.h"
17 #include "exec/translation-block.h"
18 
19 void page_protect(tb_page_addr_t page_addr);
20 int page_unprotect(tb_page_addr_t address, uintptr_t pc);
21 
22 int page_get_flags(target_ulong address);
23 
24 /**
25  * page_set_flags:
26  * @start: first byte of range
27  * @last: last byte of range
28  * @flags: flags to set
29  * Context: holding mmap lock
30  *
31  * Modify the flags of a page and invalidate the code if necessary.
32  * The flag PAGE_WRITE_ORG is positioned automatically depending
33  * on PAGE_WRITE.  The mmap_lock should already be held.
34  */
35 void page_set_flags(target_ulong start, target_ulong last, int flags);
36 
37 void page_reset_target_data(target_ulong start, target_ulong last);
38 
39 /**
40  * page_check_range
41  * @start: first byte of range
42  * @len: length of range
43  * @flags: flags required for each page
44  *
45  * Return true if every page in [@start, @start+@len) has @flags set.
46  * Return false if any page is unmapped.  Thus testing flags == 0 is
47  * equivalent to testing for flags == PAGE_VALID.
48  */
49 bool page_check_range(target_ulong start, target_ulong last, int flags);
50 
51 /**
52  * page_check_range_empty:
53  * @start: first byte of range
54  * @last: last byte of range
55  * Context: holding mmap lock
56  *
57  * Return true if the entire range [@start, @last] is unmapped.
58  * The memory lock must be held so that the caller will can ensure
59  * the result stays true until a new mapping can be installed.
60  */
61 bool page_check_range_empty(target_ulong start, target_ulong last);
62 
63 /**
64  * page_find_range_empty
65  * @min: first byte of search range
66  * @max: last byte of search range
67  * @len: size of the hole required
68  * @align: alignment of the hole required (power of 2)
69  *
70  * If there is a range [x, x+@len) within [@min, @max] such that
71  * x % @align == 0, then return x.  Otherwise return -1.
72  * The memory lock must be held, as the caller will want to ensure
73  * the returned range stays empty until a new mapping can be installed.
74  */
75 target_ulong page_find_range_empty(target_ulong min, target_ulong max,
76                                    target_ulong len, target_ulong align);
77 
78 /**
79  * page_get_target_data(address)
80  * @address: guest virtual address
81  *
82  * Return TARGET_PAGE_DATA_SIZE bytes of out-of-band data to associate
83  * with the guest page at @address, allocating it if necessary.  The
84  * caller should already have verified that the address is valid.
85  *
86  * The memory will be freed when the guest page is deallocated,
87  * e.g. with the munmap system call.
88  */
89 __attribute__((returns_nonnull))
90 void *page_get_target_data(target_ulong address);
91 
92 typedef int (*walk_memory_regions_fn)(void *, target_ulong,
93                                       target_ulong, unsigned long);
94 
95 int walk_memory_regions(void *, walk_memory_regions_fn);
96 
97 void page_dump(FILE *f);
98 
99 #endif
100