3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
14 // Name mangle to prevent build errors. I.e conflicts between EFI and OS
16 #define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_
17 #define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_
18 #define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_
19 #define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_
20 #define B0 _UNIX_EFI_NAME_MANGLE_B0_
25 #include <sys/types.h>
27 #include <sys/termios.h>
31 #include <sys/dirent.h>
47 #include <sys/ioctl.h>
48 #include <sys/statvfs.h>
50 #include <sys/socket.h>
52 #include <netinet/in.h>
57 #include <net/if_dl.h>
59 #include <sys/param.h>
60 #include <sys/mount.h>
64 #define _Bool char // for clang debug
84 #include <Library/PeCoffLib.h>
85 #include <Library/BaseLib.h>
86 #include <Library/BaseMemoryLib.h>
87 #include <Library/MemoryAllocationLib.h>
88 #include <Library/PrintLib.h>
89 #include <Library/PcdLib.h>
90 #include <Library/DebugLib.h>
91 #include <Library/ReportStatusCodeLib.h>
93 #include <Library/ThunkPpiList.h>
94 #include <Library/ThunkProtocolList.h>
95 #include <Library/PeiServicesLib.h>
96 #include <Library/PeCoffGetEntryPointLib.h>
97 #include <Library/EmuMagicPageLib.h>
99 #include <Ppi/EmuThunk.h>
100 #include <Ppi/StatusCode.h>
102 #include <Protocol/SimplePointer.h>
103 #include <Protocol/SimpleTextIn.h>
104 #include <Protocol/SimpleTextInEx.h>
105 #include <Protocol/UgaDraw.h>
106 #include <Protocol/SimpleFileSystem.h>
108 #include <Protocol/EmuThunk.h>
109 #include <Protocol/EmuIoThunk.h>
110 #include <Protocol/EmuGraphicsWindow.h>
111 #include <Protocol/EmuThread.h>
112 #include <Protocol/EmuBlockIo.h>
113 #include <Protocol/EmuSnp.h>
115 #include <Guid/FileInfo.h>
116 #include <Guid/FileSystemInfo.h>
117 #include <Guid/FileSystemVolumeLabelInfo.h>
123 #define STACK_SIZE 0x20000
126 EFI_PHYSICAL_ADDRESS Address
;
131 EFI_PHYSICAL_ADDRESS Memory
;
136 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
139 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
141 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
148 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
150 EFI_PHYSICAL_ADDRESS
*EntryPoint
162 IN UINTN LargestRegion
,
163 IN UINTN LargestRegionSize
,
164 IN UINTN BootFirmwareVolumeBase
,
171 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
172 IN UINT64
*ImageSize
,
173 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
178 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
184 IN EFI_FV_FILETYPE SearchType
,
185 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
186 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
190 SecFfsFindSectionData (
191 IN EFI_SECTION_TYPE SectionType
,
192 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
193 IN OUT VOID
**SectionData
198 SecUnixPeCoffLoaderLoadAsDll (
199 IN CHAR8
*PdbFileName
,
200 IN VOID
**ImageEntryPoint
,
206 SecUnixPeCoffLoaderFreeLibrary (
213 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
214 IN OUT UINT64
*FdSize
,
215 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
221 GasketSecUnixFdAddress (
223 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
224 IN OUT UINT64
*FdSize
,
225 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
231 GetImageReadFunction (
232 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
233 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
241 IN OUT UINTN
*ReadSize
,
248 IN UINTN
*StrLen OPTIONAL
252 CountSeparatorsInString (
253 IN
const CHAR16
*String
,
259 SecTemporaryRamSupport (
260 IN CONST EFI_PEI_SERVICES
**PeiServices
,
261 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
262 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
268 GasketSecTemporaryRamSupport (
269 IN CONST EFI_PEI_SERVICES
**PeiServices
,
270 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
271 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
278 SecPeCoffGetEntryPoint (
280 IN OUT VOID
**EntryPoint
285 SecPeCoffRelocateImageExtraAction (
286 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
291 SecPeCoffLoaderUnloadImageExtraAction (
292 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
298 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
299 IN VOID
*Context1
, OPTIONAL
300 IN VOID
*Context2
, OPTIONAL
305 SecInitThunkProtocol (
310 EFI_PHYSICAL_ADDRESS
*
320 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
327 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
332 EfiSystemMemoryRange (
333 IN VOID
*MemoryAddress
337 VOID
SecSleep (UINT64 Nanoseconds
);
338 VOID
SecEnableInterrupt (VOID
);
339 VOID
SecDisableInterrupt (VOID
);
340 BOOLEAN
SecInterruptEanbled (VOID
);
343 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
344 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
345 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
346 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
347 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;
348 extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo
;