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