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 (
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
305 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
306 IN VOID
*Context1
, OPTIONAL
307 IN VOID
*Context2
, OPTIONAL
312 SecInitThunkProtocol (
317 EFI_PHYSICAL_ADDRESS
*
327 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
334 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
340 VOID
SecSleep (UINT64 Milliseconds
);
341 VOID
SecEnableInterrupt (VOID
);
342 VOID
SecDisableInterrupt (VOID
);
343 BOOLEAN
SecInterruptEanbled (VOID
);
346 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
347 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
348 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
349 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
350 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;
351 extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo
;