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.
22 #include <Library/PeCoffLib.h>
23 #include <Library/BaseLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/PrintLib.h>
26 #include <Library/PcdLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/ThunkPpiList.h>
31 #include <Library/ThunkProtocolList.h>
32 #include <Library/PpiListLib.h>
33 #include <Library/PeiServicesLib.h>
34 #include <Library/PeCoffGetEntryPointLib.h>
36 #include <Ppi/EmuThunk.h>
37 #include <Ppi/StatusCode.h>
39 #include <Protocol/SimplePointer.h>
40 #include <Protocol/SimpleTextIn.h>
41 #include <Protocol/SimpleTextInEx.h>
42 #include <Protocol/UgaDraw.h>
43 #include <Protocol/SimpleFileSystem.h>
45 #include <Protocol/EmuThunk.h>
46 #include <Protocol/EmuIoThunk.h>
47 #include <Protocol/EmuGraphicsWindow.h>
48 #include <Protocol/EmuThread.h>
49 #include <Protocol/EmuBlockIo.h>
51 #include <Guid/FileInfo.h>
52 #include <Guid/FileSystemInfo.h>
53 #include <Guid/FileSystemVolumeLabelInfo.h>
58 #include <sys/types.h>
60 #include <sys/termios.h>
64 #include <sys/dirent.h>
80 #include <sys/ioctl.h>
82 #include <sys/socket.h>
84 #include <netinet/in.h>
89 #include <net/if_dl.h>
91 #include <sys/param.h>
92 #include <sys/mount.h>
95 #define _Bool char // for clang debug
107 #define STACK_SIZE 0x20000
110 EFI_PHYSICAL_ADDRESS Address
;
115 EFI_PHYSICAL_ADDRESS Memory
;
120 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
123 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
125 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
132 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
134 EFI_PHYSICAL_ADDRESS
*EntryPoint
146 IN UINTN LargestRegion
,
147 IN UINTN LargestRegionSize
,
148 IN UINTN BootFirmwareVolumeBase
,
155 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
156 IN UINT64
*ImageSize
,
157 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
162 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
168 IN EFI_FV_FILETYPE SearchType
,
169 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
170 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
174 SecFfsFindSectionData (
175 IN EFI_SECTION_TYPE SectionType
,
176 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
177 IN OUT VOID
**SectionData
182 SecUnixPeCoffLoaderLoadAsDll (
183 IN CHAR8
*PdbFileName
,
184 IN VOID
**ImageEntryPoint
,
190 SecUnixPeCoffLoaderFreeLibrary (
198 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
199 IN OUT UINT64
*FdSize
,
200 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
206 GasketSecUnixFdAddress (
208 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
209 IN OUT UINT64
*FdSize
,
210 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
216 GetImageReadFunction (
217 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
218 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
226 IN OUT UINTN
*ReadSize
,
233 IN UINTN
*StrLen OPTIONAL
237 CountSeperatorsInString (
238 IN
const CHAR16
*String
,
244 SecTemporaryRamSupport (
245 IN CONST EFI_PEI_SERVICES
**PeiServices
,
246 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
247 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
253 GasketSecTemporaryRamSupport (
254 IN CONST EFI_PEI_SERVICES
**PeiServices
,
255 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
256 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
263 SecPeCoffGetEntryPoint (
265 IN OUT VOID
**EntryPoint
270 SecPeCoffRelocateImageExtraAction (
271 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
276 SecPeCoffLoaderUnloadImageExtraAction (
277 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
284 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
285 IN VOID
*Context1
, OPTIONAL
286 IN VOID
*Context2
, OPTIONAL
291 SecInitThunkProtocol (
296 EFI_PHYSICAL_ADDRESS
*
306 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
312 VOID
SecSleep (UINT64 Milliseconds
);
313 VOID
SecEnableInterrupt (VOID
);
314 VOID
SecDisableInterrupt (VOID
);
315 BOOLEAN
SecInterruptEanbled (VOID
);
318 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
319 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
320 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
321 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
322 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;