]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Core/Dxe/Mem/Imem.h
MdeModulePkg/Core: fix feature conflict between NX and heap guard
[mirror_edk2.git] / MdeModulePkg / Core / Dxe / Mem / Imem.h
1 /** @file
2 Data structure and functions to allocate and free memory space.
3
4 Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _IMEM_H_
16 #define _IMEM_H_
17
18 //
19 // +---------------------------------------------------+
20 // | 0..(EfiMaxMemoryType - 1) - Normal memory type |
21 // +---------------------------------------------------+
22 // | EfiMaxMemoryType..0x6FFFFFFF - Invalid |
23 // +---------------------------------------------------+
24 // | 0x70000000..0x7FFFFFFF - OEM reserved |
25 // +---------------------------------------------------+
26 // | 0x80000000..0xFFFFFFFF - OS reserved |
27 // +---------------------------------------------------+
28 //
29 #define MEMORY_TYPE_OS_RESERVED_MIN 0x80000000
30 #define MEMORY_TYPE_OS_RESERVED_MAX 0xFFFFFFFF
31 #define MEMORY_TYPE_OEM_RESERVED_MIN 0x70000000
32 #define MEMORY_TYPE_OEM_RESERVED_MAX 0x7FFFFFFF
33
34 //
35 // MEMORY_MAP_ENTRY
36 //
37
38 #define MEMORY_MAP_SIGNATURE SIGNATURE_32('m','m','a','p')
39 typedef struct {
40 UINTN Signature;
41 LIST_ENTRY Link;
42 BOOLEAN FromPages;
43
44 EFI_MEMORY_TYPE Type;
45 UINT64 Start;
46 UINT64 End;
47
48 UINT64 VirtualStart;
49 UINT64 Attribute;
50 } MEMORY_MAP;
51
52 //
53 // Internal prototypes
54 //
55
56
57 /**
58 Internal function. Used by the pool functions to allocate pages
59 to back pool allocation requests.
60
61 @param PoolType The type of memory for the new pool pages
62 @param NumberOfPages No of pages to allocate
63 @param Alignment Bits to align.
64 @param NeedGuard Flag to indicate Guard page is needed or not
65
66 @return The allocated memory, or NULL
67
68 **/
69 VOID *
70 CoreAllocatePoolPages (
71 IN EFI_MEMORY_TYPE PoolType,
72 IN UINTN NumberOfPages,
73 IN UINTN Alignment,
74 IN BOOLEAN NeedGuard
75 );
76
77
78
79 /**
80 Internal function. Frees pool pages allocated via AllocatePoolPages ()
81
82 @param Memory The base address to free
83 @param NumberOfPages The number of pages to free
84
85 **/
86 VOID
87 CoreFreePoolPages (
88 IN EFI_PHYSICAL_ADDRESS Memory,
89 IN UINTN NumberOfPages
90 );
91
92
93
94 /**
95 Internal function to allocate pool of a particular type.
96 Caller must have the memory lock held
97
98 @param PoolType Type of pool to allocate
99 @param Size The amount of pool to allocate
100 @param NeedGuard Flag to indicate Guard page is needed or not
101
102 @return The allocate pool, or NULL
103
104 **/
105 VOID *
106 CoreAllocatePoolI (
107 IN EFI_MEMORY_TYPE PoolType,
108 IN UINTN Size,
109 IN BOOLEAN NeedGuard
110 );
111
112
113
114 /**
115 Internal function to free a pool entry.
116 Caller must have the memory lock held
117
118 @param Buffer The allocated pool entry to free
119 @param PoolType Pointer to pool type
120
121 @retval EFI_INVALID_PARAMETER Buffer not valid
122 @retval EFI_SUCCESS Buffer successfully freed.
123
124 **/
125 EFI_STATUS
126 CoreFreePoolI (
127 IN VOID *Buffer,
128 OUT EFI_MEMORY_TYPE *PoolType OPTIONAL
129 );
130
131
132
133 /**
134 Enter critical section by gaining lock on gMemoryLock.
135
136 **/
137 VOID
138 CoreAcquireMemoryLock (
139 VOID
140 );
141
142
143 /**
144 Exit critical section by releasing lock on gMemoryLock.
145
146 **/
147 VOID
148 CoreReleaseMemoryLock (
149 VOID
150 );
151
152 /**
153 Allocates pages from the memory map.
154
155 @param Type The type of allocation to perform
156 @param MemoryType The type of memory to turn the allocated pages
157 into
158 @param NumberOfPages The number of pages to allocate
159 @param Memory A pointer to receive the base allocated memory
160 address
161 @param NeedGuard Flag to indicate Guard page is needed or not
162
163 @return Status. On success, Memory is filled in with the base address allocated
164 @retval EFI_INVALID_PARAMETER Parameters violate checking rules defined in
165 spec.
166 @retval EFI_NOT_FOUND Could not allocate pages match the requirement.
167 @retval EFI_OUT_OF_RESOURCES No enough pages to allocate.
168 @retval EFI_SUCCESS Pages successfully allocated.
169
170 **/
171 EFI_STATUS
172 EFIAPI
173 CoreInternalAllocatePages (
174 IN EFI_ALLOCATE_TYPE Type,
175 IN EFI_MEMORY_TYPE MemoryType,
176 IN UINTN NumberOfPages,
177 IN OUT EFI_PHYSICAL_ADDRESS *Memory,
178 IN BOOLEAN NeedGuard
179 );
180
181 //
182 // Internal Global data
183 //
184
185 extern EFI_LOCK gMemoryLock;
186 extern LIST_ENTRY gMemoryMap;
187 extern LIST_ENTRY mGcdMemorySpaceMap;
188 #endif