]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/Unix/Sec/SecMain.h
Clarify the requirements for the Destination parameter of UnicodeStrToAsciiStr.
[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
2b59fcd5 19//\r
20// Name mangle to prevent build errors. I.e conflicts between EFI and OS\r
21//\r
22#define NTOHL _UNIX_EFI_NAME_MANGLE_NTOHL_\r
23#define HTONL _UNIX_EFI_NAME_MANGLE_HTONL_\r
24#define NTOHS _UNIX_EFI_NAME_MANGLE_NTOHS_\r
25#define HTONS _UNIX_EFI_NAME_MANGLE_HTOHS_\r
26#define B0 _UNIX_EFI_NAME_MANGLE_B0_\r
949f388f 27\r
28#include <stdio.h>\r
29#include <stdlib.h>\r
30\r
31#include <sys/types.h>\r
32#include <sys/stat.h>\r
33#include <sys/termios.h>\r
34#include <sys/time.h>\r
35\r
36#if __CYGWIN__\r
37#include <sys/dirent.h>\r
38#else\r
39#include <sys/dir.h>\r
40#endif\r
41\r
42#include <sys/mman.h>\r
43#include <dlfcn.h>\r
44\r
45#include <unistd.h>\r
46#include <poll.h>\r
47#include <fcntl.h>\r
48#include <time.h>\r
49#include <signal.h>\r
50#include <errno.h>\r
51#include <string.h>\r
52#include <stdlib.h>\r
53#include <sys/ioctl.h>\r
63947cc4 54#include <sys/statvfs.h>\r
949f388f 55\r
56#include <sys/socket.h>\r
57#include <netdb.h>\r
58#include <netinet/in.h>\r
59#include <net/if.h>\r
60#include <ifaddrs.h>\r
61\r
62#ifdef __APPLE__\r
63#include <net/if_dl.h>\r
64#include <net/bpf.h>\r
65#include <sys/param.h>\r
66#include <sys/mount.h>\r
63947cc4 67#include <sys/disk.h>\r
949f388f 68#define _XOPEN_SOURCE\r
69#ifndef _Bool\r
70 #define _Bool char // for clang debug\r
71#endif\r
72#else\r
73#include <termio.h>\r
74#include <sys/vfs.h>\r
63947cc4 75#include <linux/fs.h>\r
949f388f 76#endif \r
77\r
78#include <utime.h>\r
79\r
2b59fcd5 80#undef NTOHL\r
81#undef HTONL\r
82#undef NTOHS\r
83#undef HTONS\r
84#undef B0\r
85\r
86\r
87#include <PiPei.h>\r
88#include <Uefi.h>\r
89\r
90#include <Library/PeCoffLib.h>\r
91#include <Library/BaseLib.h>\r
92#include <Library/BaseMemoryLib.h>\r
b8800fc5 93#include <Library/MemoryAllocationLib.h>\r
2b59fcd5 94#include <Library/PrintLib.h>\r
95#include <Library/PcdLib.h>\r
96#include <Library/DebugLib.h>\r
97#include <Library/ReportStatusCodeLib.h>\r
98\r
99#include <Library/ThunkPpiList.h>\r
100#include <Library/ThunkProtocolList.h>\r
101#include <Library/PeiServicesLib.h>\r
102#include <Library/PeCoffGetEntryPointLib.h>\r
103#include <Library/EmuMagicPageLib.h>\r
104\r
105#include <Ppi/EmuThunk.h>\r
106#include <Ppi/StatusCode.h>\r
107\r
108#include <Protocol/SimplePointer.h>\r
109#include <Protocol/SimpleTextIn.h>\r
110#include <Protocol/SimpleTextInEx.h>\r
111#include <Protocol/UgaDraw.h>\r
112#include <Protocol/SimpleFileSystem.h>\r
113\r
114#include <Protocol/EmuThunk.h>\r
115#include <Protocol/EmuIoThunk.h>\r
116#include <Protocol/EmuGraphicsWindow.h>\r
117#include <Protocol/EmuThread.h>\r
118#include <Protocol/EmuBlockIo.h>\r
119#include <Protocol/EmuSnp.h>\r
120\r
121#include <Guid/FileInfo.h>\r
122#include <Guid/FileSystemInfo.h>\r
123#include <Guid/FileSystemVolumeLabelInfo.h>\r
124\r
125\r
949f388f 126#include "Gasket.h"\r
127\r
128\r
129#define STACK_SIZE 0x20000 \r
130\r
131typedef struct {\r
132 EFI_PHYSICAL_ADDRESS Address;\r
133 UINT64 Size;\r
134} EMU_FD_INFO;\r
135\r
136typedef struct {\r
137 EFI_PHYSICAL_ADDRESS Memory;\r
138 UINT64 Size;\r
139} EMU_SYSTEM_MEMORY;\r
140\r
141\r
142#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
143\r
144typedef struct {\r
145 PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext;\r
146 VOID *ModHandle;\r
147} IMAGE_CONTEXT_TO_MOD_HANDLE;\r
148\r
149\r
150EFI_STATUS\r
151EFIAPI\r
152SecUnixPeiLoadFile (\r
153 VOID *Pe32Data, \r
154 EFI_PHYSICAL_ADDRESS *ImageAddress, \r
155 UINT64 *ImageSize, \r
156 EFI_PHYSICAL_ADDRESS *EntryPoint \r
157 );\r
158\r
159int\r
160main (\r
161 IN int Argc,\r
162 IN char **Argv,\r
163 IN char **Envp\r
164 );\r
165\r
166VOID\r
167SecLoadFromCore (\r
168 IN UINTN LargestRegion,\r
169 IN UINTN LargestRegionSize,\r
170 IN UINTN BootFirmwareVolumeBase,\r
171 IN VOID *PeiCoreFile\r
172 );\r
173\r
174EFI_STATUS\r
175SecLoadFile (\r
176 IN VOID *Pe32Data,\r
177 IN EFI_PHYSICAL_ADDRESS *ImageAddress,\r
178 IN UINT64 *ImageSize,\r
179 IN EFI_PHYSICAL_ADDRESS *EntryPoint\r
180 );\r
181\r
182EFI_STATUS\r
183SecFfsFindPeiCore (\r
184 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
185 OUT VOID **Pe32Data\r
186 );\r
187\r
188EFI_STATUS\r
189SecFfsFindNextFile (\r
190 IN EFI_FV_FILETYPE SearchType,\r
191 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
192 IN OUT EFI_FFS_FILE_HEADER **FileHeader\r
193 );\r
194\r
195EFI_STATUS\r
196SecFfsFindSectionData (\r
197 IN EFI_SECTION_TYPE SectionType,\r
198 IN EFI_FFS_FILE_HEADER *FfsFileHeader,\r
199 IN OUT VOID **SectionData\r
200 );\r
201\r
202EFI_STATUS\r
203EFIAPI\r
204SecUnixPeCoffLoaderLoadAsDll (\r
205 IN CHAR8 *PdbFileName,\r
206 IN VOID **ImageEntryPoint,\r
207 OUT VOID **ModHandle\r
208 );\r
209\r
210EFI_STATUS\r
211EFIAPI\r
212SecUnixPeCoffLoaderFreeLibrary (\r
213 OUT VOID *ModHandle\r
214 );\r
215\r
216EFI_STATUS\r
949f388f 217SecUnixFdAddress (\r
218 IN UINTN Index,\r
219 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
220 IN OUT UINT64 *FdSize,\r
221 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
222 )\r
223;\r
224\r
225EFI_STATUS\r
226EFIAPI\r
227GasketSecUnixFdAddress (\r
228 IN UINTN Index,\r
229 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
230 IN OUT UINT64 *FdSize,\r
231 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
232 )\r
233;\r
234\r
235\r
236EFI_STATUS\r
237GetImageReadFunction (\r
238 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
239 IN EFI_PHYSICAL_ADDRESS *TopOfMemory\r
240 );\r
241\r
242EFI_STATUS\r
243EFIAPI\r
244SecImageRead (\r
245 IN VOID *FileHandle,\r
246 IN UINTN FileOffset,\r
247 IN OUT UINTN *ReadSize,\r
248 OUT VOID *Buffer\r
249 );\r
250\r
251CHAR16 *\r
252AsciiToUnicode (\r
253 IN CHAR8 *Ascii,\r
254 IN UINTN *StrLen OPTIONAL\r
255 );\r
256\r
257UINTN\r
258CountSeperatorsInString (\r
259 IN const CHAR16 *String,\r
260 IN CHAR16 Seperator\r
261 );\r
262\r
263EFI_STATUS\r
264EFIAPI\r
265SecTemporaryRamSupport (\r
266 IN CONST EFI_PEI_SERVICES **PeiServices,\r
267 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
268 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
269 IN UINTN CopySize\r
270 );\r
271 \r
272EFI_STATUS\r
273EFIAPI\r
274GasketSecTemporaryRamSupport (\r
275 IN CONST EFI_PEI_SERVICES **PeiServices,\r
276 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
277 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
278 IN UINTN CopySize\r
279 );\r
280\r
281\r
282RETURN_STATUS\r
283EFIAPI\r
284SecPeCoffGetEntryPoint (\r
285 IN VOID *Pe32Data,\r
286 IN OUT VOID **EntryPoint\r
287 );\r
288\r
289VOID\r
290EFIAPI\r
291SecPeCoffRelocateImageExtraAction (\r
292 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
293 );\r
294\r
295VOID\r
296EFIAPI\r
297SecPeCoffLoaderUnloadImageExtraAction (\r
298 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
299 );\r
300\r
301\r
302VOID\r
949f388f 303PeiSwitchStacks (\r
304 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
305 IN VOID *Context1, OPTIONAL\r
306 IN VOID *Context2, OPTIONAL\r
949f388f 307 IN VOID *NewStack\r
308 );\r
309\r
310VOID\r
311SecInitThunkProtocol (\r
312 VOID\r
313 );\r
65e3f333 314 \r
949f388f 315 \r
65e3f333 316EFI_PHYSICAL_ADDRESS *\r
317MapMemory (\r
318 INTN fd,\r
319 UINT64 length,\r
320 INTN prot,\r
321 INTN flags);\r
322\r
323EFI_STATUS\r
324MapFile (\r
325 IN CHAR8 *FileName,\r
326 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,\r
327 OUT UINT64 *Length\r
328 );\r
329\r
8052c4a2 330EFI_STATUS\r
331MapFd0 (\r
332 IN CHAR8 *FileName,\r
333 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,\r
334 OUT UINT64 *Length\r
335 );\r
336\r
1d7ac5a6 337BOOLEAN\r
338EfiSystemMemoryRange (\r
339 IN VOID *MemoryAddress\r
340 );\r
341\r
949f388f 342\r
1ef41207 343VOID SecSleep (UINT64 Nanoseconds);\r
949f388f 344VOID SecEnableInterrupt (VOID);\r
345VOID SecDisableInterrupt (VOID);\r
346BOOLEAN SecInterruptEanbled (VOID);\r
347\r
348\r
349extern EMU_THUNK_PROTOCOL gEmuThunkProtocol;\r
350extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;\r
351extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;\r
352extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;\r
033d0e5f 353extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;\r
2b59fcd5 354extern EMU_IO_THUNK_PROTOCOL gSnpThunkIo;\r
949f388f 355\r
356#endif\r