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/PrintLib.h>
94 #include <Library/PcdLib.h>
95 #include <Library/DebugLib.h>
96 #include <Library/ReportStatusCodeLib.h>
98 #include <Library/ThunkPpiList.h>
99 #include <Library/ThunkProtocolList.h>
100 #include <Library/PeiServicesLib.h>
101 #include <Library/PeCoffGetEntryPointLib.h>
102 #include <Library/EmuMagicPageLib.h>
104 #include <Ppi/EmuThunk.h>
105 #include <Ppi/StatusCode.h>
107 #include <Protocol/SimplePointer.h>
108 #include <Protocol/SimpleTextIn.h>
109 #include <Protocol/SimpleTextInEx.h>
110 #include <Protocol/UgaDraw.h>
111 #include <Protocol/SimpleFileSystem.h>
113 #include <Protocol/EmuThunk.h>
114 #include <Protocol/EmuIoThunk.h>
115 #include <Protocol/EmuGraphicsWindow.h>
116 #include <Protocol/EmuThread.h>
117 #include <Protocol/EmuBlockIo.h>
118 #include <Protocol/EmuSnp.h>
120 #include <Guid/FileInfo.h>
121 #include <Guid/FileSystemInfo.h>
122 #include <Guid/FileSystemVolumeLabelInfo.h>
128 #define STACK_SIZE 0x20000
131 EFI_PHYSICAL_ADDRESS Address
;
136 EFI_PHYSICAL_ADDRESS Memory
;
141 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
144 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
146 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
153 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
155 EFI_PHYSICAL_ADDRESS
*EntryPoint
167 IN UINTN LargestRegion
,
168 IN UINTN LargestRegionSize
,
169 IN UINTN BootFirmwareVolumeBase
,
176 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
177 IN UINT64
*ImageSize
,
178 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
183 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
189 IN EFI_FV_FILETYPE SearchType
,
190 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
191 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
195 SecFfsFindSectionData (
196 IN EFI_SECTION_TYPE SectionType
,
197 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
198 IN OUT VOID
**SectionData
203 SecUnixPeCoffLoaderLoadAsDll (
204 IN CHAR8
*PdbFileName
,
205 IN VOID
**ImageEntryPoint
,
211 SecUnixPeCoffLoaderFreeLibrary (
218 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
219 IN OUT UINT64
*FdSize
,
220 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
226 GasketSecUnixFdAddress (
228 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
229 IN OUT UINT64
*FdSize
,
230 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
236 GetImageReadFunction (
237 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
238 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
246 IN OUT UINTN
*ReadSize
,
253 IN UINTN
*StrLen OPTIONAL
257 CountSeperatorsInString (
258 IN
const CHAR16
*String
,
264 SecTemporaryRamSupport (
265 IN CONST EFI_PEI_SERVICES
**PeiServices
,
266 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
267 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
273 GasketSecTemporaryRamSupport (
274 IN CONST EFI_PEI_SERVICES
**PeiServices
,
275 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
276 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
283 SecPeCoffGetEntryPoint (
285 IN OUT VOID
**EntryPoint
290 SecPeCoffRelocateImageExtraAction (
291 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
296 SecPeCoffLoaderUnloadImageExtraAction (
297 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
303 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
304 IN VOID
*Context1
, OPTIONAL
305 IN VOID
*Context2
, OPTIONAL
310 SecInitThunkProtocol (
315 EFI_PHYSICAL_ADDRESS
*
325 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
332 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
338 VOID
SecSleep (UINT64 Milliseconds
);
339 VOID
SecEnableInterrupt (VOID
);
340 VOID
SecDisableInterrupt (VOID
);
341 BOOLEAN
SecInterruptEanbled (VOID
);
344 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
345 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
346 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
347 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
348 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;
349 extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo
;