1 | /** @file
|
---|
2 | * IPRT - Parameter Definitions.
|
---|
3 | */
|
---|
4 |
|
---|
5 | /*
|
---|
6 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
7 | *
|
---|
8 | * This file is part of VirtualBox base platform packages, as
|
---|
9 | * available from https://www.virtualbox.org.
|
---|
10 | *
|
---|
11 | * This program is free software; you can redistribute it and/or
|
---|
12 | * modify it under the terms of the GNU General Public License
|
---|
13 | * as published by the Free Software Foundation, in version 3 of the
|
---|
14 | * License.
|
---|
15 | *
|
---|
16 | * This program is distributed in the hope that it will be useful, but
|
---|
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
19 | * General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
23 | *
|
---|
24 | * The contents of this file may alternatively be used under the terms
|
---|
25 | * of the Common Development and Distribution License Version 1.0
|
---|
26 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
27 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
28 | * CDDL are applicable instead of those of the GPL.
|
---|
29 | *
|
---|
30 | * You may elect to license modified versions of this file under the
|
---|
31 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
32 | *
|
---|
33 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef IPRT_INCLUDED_param_h
|
---|
37 | #define IPRT_INCLUDED_param_h
|
---|
38 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
39 | # pragma once
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/cdefs.h>
|
---|
43 |
|
---|
44 | /** @todo Much of the PAGE_* stuff here is obsolete and highly risky to have around.
|
---|
45 | * As for component configs (MM_*), either we gather all in here or we move those bits away! */
|
---|
46 |
|
---|
47 | /** @defgroup grp_rt_param System Parameter Definitions
|
---|
48 | * @ingroup grp_rt_cdefs
|
---|
49 | * @{
|
---|
50 | */
|
---|
51 |
|
---|
52 | /* Undefine PAGE_SIZE and PAGE_SHIFT to avoid unnecessary noice when clashing
|
---|
53 | * with system headers. Include system headers before / after iprt depending
|
---|
54 | * on which you wish to take precedence. */
|
---|
55 | #undef PAGE_SIZE
|
---|
56 | #undef PAGE_SHIFT
|
---|
57 |
|
---|
58 | /* Undefine PAGE_OFFSET_MASK to avoid the conflict with the-linux-kernel.h */
|
---|
59 | #undef PAGE_OFFSET_MASK
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * i386 Page size.
|
---|
63 | */
|
---|
64 | #if defined(RT_ARCH_SPARC64)
|
---|
65 | # define PAGE_SIZE 8192
|
---|
66 | #elif defined(RT_ARCH_ARM64)
|
---|
67 | # if defined(RT_OS_DARWIN)
|
---|
68 | # define PAGE_SIZE 16384
|
---|
69 | # elif defined(RT_OS_LINUX)
|
---|
70 | # ifdef IN_RING0
|
---|
71 | # define PAGE_SIZE (1 << CONFIG_ARM64_PAGE_SHIFT)
|
---|
72 | # else
|
---|
73 | # define PAGE_SIZE RT_DONT_USE_PAGE_SIZE_ON_LINUX_ARM64_IN_USERSPACE_DUE_TO_VARIABLE_PAGE_SIZE
|
---|
74 | # endif
|
---|
75 | # elif defined(RT_OS_WINDOWS)
|
---|
76 | # define PAGE_SIZE 4096
|
---|
77 | # else
|
---|
78 | # error "This needs porting"
|
---|
79 | # endif
|
---|
80 | #else
|
---|
81 | # define PAGE_SIZE 4096
|
---|
82 | #endif
|
---|
83 |
|
---|
84 | /**
|
---|
85 | * i386 Page shift.
|
---|
86 | * This is used to convert between size (in bytes) and page count.
|
---|
87 | */
|
---|
88 | #if defined(RT_ARCH_SPARC64)
|
---|
89 | # define PAGE_SHIFT 13
|
---|
90 | #elif defined(RT_ARCH_ARM64)
|
---|
91 | # if defined(RT_OS_DARWIN)
|
---|
92 | # define PAGE_SHIFT 14
|
---|
93 | # elif defined(RT_OS_LINUX)
|
---|
94 | # ifdef IN_RING0
|
---|
95 | # define PAGE_SHIFT CONFIG_ARM64_PAGE_SHIFT
|
---|
96 | # else
|
---|
97 | # define PAGE_SHIFT RT_DONT_USE_PAGE_SHIFT_ON_LINUX_ARM64_IN_USERSPACE_DUE_TO_VARIABLE_PAGE_SIZE
|
---|
98 | # endif
|
---|
99 | # elif defined(RT_OS_WINDOWS)
|
---|
100 | # define PAGE_SHIFT 12
|
---|
101 | # else
|
---|
102 | # error "This needs porting"
|
---|
103 | # endif
|
---|
104 | #else
|
---|
105 | # define PAGE_SHIFT 12
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * i386 Page offset mask.
|
---|
110 | *
|
---|
111 | * @note If you do one-complement this, always insert a target type case after
|
---|
112 | * the operator! Otherwise you may end up with weird results.
|
---|
113 | */
|
---|
114 | #if defined(RT_ARCH_SPARC64)
|
---|
115 | # define PAGE_OFFSET_MASK 0x1fff
|
---|
116 | #elif defined(RT_ARCH_ARM64)
|
---|
117 | # if defined(RT_OS_DARWIN)
|
---|
118 | # define PAGE_OFFSET_MASK 0x3fff
|
---|
119 | # elif defined(RT_OS_LINUX)
|
---|
120 | # ifdef IN_RING0
|
---|
121 | # define PAGE_OFFSET_MASK (PAGE_SIZE - 1)
|
---|
122 | # else
|
---|
123 | # define PAGE_OFFSET_MASK RT_DONT_USE_PAGE_OFFSET_MASK_ON_LINUX_ARM64_IN_USERSPACE_DUE_TO_VARIABLE_PAGE_SIZE
|
---|
124 | # endif
|
---|
125 | # elif defined(RT_OS_WINDOWS)
|
---|
126 | # define PAGE_OFFSET_MASK 0xfff
|
---|
127 | # else
|
---|
128 | # error "This needs porting"
|
---|
129 | # endif
|
---|
130 | #else
|
---|
131 | # define PAGE_OFFSET_MASK 0xfff
|
---|
132 | #endif
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Page address mask for the uintptr_t sized pointers.
|
---|
136 | *
|
---|
137 | * Be careful when using this since it may be a size too big!
|
---|
138 | * @remark Physical addresses are always masked using X86_PTE_PAE_PG_MASK!
|
---|
139 | */
|
---|
140 | #define PAGE_BASE_MASK (~(uintptr_t)PAGE_OFFSET_MASK)
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Get the page aligned address of a POINTER in the CURRENT context.
|
---|
144 | *
|
---|
145 | * @returns Page aligned address (it's an uintptr_t).
|
---|
146 | * @param pv The virtual address to align.
|
---|
147 | *
|
---|
148 | * @remarks Physical addresses are always masked using X86_PTE_PAE_PG_MASK!
|
---|
149 | * @remarks This only works with POINTERS in the current context.
|
---|
150 | * Do NOT use on guest address or physical address!
|
---|
151 | */
|
---|
152 | #define PAGE_ADDRESS(pv) ((uintptr_t)(pv) & ~(uintptr_t)PAGE_OFFSET_MASK)
|
---|
153 |
|
---|
154 | /**
|
---|
155 | * Get the page aligned address of a physical address
|
---|
156 | *
|
---|
157 | * @returns Page aligned address (it's an RTHCPHYS or RTGCPHYS).
|
---|
158 | * @param Phys The physical address to align.
|
---|
159 | */
|
---|
160 | #define PHYS_PAGE_ADDRESS(Phys) ((Phys) & X86_PTE_PAE_PG_MASK)
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Host max path (the reasonable value).
|
---|
164 | * @remarks defined both by iprt/param.h and iprt/path.h.
|
---|
165 | */
|
---|
166 | #if !defined(IPRT_INCLUDED_path_h) || defined(DOXYGEN_RUNNING)
|
---|
167 | # define RTPATH_MAX (4096 + 4) /* (PATH_MAX + 1) on linux w/ some alignment */
|
---|
168 | #endif
|
---|
169 |
|
---|
170 | /** @} */
|
---|
171 |
|
---|
172 | #endif /* !IPRT_INCLUDED_param_h */
|
---|
173 |
|
---|