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>
50 #include <Guid/FileInfo.h>
51 #include <Guid/FileSystemInfo.h>
52 #include <Guid/FileSystemVolumeLabelInfo.h>
57 #include <sys/types.h>
59 #include <sys/termios.h>
63 #include <sys/dirent.h>
79 #include <sys/ioctl.h>
81 #include <sys/socket.h>
83 #include <netinet/in.h>
88 #include <net/if_dl.h>
90 #include <sys/param.h>
91 #include <sys/mount.h>
94 #define _Bool char // for clang debug
106 #define STACK_SIZE 0x20000
109 EFI_PHYSICAL_ADDRESS Address
;
114 EFI_PHYSICAL_ADDRESS Memory
;
119 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
122 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
124 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
131 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
133 EFI_PHYSICAL_ADDRESS
*EntryPoint
145 IN UINTN LargestRegion
,
146 IN UINTN LargestRegionSize
,
147 IN UINTN BootFirmwareVolumeBase
,
154 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
155 IN UINT64
*ImageSize
,
156 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
161 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
167 IN EFI_FV_FILETYPE SearchType
,
168 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
169 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
173 SecFfsFindSectionData (
174 IN EFI_SECTION_TYPE SectionType
,
175 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
176 IN OUT VOID
**SectionData
181 SecUnixPeCoffLoaderLoadAsDll (
182 IN CHAR8
*PdbFileName
,
183 IN VOID
**ImageEntryPoint
,
189 SecUnixPeCoffLoaderFreeLibrary (
197 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
198 IN OUT UINT64
*FdSize
,
199 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
205 GasketSecUnixFdAddress (
207 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
208 IN OUT UINT64
*FdSize
,
209 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
215 GetImageReadFunction (
216 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
217 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
225 IN OUT UINTN
*ReadSize
,
232 IN UINTN
*StrLen OPTIONAL
236 CountSeperatorsInString (
237 IN
const CHAR16
*String
,
243 SecTemporaryRamSupport (
244 IN CONST EFI_PEI_SERVICES
**PeiServices
,
245 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
246 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
252 GasketSecTemporaryRamSupport (
253 IN CONST EFI_PEI_SERVICES
**PeiServices
,
254 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
255 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
262 SecPeCoffGetEntryPoint (
264 IN OUT VOID
**EntryPoint
269 SecPeCoffRelocateImageExtraAction (
270 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
275 SecPeCoffLoaderUnloadImageExtraAction (
276 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
283 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
284 IN VOID
*Context1
, OPTIONAL
285 IN VOID
*Context2
, OPTIONAL
286 IN VOID
*Context3
, 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
;