xref: /qemu/include/exec/page-protection.h (revision bcbd8c0edf712a7d55d9bf020be4b0f21ce3c35c)
1 /*
2  * QEMU page protection definitions.
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  * SPDX-License-Identifier: LGPL-2.1+
7  */
8 #ifndef EXEC_PAGE_PROT_COMMON_H
9 #define EXEC_PAGE_PROT_COMMON_H
10 
11 /* same as PROT_xxx */
12 #define PAGE_READ      0x0001
13 #define PAGE_WRITE     0x0002
14 #define PAGE_EXEC      0x0004
15 #define PAGE_RWX       (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
16 #define PAGE_VALID     0x0008
17 /*
18  * Original state of the write flag (used when tracking self-modifying code)
19  */
20 #define PAGE_WRITE_ORG 0x0010
21 /*
22  * Invalidate the TLB entry immediately, helpful for s390x
23  * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs()
24  */
25 #define PAGE_WRITE_INV 0x0020
26 /* For use with page_set_flags: page is being replaced; target_data cleared. */
27 #define PAGE_RESET     0x0040
28 /* For linux-user, indicates that the page is MAP_ANON. */
29 #define PAGE_ANON      0x0080
30 
31 /* Target-specific bits that will be used via page_get_flags().  */
32 #define PAGE_TARGET_1  0x0200
33 #define PAGE_TARGET_2  0x0400
34 
35 /*
36  * For linux-user, indicates that the page is mapped with the same semantics
37  * in both guest and host.
38  */
39 #define PAGE_PASSTHROUGH 0x0800
40 
41 #ifdef CONFIG_USER_ONLY
42 
43 void TSA_NO_TSA mmap_lock(void);
44 void TSA_NO_TSA mmap_unlock(void);
45 bool have_mmap_lock(void);
46 
47 static inline void mmap_unlock_guard(void *unused)
48 {
49     mmap_unlock();
50 }
51 
52 #define WITH_MMAP_LOCK_GUARD() \
53     for (int _mmap_lock_iter __attribute__((cleanup(mmap_unlock_guard))) \
54          = (mmap_lock(), 0); _mmap_lock_iter == 0; _mmap_lock_iter = 1)
55 #else
56 
57 static inline void mmap_lock(void) {}
58 static inline void mmap_unlock(void) {}
59 #define WITH_MMAP_LOCK_GUARD()
60 
61 #endif /* !CONFIG_USER_ONLY */
62 
63 #endif
64