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