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