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