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