TianoCore EDK2 master
Loading...
Searching...
No Matches
Host.h
1/*++ @file
2
3Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
4Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
5
6SPDX-License-Identifier: BSD-2-Clause-Patent
7
8**/
9
10#ifndef _SEC_MAIN_H__
11#define _SEC_MAIN_H__
12
13//
14// Name mangle to prevent build errors. I.e conflicts between EFI and OS
15//
16#define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_
17#define NTOHLL _UNIX_EFI_NAME_MANGLE_NTOHLL_
18#define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_
19#define HTONLL _UNIX_EFI_NAME_MANGLE_HTONLL_
20#define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_
21#define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_
22#define B0 _UNIX_EFI_NAME_MANGLE_B0_
23
24#include <stdio.h>
25#include <stdlib.h>
26
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <sys/termios.h>
30#include <sys/time.h>
31
32#if __CYGWIN__
33 #include <sys/dirent.h>
34#else
35 #include <sys/dir.h>
36#endif
37
38#include <sys/mman.h>
39#include <dlfcn.h>
40
41#include <unistd.h>
42#include <poll.h>
43#include <fcntl.h>
44#include <time.h>
45#include <signal.h>
46#include <errno.h>
47#include <string.h>
48#include <stdlib.h>
49#include <sys/ioctl.h>
50#include <sys/statvfs.h>
51
52#include <sys/socket.h>
53#include <netdb.h>
54#include <netinet/in.h>
55#include <net/if.h>
56#include <ifaddrs.h>
57
58#ifdef __APPLE__
59 #include <net/if_dl.h>
60 #include <net/bpf.h>
61 #include <sys/param.h>
62 #include <sys/mount.h>
63 #include <sys/disk.h>
64#define _XOPEN_SOURCE
65 #ifndef _Bool
66#define _Bool char // for clang debug
67 #endif
68#else
69 #include <termio.h>
70 #include <sys/vfs.h>
71 #include <linux/fs.h>
72#endif
73
74#include <utime.h>
75
76#undef NTOHL
77#undef NTOHLL
78#undef HTONL
79#undef HTONLL
80#undef NTOHS
81#undef HTONS
82#undef B0
83#undef CR3
84
85#include <PiPei.h>
86#include <Uefi.h>
87
88#include <Library/PeCoffLib.h>
89#include <Library/BaseLib.h>
92#include <Library/PrintLib.h>
93#include <Library/PcdLib.h>
94#include <Library/DebugLib.h>
96
101#include <Library/EmuMagicPageLib.h>
102
103#include <Ppi/EmuThunk.h>
104#include <Ppi/StatusCode.h>
105
109#include <Protocol/UgaDraw.h>
111
112#include <Protocol/EmuThunk.h>
113#include <Protocol/EmuIoThunk.h>
114#include <Protocol/EmuGraphicsWindow.h>
115#include <Protocol/EmuThread.h>
116#include <Protocol/EmuBlockIo.h>
117#include <Protocol/EmuSnp.h>
118
119#include <Guid/FileInfo.h>
120#include <Guid/FileSystemInfo.h>
122
123#include "Gasket.h"
124
125#define STACK_SIZE 0x20000
126
127typedef struct {
128 EFI_PHYSICAL_ADDRESS Address;
129 UINT64 Size;
131
132typedef struct {
134 UINT64 Size;
136
137#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
138
139typedef struct {
140 PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext;
141 VOID *ModHandle;
143
145EFIAPI
146SecUnixPeiLoadFile (
147 VOID *Pe32Data,
148 EFI_PHYSICAL_ADDRESS *ImageAddress,
149 UINT64 *ImageSize,
150 EFI_PHYSICAL_ADDRESS *EntryPoint
151 );
152
153int
154main (
155 IN int Argc,
156 IN char **Argv,
157 IN char **Envp
158 );
159
160VOID
161SecLoadFromCore (
162 IN UINTN LargestRegion,
163 IN UINTN LargestRegionSize,
164 IN UINTN BootFirmwareVolumeBase,
165 IN VOID *PeiCoreFile
166 );
167
169SecLoadFile (
170 IN VOID *Pe32Data,
171 IN EFI_PHYSICAL_ADDRESS *ImageAddress,
172 IN UINT64 *ImageSize,
173 IN EFI_PHYSICAL_ADDRESS *EntryPoint
174 );
175
177SecFfsFindPeiCore (
178 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
179 OUT VOID **Pe32Data
180 );
181
183SecFfsFindNextFile (
184 IN EFI_FV_FILETYPE SearchType,
185 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
186 IN OUT EFI_FFS_FILE_HEADER **FileHeader
187 );
188
190SecFfsFindSectionData (
191 IN EFI_SECTION_TYPE SectionType,
192 IN EFI_FFS_FILE_HEADER *FfsFileHeader,
193 IN OUT VOID **SectionData
194 );
195
197EFIAPI
198SecUnixPeCoffLoaderLoadAsDll (
199 IN CHAR8 *PdbFileName,
200 IN VOID **ImageEntryPoint,
201 OUT VOID **ModHandle
202 );
203
205EFIAPI
206SecUnixPeCoffLoaderFreeLibrary (
207 OUT VOID *ModHandle
208 );
209
211SecUnixFdAddress (
212 IN UINTN Index,
214 IN OUT UINT64 *FdSize,
216 )
217;
218
220EFIAPI
221GasketSecUnixFdAddress (
222 IN UINTN Index,
224 IN OUT UINT64 *FdSize,
226 )
227;
228
230GetImageReadFunction (
231 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
232 IN EFI_PHYSICAL_ADDRESS *TopOfMemory
233 );
234
236EFIAPI
237SecImageRead (
238 IN VOID *FileHandle,
239 IN UINTN FileOffset,
240 IN OUT UINTN *ReadSize,
241 OUT VOID *Buffer
242 );
243
244CHAR16 *
245AsciiToUnicode (
246 IN CHAR8 *Ascii,
247 IN UINTN *StrLen OPTIONAL
248 );
249
250UINTN
251CountSeparatorsInString (
252 IN const CHAR16 *String,
253 IN CHAR16 Separator
254 );
255
257EFIAPI
259 IN CONST EFI_PEI_SERVICES **PeiServices,
260 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
261 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
262 IN UINTN CopySize
263 );
264
266EFIAPI
267GasketSecTemporaryRamSupport (
268 IN CONST EFI_PEI_SERVICES **PeiServices,
269 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
270 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
271 IN UINTN CopySize
272 );
273
274RETURN_STATUS
275EFIAPI
276SecPeCoffGetEntryPoint (
277 IN VOID *Pe32Data,
278 IN OUT VOID **EntryPoint
279 );
280
281VOID
282EFIAPI
283SecPeCoffRelocateImageExtraAction (
285 );
286
287VOID
288EFIAPI
289SecPeCoffLoaderUnloadImageExtraAction (
291 );
292
293VOID
294PeiSwitchStacks (
295 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
296 IN VOID *Context1 OPTIONAL,
297 IN VOID *Context2 OPTIONAL,
298 IN VOID *NewStack
299 );
300
301VOID
302SecInitThunkProtocol (
303 VOID
304 );
305
307MapMemory (
308 INTN fd,
309 UINT64 length,
310 INTN prot,
311 INTN flags
312 );
313
315MapFile (
316 IN CHAR8 *FileName,
317 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
318 OUT UINT64 *Length
319 );
320
322MapFd0 (
323 IN CHAR8 *FileName,
324 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
325 OUT UINT64 *Length
326 );
327
328BOOLEAN
329EfiSystemMemoryRange (
330 IN VOID *MemoryAddress
331 );
332
333VOID
334SecSleep (
335 UINT64 Nanoseconds
336 );
337
338VOID
339SecEnableInterrupt (
340 VOID
341 );
342
343VOID
344SecDisableInterrupt (
345 VOID
346 );
347
348BOOLEAN
349SecInterruptEanbled (
350 VOID
351 );
352
353extern EMU_THUNK_PROTOCOL gEmuThunkProtocol;
354extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;
355extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;
356extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;
357extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;
358extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo;
359
360#endif
UINT64 UINTN
INT64 INTN
STATIC EFI_STATUS EFIAPI SecTemporaryRamSupport(IN CONST EFI_PEI_SERVICES **PeiServices, IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase, IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase, IN UINTN CopySize)
Definition: Sec.c:35
VOID(EFIAPI * SWITCH_STACK_ENTRY_POINT)(IN VOID *Context1 OPTIONAL, IN VOID *Context2 OPTIONAL)
Definition: BaseLib.h:5019
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
int main()
=== TEST ENGINE ================================================================================
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
UINT64 EFI_PHYSICAL_ADDRESS
Definition: UefiBaseType.h:50
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29