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/PeiServicesLib.h>
33 #include <Library/PeCoffGetEntryPointLib.h>
34 #include <Library/EmuMagicPageLib.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>
81 #include <sys/statvfs.h>
83 #include <sys/socket.h>
85 #include <netinet/in.h>
90 #include <net/if_dl.h>
92 #include <sys/param.h>
93 #include <sys/mount.h>
97 #define _Bool char // for clang debug
102 #include <linux/fs.h>
110 #define STACK_SIZE 0x20000
113 EFI_PHYSICAL_ADDRESS Address
;
118 EFI_PHYSICAL_ADDRESS Memory
;
123 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
126 PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
;
128 } IMAGE_CONTEXT_TO_MOD_HANDLE
;
135 EFI_PHYSICAL_ADDRESS
*ImageAddress
,
137 EFI_PHYSICAL_ADDRESS
*EntryPoint
149 IN UINTN LargestRegion
,
150 IN UINTN LargestRegionSize
,
151 IN UINTN BootFirmwareVolumeBase
,
158 IN EFI_PHYSICAL_ADDRESS
*ImageAddress
,
159 IN UINT64
*ImageSize
,
160 IN EFI_PHYSICAL_ADDRESS
*EntryPoint
165 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
171 IN EFI_FV_FILETYPE SearchType
,
172 IN EFI_FIRMWARE_VOLUME_HEADER
*FwVolHeader
,
173 IN OUT EFI_FFS_FILE_HEADER
**FileHeader
177 SecFfsFindSectionData (
178 IN EFI_SECTION_TYPE SectionType
,
179 IN EFI_FFS_FILE_HEADER
*FfsFileHeader
,
180 IN OUT VOID
**SectionData
185 SecUnixPeCoffLoaderLoadAsDll (
186 IN CHAR8
*PdbFileName
,
187 IN VOID
**ImageEntryPoint
,
193 SecUnixPeCoffLoaderFreeLibrary (
201 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
202 IN OUT UINT64
*FdSize
,
203 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
209 GasketSecUnixFdAddress (
211 IN OUT EFI_PHYSICAL_ADDRESS
*FdBase
,
212 IN OUT UINT64
*FdSize
,
213 IN OUT EFI_PHYSICAL_ADDRESS
*FixUp
219 GetImageReadFunction (
220 IN PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
,
221 IN EFI_PHYSICAL_ADDRESS
*TopOfMemory
229 IN OUT UINTN
*ReadSize
,
236 IN UINTN
*StrLen OPTIONAL
240 CountSeperatorsInString (
241 IN
const CHAR16
*String
,
247 SecTemporaryRamSupport (
248 IN CONST EFI_PEI_SERVICES
**PeiServices
,
249 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
250 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
256 GasketSecTemporaryRamSupport (
257 IN CONST EFI_PEI_SERVICES
**PeiServices
,
258 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase
,
259 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase
,
266 SecPeCoffGetEntryPoint (
268 IN OUT VOID
**EntryPoint
273 SecPeCoffRelocateImageExtraAction (
274 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
279 SecPeCoffLoaderUnloadImageExtraAction (
280 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
287 IN SWITCH_STACK_ENTRY_POINT EntryPoint
,
288 IN VOID
*Context1
, OPTIONAL
289 IN VOID
*Context2
, OPTIONAL
294 SecInitThunkProtocol (
299 EFI_PHYSICAL_ADDRESS
*
309 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
316 IN OUT EFI_PHYSICAL_ADDRESS
*BaseAddress
,
322 VOID
SecSleep (UINT64 Milliseconds
);
323 VOID
SecEnableInterrupt (VOID
);
324 VOID
SecDisableInterrupt (VOID
);
325 BOOLEAN
SecInterruptEanbled (VOID
);
328 extern EMU_THUNK_PROTOCOL gEmuThunkProtocol
;
329 extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo
;
330 extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo
;
331 extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo
;
332 extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo
;