]> git.proxmox.com Git - mirror_edk2.git/blame - InOsEmuPkg/Unix/Sec/SecMain.h
Fix X64 clang warnings.
[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
81\r
82#include <sys/socket.h>\r
83#include <netdb.h>\r
84#include <netinet/in.h>\r
85#include <net/if.h>\r
86#include <ifaddrs.h>\r
87\r
88#ifdef __APPLE__\r
89#include <net/if_dl.h>\r
90#include <net/bpf.h>\r
91#include <sys/param.h>\r
92#include <sys/mount.h>\r
93#define _XOPEN_SOURCE\r
94#ifndef _Bool\r
95 #define _Bool char // for clang debug\r
96#endif\r
97#else\r
98#include <termio.h>\r
99#include <sys/vfs.h>\r
100#endif \r
101\r
102#include <utime.h>\r
103\r
104#include "Gasket.h"\r
105\r
106\r
107#define STACK_SIZE 0x20000 \r
108\r
109typedef struct {\r
110 EFI_PHYSICAL_ADDRESS Address;\r
111 UINT64 Size;\r
112} EMU_FD_INFO;\r
113\r
114typedef struct {\r
115 EFI_PHYSICAL_ADDRESS Memory;\r
116 UINT64 Size;\r
117} EMU_SYSTEM_MEMORY;\r
118\r
119\r
120#define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100\r
121\r
122typedef struct {\r
123 PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext;\r
124 VOID *ModHandle;\r
125} IMAGE_CONTEXT_TO_MOD_HANDLE;\r
126\r
127\r
128EFI_STATUS\r
129EFIAPI\r
130SecUnixPeiLoadFile (\r
131 VOID *Pe32Data, \r
132 EFI_PHYSICAL_ADDRESS *ImageAddress, \r
133 UINT64 *ImageSize, \r
134 EFI_PHYSICAL_ADDRESS *EntryPoint \r
135 );\r
136\r
137int\r
138main (\r
139 IN int Argc,\r
140 IN char **Argv,\r
141 IN char **Envp\r
142 );\r
143\r
144VOID\r
145SecLoadFromCore (\r
146 IN UINTN LargestRegion,\r
147 IN UINTN LargestRegionSize,\r
148 IN UINTN BootFirmwareVolumeBase,\r
149 IN VOID *PeiCoreFile\r
150 );\r
151\r
152EFI_STATUS\r
153SecLoadFile (\r
154 IN VOID *Pe32Data,\r
155 IN EFI_PHYSICAL_ADDRESS *ImageAddress,\r
156 IN UINT64 *ImageSize,\r
157 IN EFI_PHYSICAL_ADDRESS *EntryPoint\r
158 );\r
159\r
160EFI_STATUS\r
161SecFfsFindPeiCore (\r
162 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
163 OUT VOID **Pe32Data\r
164 );\r
165\r
166EFI_STATUS\r
167SecFfsFindNextFile (\r
168 IN EFI_FV_FILETYPE SearchType,\r
169 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,\r
170 IN OUT EFI_FFS_FILE_HEADER **FileHeader\r
171 );\r
172\r
173EFI_STATUS\r
174SecFfsFindSectionData (\r
175 IN EFI_SECTION_TYPE SectionType,\r
176 IN EFI_FFS_FILE_HEADER *FfsFileHeader,\r
177 IN OUT VOID **SectionData\r
178 );\r
179\r
180EFI_STATUS\r
181EFIAPI\r
182SecUnixPeCoffLoaderLoadAsDll (\r
183 IN CHAR8 *PdbFileName,\r
184 IN VOID **ImageEntryPoint,\r
185 OUT VOID **ModHandle\r
186 );\r
187\r
188EFI_STATUS\r
189EFIAPI\r
190SecUnixPeCoffLoaderFreeLibrary (\r
191 OUT VOID *ModHandle\r
192 );\r
193\r
194EFI_STATUS\r
195EFIAPI\r
196SecUnixFdAddress (\r
197 IN UINTN Index,\r
198 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
199 IN OUT UINT64 *FdSize,\r
200 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
201 )\r
202;\r
203\r
204EFI_STATUS\r
205EFIAPI\r
206GasketSecUnixFdAddress (\r
207 IN UINTN Index,\r
208 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,\r
209 IN OUT UINT64 *FdSize,\r
210 IN OUT EFI_PHYSICAL_ADDRESS *FixUp\r
211 )\r
212;\r
213\r
214\r
215EFI_STATUS\r
216GetImageReadFunction (\r
217 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,\r
218 IN EFI_PHYSICAL_ADDRESS *TopOfMemory\r
219 );\r
220\r
221EFI_STATUS\r
222EFIAPI\r
223SecImageRead (\r
224 IN VOID *FileHandle,\r
225 IN UINTN FileOffset,\r
226 IN OUT UINTN *ReadSize,\r
227 OUT VOID *Buffer\r
228 );\r
229\r
230CHAR16 *\r
231AsciiToUnicode (\r
232 IN CHAR8 *Ascii,\r
233 IN UINTN *StrLen OPTIONAL\r
234 );\r
235\r
236UINTN\r
237CountSeperatorsInString (\r
238 IN const CHAR16 *String,\r
239 IN CHAR16 Seperator\r
240 );\r
241\r
242EFI_STATUS\r
243EFIAPI\r
244SecTemporaryRamSupport (\r
245 IN CONST EFI_PEI_SERVICES **PeiServices,\r
246 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
247 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
248 IN UINTN CopySize\r
249 );\r
250 \r
251EFI_STATUS\r
252EFIAPI\r
253GasketSecTemporaryRamSupport (\r
254 IN CONST EFI_PEI_SERVICES **PeiServices,\r
255 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,\r
256 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,\r
257 IN UINTN CopySize\r
258 );\r
259\r
260\r
261RETURN_STATUS\r
262EFIAPI\r
263SecPeCoffGetEntryPoint (\r
264 IN VOID *Pe32Data,\r
265 IN OUT VOID **EntryPoint\r
266 );\r
267\r
268VOID\r
269EFIAPI\r
270SecPeCoffRelocateImageExtraAction (\r
271 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
272 );\r
273\r
274VOID\r
275EFIAPI\r
276SecPeCoffLoaderUnloadImageExtraAction (\r
277 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext\r
278 );\r
279\r
280\r
281VOID\r
282EFIAPI\r
283PeiSwitchStacks (\r
284 IN SWITCH_STACK_ENTRY_POINT EntryPoint,\r
285 IN VOID *Context1, OPTIONAL\r
286 IN VOID *Context2, OPTIONAL\r
949f388f 287 IN VOID *NewStack\r
288 );\r
289\r
290VOID\r
291SecInitThunkProtocol (\r
292 VOID\r
293 );\r
65e3f333 294 \r
949f388f 295 \r
65e3f333 296EFI_PHYSICAL_ADDRESS *\r
297MapMemory (\r
298 INTN fd,\r
299 UINT64 length,\r
300 INTN prot,\r
301 INTN flags);\r
302\r
303EFI_STATUS\r
304MapFile (\r
305 IN CHAR8 *FileName,\r
306 IN OUT EFI_PHYSICAL_ADDRESS *BaseAddress,\r
307 OUT UINT64 *Length\r
308 );\r
309\r
310 \r
949f388f 311\r
312VOID SecSleep (UINT64 Milliseconds);\r
313VOID SecEnableInterrupt (VOID);\r
314VOID SecDisableInterrupt (VOID);\r
315BOOLEAN SecInterruptEanbled (VOID);\r
316\r
317\r
318extern EMU_THUNK_PROTOCOL gEmuThunkProtocol;\r
319extern EMU_IO_THUNK_PROTOCOL gX11ThunkIo;\r
320extern EMU_IO_THUNK_PROTOCOL gPosixFileSystemThunkIo;\r
321extern EMU_IO_THUNK_PROTOCOL gPthreadThunkIo;\r
033d0e5f 322extern EMU_IO_THUNK_PROTOCOL gBlockIoThunkIo;\r
949f388f 323\r
324#endif\r