3 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Library/PeCoffLib.h>
22 #include <Library/BaseLib.h>
23 #include <Library/BaseMemoryLib.h>
24 #include <Library/PrintLib.h>
25 #include <Library/PcdLib.h>
26 #include <Library/DebugLib.h>
27 #include <Library/ReportStatusCodeLib.h>
29 #include <Library/ThunkPpiList.h>
30 #include <Library/ThunkProtocolList.h>
32 #include <Ppi/EmuThunk.h>
33 #include <Ppi/StatusCode.h>
34 #include <Ppi/TemporaryRamSupport.h>
35 #include <Ppi/EmuPeiServicesTableUpdate.h>
37 #include <Protocol/SimplePointer.h>
38 #include <Protocol/SimpleTextIn.h>
39 #include <Protocol/SimpleTextInEx.h>
40 #include <Protocol/UgaDraw.h>
41 #include <Protocol/SimpleFileSystem.h>
43 #include <Protocol/EmuThunk.h>
44 #include <Protocol/EmuIoThunk.h>
45 #include <Protocol/EmuGraphicsWindow.h>
46 #include <Protocol/EmuPthreadThunk.h>
48 #include <Guid/FileInfo.h>
49 #include <Guid/FileSystemInfo.h>
50 #include <Guid/FileSystemVolumeLabelInfo.h>
55 #include <sys/types.h>
57 #include <sys/termios.h>
61 #include <sys/dirent.h>
77 #include <sys/ioctl.h>
79 #include <sys/socket.h>
81 #include <netinet/in.h>
86 #include <net/if_dl.h>
88 #include <sys/param.h>
89 #include <sys/mount.h>
92 #define _Bool char // for clang debug
104 #define STACK_SIZE 0x20000
107 EFI_PHYSICAL_ADDRESS Address
;
112 EFI_PHYSICAL_ADDRESS Memory
;
117 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
120 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
122 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
129 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
131 EFI_PHYSICAL_ADDRESS
*EntryPoint
143 IN UINTN LargestRegion
,
144 IN UINTN LargestRegionSize
,
145 IN UINTN BootFirmwareVolumeBase
,
152 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
153 IN UINT64
*ImageSize
,
154 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
159 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
165 IN EFI_FV_FILETYPE SearchType
,
166 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
167 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
171 SecFfsFindSectionData (
172 IN EFI_SECTION_TYPE SectionType
,
173 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
174 IN OUT VOID
**SectionData
179 SecUnixPeCoffLoaderLoadAsDll (
180 IN CHAR8
*PdbFileName
,
181 IN VOID
**ImageEntryPoint
,
187 SecUnixPeCoffLoaderFreeLibrary (
195 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
196 IN OUT UINT64
*FdSize
,
197 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
203 GasketSecUnixFdAddress (
205 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
206 IN OUT UINT64
*FdSize
,
207 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
213 GetImageReadFunction (
214 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
215 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
223 IN OUT UINTN
*ReadSize
,
230 IN UINTN
*StrLen OPTIONAL
234 CountSeperatorsInString (
235 IN
const CHAR16
*String
,
241 SecTemporaryRamSupport (
242 IN CONST EFI_PEI_SERVICES
**PeiServices
,
243 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
244 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
250 GasketSecTemporaryRamSupport (
251 IN CONST EFI_PEI_SERVICES
**PeiServices
,
252 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
253 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
260 SecPeCoffGetEntryPoint (
262 IN OUT VOID
**EntryPoint
267 SecPeCoffRelocateImageExtraAction (
268 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
273 SecPeCoffLoaderUnloadImageExtraAction (
274 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
281 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
282 IN VOID
*Context1
, OPTIONAL
283 IN VOID
*Context2
, OPTIONAL
284 IN VOID
*Context3
, OPTIONAL
289 SecInitThunkProtocol (
294 VOID
SecSleep (UINT64 Milliseconds
);
295 VOID
SecEnableInterrupt (VOID
);
296 VOID
SecDisableInterrupt (VOID
);
297 BOOLEAN
SecInterruptEanbled (VOID
);
300 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
301 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
302 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
303 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;