3 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 // Name mangle to prevent build errors. I.e conflicts between EFI and OS
22 #define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_
23 #define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_
24 #define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_
25 #define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_
26 #define B0 _UNIX_EFI_NAME_MANGLE_B0_
31 #include <sys/types.h>
33 #include <sys/termios.h>
37 #include <sys/dirent.h>
53 #include <sys/ioctl.h>
54 #include <sys/statvfs.h>
56 #include <sys/socket.h>
58 #include <netinet/in.h>
63 #include <net/if_dl.h>
65 #include <sys/param.h>
66 #include <sys/mount.h>
70 #define _Bool char // for clang debug
90 #include <Library/PeCoffLib.h>
91 #include <Library/BaseLib.h>
92 #include <Library/BaseMemoryLib.h>
93 #include <Library/MemoryAllocationLib.h>
94 #include <Library/PrintLib.h>
95 #include <Library/PcdLib.h>
96 #include <Library/DebugLib.h>
97 #include <Library/ReportStatusCodeLib.h>
99 #include <Library/ThunkPpiList.h>
100 #include <Library/ThunkProtocolList.h>
101 #include <Library/PeiServicesLib.h>
102 #include <Library/PeCoffGetEntryPointLib.h>
103 #include <Library/EmuMagicPageLib.h>
105 #include <Ppi/EmuThunk.h>
106 #include <Ppi/StatusCode.h>
108 #include <Protocol/SimplePointer.h>
109 #include <Protocol/SimpleTextIn.h>
110 #include <Protocol/SimpleTextInEx.h>
111 #include <Protocol/UgaDraw.h>
112 #include <Protocol/SimpleFileSystem.h>
114 #include <Protocol/EmuThunk.h>
115 #include <Protocol/EmuIoThunk.h>
116 #include <Protocol/EmuGraphicsWindow.h>
117 #include <Protocol/EmuThread.h>
118 #include <Protocol/EmuBlockIo.h>
119 #include <Protocol/EmuSnp.h>
121 #include <Guid/FileInfo.h>
122 #include <Guid/FileSystemInfo.h>
123 #include <Guid/FileSystemVolumeLabelInfo.h>
129 #define STACK_SIZE 0x20000
132 EFI_PHYSICAL_ADDRESS Address
;
137 EFI_PHYSICAL_ADDRESS Memory
;
142 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
145 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
147 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
154 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
156 EFI_PHYSICAL_ADDRESS
*EntryPoint
168 IN UINTN LargestRegion
,
169 IN UINTN LargestRegionSize
,
170 IN UINTN BootFirmwareVolumeBase
,
177 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
178 IN UINT64
*ImageSize
,
179 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
184 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
190 IN EFI_FV_FILETYPE SearchType
,
191 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
192 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
196 SecFfsFindSectionData (
197 IN EFI_SECTION_TYPE SectionType
,
198 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
199 IN OUT VOID
**SectionData
204 SecUnixPeCoffLoaderLoadAsDll (
205 IN CHAR8
*PdbFileName
,
206 IN VOID
**ImageEntryPoint
,
212 SecUnixPeCoffLoaderFreeLibrary (
219 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
220 IN OUT UINT64
*FdSize
,
221 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
227 GasketSecUnixFdAddress (
229 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
230 IN OUT UINT64
*FdSize
,
231 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
237 GetImageReadFunction (
238 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
239 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
247 IN OUT UINTN
*ReadSize
,
254 IN UINTN
*StrLen OPTIONAL
258 CountSeperatorsInString (
259 IN
const CHAR16
*String
,
265 SecTemporaryRamSupport (
266 IN CONST EFI_PEI_SERVICES
**PeiServices
,
267 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
268 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
274 GasketSecTemporaryRamSupport (
275 IN CONST EFI_PEI_SERVICES
**PeiServices
,
276 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
277 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
284 SecPeCoffGetEntryPoint (
286 IN OUT VOID
**EntryPoint
291 SecPeCoffRelocateImageExtraAction (
292 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
297 SecPeCoffLoaderUnloadImageExtraAction (
298 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
304 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
305 IN VOID
*Context1
, OPTIONAL
306 IN VOID
*Context2
, OPTIONAL
311 SecInitThunkProtocol (
316 EFI_PHYSICAL_ADDRESS
*
326 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
333 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
339 VOID
SecSleep (UINT64 Nanoseconds
);
340 VOID
SecEnableInterrupt (VOID
);
341 VOID
SecDisableInterrupt (VOID
);
342 BOOLEAN
SecInterruptEanbled (VOID
);
345 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
346 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
347 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
348 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
349 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;
350 extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo
;