]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/Unix/Sec/SecMain.h
InOsEmuPkg: Fixed mounting device nodes and .dmg files in the emulator.
[mirror_edk2.git] / InOsEmuPkg / Unix / Sec / SecMain.h
CommitLineData
949f388f 1/*++ @file\r
2\r
10d1be3e 3Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
949f388f 4Portions copyright (c) 2008 - 2011, Apple Inc. All rights reserved.<BR>\r
10d1be3e 5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
949f388f 13\r
14**/\r
15\r
16#ifndef _SEC_MAIN_H__\r
17#define _SEC_MAIN_H__\r
18\r
19#include <PiPei.h>\r
20#include <Uefi.h>\r
21\r
22#include <Library/PeCoffLib.h>\r
23#include <Library/BaseLib.h>\r
24#include <Library/BaseMemoryLib.h>\r
25#include <Library/PrintLib.h>\r
26#include <Library/PcdLib.h>\r
27#include <Library/DebugLib.h>\r
28#include <Library/ReportStatusCodeLib.h>\r
29\r
30#include <Library/ThunkPpiList.h>\r
31#include <Library/ThunkProtocolList.h>\r
65e3f333 32#include <Library/PpiListLib.h>\r
33#include <Library/PeiServicesLib.h>\r
34#include <Library/PeCoffGetEntryPointLib.h>\r
949f388f 35\r
36#include <Ppi/EmuThunk.h>\r
37#include <Ppi/StatusCode.h>\r
949f388f 38\r
39#include <Protocol/SimplePointer.h>\r
40#include <Protocol/SimpleTextIn.h>\r
41#include <Protocol/SimpleTextInEx.h>\r
42#include <Protocol/UgaDraw.h>\r
43#include <Protocol/SimpleFileSystem.h>\r
44\r
45#include <Protocol/EmuThunk.h>\r
46#include <Protocol/EmuIoThunk.h>\r
47#include <Protocol/EmuGraphicsWindow.h>\r
10d1be3e 48#include <Protocol/EmuThread.h>\r
033d0e5f 49#include <Protocol/EmuBlockIo.h>\r
949f388f 50\r
51#include <Guid/FileInfo.h>\r
52#include <Guid/FileSystemInfo.h>\r
53#include <Guid/FileSystemVolumeLabelInfo.h>\r
54\r
55#include <stdio.h>\r
56#include <stdlib.h>\r
57\r
58#include <sys/types.h>\r
59#include <sys/stat.h>\r
60#include <sys/termios.h>\r
61#include <sys/time.h>\r
62\r
63#if __CYGWIN__\r
64#include <sys/dirent.h>\r
65#else\r
66#include <sys/dir.h>\r
67#endif\r
68\r
69#include <sys/mman.h>\r
70#include <dlfcn.h>\r
71\r
72#include <unistd.h>\r
73#include <poll.h>\r
74#include <fcntl.h>\r
75#include <time.h>\r
76#include <signal.h>\r
77#include <errno.h>\r
78#include <string.h>\r
79#include <stdlib.h>\r
80#include <sys/ioctl.h>\r
63947cc4 81#include <sys/statvfs.h>\r
949f388f 82\r
83#include <sys/socket.h>\r
84#include <netdb.h>\r
85#include <netinet/in.h>\r
86#include <net/if.h>\r
87#include <ifaddrs.h>\r
88\r
89#ifdef __APPLE__\r
90#include <net/if_dl.h>\r
91#include <net/bpf.h>\r
92#include <sys/param.h>\r
93#include <sys/mount.h>\r
63947cc4 94#include <sys/disk.h>\r
949f388f 95#define _XOPEN_SOURCE\r
96#ifndef _Bool\r
97 #define _Bool char // for clang debug\r
98#endif\r
99#else\r
100#include <termio.h>\r
101#include <sys/vfs.h>\r
63947cc4 102#include <linux/fs.h>\r
949f388f 103#endif \r
104\r
105#include <utime.h>\r
106\r
107#include "Gasket.h"\r
108\r
109\r
110#define STACK_SIZE 0x20000 \r
111\r
112typedef struct {\r
113 EFI_PHYSICAL_ADDRESS Address;\r
114 UINT64 Size;\r
115} EMU_FD_INFO;\r
116\r
117typedef struct {\r
118 EFI_PHYSICAL_ADDRESS Memory;\r
119 UINT64 Size;\r
120} EMU_SYSTEM_MEMORY;\r
121\r
122\r
123#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
124\r
125typedef struct {\r
126 PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext;\r
127 VOID *ModHandle;\r
128} IMAGE_CONTEXT_TO_MOD_HANDLE;\r
129\r
130\r
131EFI_STATUS\r
132EFIAPI\r
133SecUnixPeiLoadFile (\r
134 VOID *Pe32Data, \r
135 EFI_PHYSICAL_ADDRESS *ImageAddress, \r
136 UINT64 *ImageSize, \r
137 EFI_PHYSICAL_ADDRESS *EntryPoint \r
138 );\r
139\r
140int\r
141main (\r
142 IN int Argc,\r
143 IN char **Argv,\r
144 IN char **Envp\r
145 );\r
146\r
147VOID\r
148SecLoadFromCore (\r
149 IN UINTN LargestRegion,\r
150 IN UINTN LargestRegionSize,\r
151 IN UINTN BootFirmwareVolumeBase,\r
152 IN VOID *PeiCoreFile\r
153 );\r
154\r
155EFI_STATUS\r
156SecLoadFile (\r
157 IN VOID *Pe32Data,\r
158 IN EFI_PHYSICAL_ADDRESS *ImageAddress,\r
159 IN UINT64 *ImageSize,\r
160 IN EFI_PHYSICAL_ADDRESS *EntryPoint\r
161 );\r
162\r
163EFI_STATUS\r
164SecFfsFindPeiCore (\r
165 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
166 OUT VOID **Pe32Data\r
167 );\r
168\r
169EFI_STATUS\r
170SecFfsFindNextFile (\r
171 IN EFI_FV_FILETYPE SearchType,\r
172 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
173 IN OUT EFI_FFS_FILE_HEADER **FileHeader\r
174 );\r
175\r
176EFI_STATUS\r
177SecFfsFindSectionData (\r
178 IN EFI_SECTION_TYPE SectionType,\r
179 IN EFI_FFS_FILE_HEADER *FfsFileHeader,\r
180 IN OUT VOID **SectionData\r
181 );\r
182\r
183EFI_STATUS\r
184EFIAPI\r
185SecUnixPeCoffLoaderLoadAsDll (\r
186 IN CHAR8 *PdbFileName,\r
187 IN VOID **ImageEntryPoint,\r
188 OUT VOID **ModHandle\r
189 );\r
190\r
191EFI_STATUS\r
192EFIAPI\r
193SecUnixPeCoffLoaderFreeLibrary (\r
194 OUT VOID *ModHandle\r
195 );\r
196\r
197EFI_STATUS\r
198EFIAPI\r
199SecUnixFdAddress (\r
200 IN UINTN Index,\r
201 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
202 IN OUT UINT64 *FdSize,\r
203 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
204 )\r
205;\r
206\r
207EFI_STATUS\r
208EFIAPI\r
209GasketSecUnixFdAddress (\r
210 IN UINTN Index,\r
211 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
212 IN OUT UINT64 *FdSize,\r
213 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
214 )\r
215;\r
216\r
217\r
218EFI_STATUS\r
219GetImageReadFunction (\r
220 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
221 IN EFI_PHYSICAL_ADDRESS *TopOfMemory\r
222 );\r
223\r
224EFI_STATUS\r
225EFIAPI\r
226SecImageRead (\r
227 IN VOID *FileHandle,\r
228 IN UINTN FileOffset,\r
229 IN OUT UINTN *ReadSize,\r
230 OUT VOID *Buffer\r
231 );\r
232\r
233CHAR16 *\r
234AsciiToUnicode (\r
235 IN CHAR8 *Ascii,\r
236 IN UINTN *StrLen OPTIONAL\r
237 );\r
238\r
239UINTN\r
240CountSeperatorsInString (\r
241 IN const CHAR16 *String,\r
242 IN CHAR16 Seperator\r
243 );\r
244\r
245EFI_STATUS\r
246EFIAPI\r
247SecTemporaryRamSupport (\r
248 IN CONST EFI_PEI_SERVICES **PeiServices,\r
249 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
250 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
251 IN UINTN CopySize\r
252 );\r
253 \r
254EFI_STATUS\r
255EFIAPI\r
256GasketSecTemporaryRamSupport (\r
257 IN CONST EFI_PEI_SERVICES **PeiServices,\r
258 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
259 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
260 IN UINTN CopySize\r
261 );\r
262\r
263\r
264RETURN_STATUS\r
265EFIAPI\r
266SecPeCoffGetEntryPoint (\r
267 IN VOID *Pe32Data,\r
268 IN OUT VOID **EntryPoint\r
269 );\r
270\r
271VOID\r
272EFIAPI\r
273SecPeCoffRelocateImageExtraAction (\r
274 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
275 );\r
276\r
277VOID\r
278EFIAPI\r
279SecPeCoffLoaderUnloadImageExtraAction (\r
280 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
281 );\r
282\r
283\r
284VOID\r
285EFIAPI\r
286PeiSwitchStacks (\r
287 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
288 IN VOID *Context1, OPTIONAL\r
289 IN VOID *Context2, OPTIONAL\r
949f388f 290 IN VOID *NewStack\r
291 );\r
292\r
293VOID\r
294SecInitThunkProtocol (\r
295 VOID\r
296 );\r
65e3f333 297 \r
949f388f 298 \r
65e3f333 299EFI_PHYSICAL_ADDRESS *\r
300MapMemory (\r
301 INTN fd,\r
302 UINT64 length,\r
303 INTN prot,\r
304 INTN flags);\r
305\r
306EFI_STATUS\r
307MapFile (\r
308 IN CHAR8 *FileName,\r
309 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,\r
310 OUT UINT64 *Length\r
311 );\r
312\r
313 \r
949f388f 314\r
315VOID SecSleep (UINT64 Milliseconds);\r
316VOID SecEnableInterrupt (VOID);\r
317VOID SecDisableInterrupt (VOID);\r
318BOOLEAN SecInterruptEanbled (VOID);\r
319\r
320\r
321extern EMU_THUNK_PROTOCOL gEmuThunkProtocol;\r
322extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;\r
323extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;\r
324extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;\r
033d0e5f 325extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;\r
949f388f 326\r
327#endif\r