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>
31 #include <Library/PpiListLib.h>
32 #include <Library/PeiServicesLib.h>
33 #include <Library/PeCoffGetEntryPointLib.h>
35 #include <Ppi/EmuThunk.h>
36 #include <Ppi/StatusCode.h>
38 #include <Protocol/SimplePointer.h>
39 #include <Protocol/SimpleTextIn.h>
40 #include <Protocol/SimpleTextInEx.h>
41 #include <Protocol/UgaDraw.h>
42 #include <Protocol/SimpleFileSystem.h>
44 #include <Protocol/EmuThunk.h>
45 #include <Protocol/EmuIoThunk.h>
46 #include <Protocol/EmuGraphicsWindow.h>
47 #include <Protocol/EmuPthreadThunk.h>
49 #include <Guid/FileInfo.h>
50 #include <Guid/FileSystemInfo.h>
51 #include <Guid/FileSystemVolumeLabelInfo.h>
56 #include <sys/types.h>
58 #include <sys/termios.h>
62 #include <sys/dirent.h>
78 #include <sys/ioctl.h>
80 #include <sys/socket.h>
82 #include <netinet/in.h>
87 #include <net/if_dl.h>
89 #include <sys/param.h>
90 #include <sys/mount.h>
93 #define _Bool char // for clang debug
105 #define STACK_SIZE 0x20000
108 EFI_PHYSICAL_ADDRESS Address
;
113 EFI_PHYSICAL_ADDRESS Memory
;
118 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
121 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
123 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
130 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
132 EFI_PHYSICAL_ADDRESS
*EntryPoint
144 IN UINTN LargestRegion
,
145 IN UINTN LargestRegionSize
,
146 IN UINTN BootFirmwareVolumeBase
,
153 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
154 IN UINT64
*ImageSize
,
155 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
160 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
166 IN EFI_FV_FILETYPE SearchType
,
167 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
168 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
172 SecFfsFindSectionData (
173 IN EFI_SECTION_TYPE SectionType
,
174 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
175 IN OUT VOID
**SectionData
180 SecUnixPeCoffLoaderLoadAsDll (
181 IN CHAR8
*PdbFileName
,
182 IN VOID
**ImageEntryPoint
,
188 SecUnixPeCoffLoaderFreeLibrary (
196 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
197 IN OUT UINT64
*FdSize
,
198 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
204 GasketSecUnixFdAddress (
206 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
207 IN OUT UINT64
*FdSize
,
208 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
214 GetImageReadFunction (
215 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
216 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
224 IN OUT UINTN
*ReadSize
,
231 IN UINTN
*StrLen OPTIONAL
235 CountSeperatorsInString (
236 IN
const CHAR16
*String
,
242 SecTemporaryRamSupport (
243 IN CONST EFI_PEI_SERVICES
**PeiServices
,
244 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
245 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
251 GasketSecTemporaryRamSupport (
252 IN CONST EFI_PEI_SERVICES
**PeiServices
,
253 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
254 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
261 SecPeCoffGetEntryPoint (
263 IN OUT VOID
**EntryPoint
268 SecPeCoffRelocateImageExtraAction (
269 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
274 SecPeCoffLoaderUnloadImageExtraAction (
275 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
282 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
283 IN VOID
*Context1
, OPTIONAL
284 IN VOID
*Context2
, OPTIONAL
285 IN VOID
*Context3
, OPTIONAL
290 SecInitThunkProtocol (
295 EFI_PHYSICAL_ADDRESS
*
305 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
311 VOID
SecSleep (UINT64 Milliseconds
);
312 VOID
SecEnableInterrupt (VOID
);
313 VOID
SecDisableInterrupt (VOID
);
314 BOOLEAN
SecInterruptEanbled (VOID
);
317 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
318 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
319 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
320 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;