]> git.proxmox.com Git - mirror_edk2.git/blob - InOsEmuPkg/Unix/Sec/SecMain.h
00ab7a61ab3648d97f6aec6d76efd574b44d546e
[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
50 #include <Guid/FileInfo.h>
51 #include <Guid/FileSystemInfo.h>
52 #include <Guid/FileSystemVolumeLabelInfo.h>
53
54 #include <stdio.h>
55 #include <stdlib.h>
56
57 #include <sys/types.h>
58 #include <sys/stat.h>
59 #include <sys/termios.h>
60 #include <sys/time.h>
61
62 #if __CYGWIN__
63 #include <sys/dirent.h>
64 #else
65 #include <sys/dir.h>
66 #endif
67
68 #include <sys/mman.h>
69 #include <dlfcn.h>
70
71 #include <unistd.h>
72 #include <poll.h>
73 #include <fcntl.h>
74 #include <time.h>
75 #include <signal.h>
76 #include <errno.h>
77 #include <string.h>
78 #include <stdlib.h>
79 #include <sys/ioctl.h>
80
81 #include <sys/socket.h>
82 #include <netdb.h>
83 #include <netinet/in.h>
84 #include <net/if.h>
85 #include <ifaddrs.h>
86
87 #ifdef __APPLE__
88 #include <net/if_dl.h>
89 #include <net/bpf.h>
90 #include <sys/param.h>
91 #include <sys/mount.h>
92 #define _XOPEN_SOURCE
93 #ifndef _Bool
94 #define _Bool char // for clang debug
95 #endif
96 #else
97 #include <termio.h>
98 #include <sys/vfs.h>
99 #endif
100
101 #include <utime.h>
102
103 #include "Gasket.h"
104
105
106 #define STACK_SIZE 0x20000
107
108 typedef struct {
109 EFI_PHYSICAL_ADDRESS Address;
110 UINT64 Size;
111 } EMU_FD_INFO;
112
113 typedef struct {
114 EFI_PHYSICAL_ADDRESS Memory;
115 UINT64 Size;
116 } EMU_SYSTEM_MEMORY;
117
118
119 #define MAX_IMAGE_CONTEXT_TO_MOD_HANDLE_ARRAY_SIZE 0x100
120
121 typedef struct {
122 PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext;
123 VOID *ModHandle;
124 } IMAGE_CONTEXT_TO_MOD_HANDLE;
125
126
127 EFI_STATUS
128 EFIAPI
129 SecUnixPeiLoadFile (
130 VOID *Pe32Data,
131 EFI_PHYSICAL_ADDRESS *ImageAddress,
132 UINT64 *ImageSize,
133 EFI_PHYSICAL_ADDRESS *EntryPoint
134 );
135
136 int
137 main (
138 IN int Argc,
139 IN char **Argv,
140 IN char **Envp
141 );
142
143 VOID
144 SecLoadFromCore (
145 IN UINTN LargestRegion,
146 IN UINTN LargestRegionSize,
147 IN UINTN BootFirmwareVolumeBase,
148 IN VOID *PeiCoreFile
149 );
150
151 EFI_STATUS
152 SecLoadFile (
153 IN VOID *Pe32Data,
154 IN EFI_PHYSICAL_ADDRESS *ImageAddress,
155 IN UINT64 *ImageSize,
156 IN EFI_PHYSICAL_ADDRESS *EntryPoint
157 );
158
159 EFI_STATUS
160 SecFfsFindPeiCore (
161 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
162 OUT VOID **Pe32Data
163 );
164
165 EFI_STATUS
166 SecFfsFindNextFile (
167 IN EFI_FV_FILETYPE SearchType,
168 IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader,
169 IN OUT EFI_FFS_FILE_HEADER **FileHeader
170 );
171
172 EFI_STATUS
173 SecFfsFindSectionData (
174 IN EFI_SECTION_TYPE SectionType,
175 IN EFI_FFS_FILE_HEADER *FfsFileHeader,
176 IN OUT VOID **SectionData
177 );
178
179 EFI_STATUS
180 EFIAPI
181 SecUnixPeCoffLoaderLoadAsDll (
182 IN CHAR8 *PdbFileName,
183 IN VOID **ImageEntryPoint,
184 OUT VOID **ModHandle
185 );
186
187 EFI_STATUS
188 EFIAPI
189 SecUnixPeCoffLoaderFreeLibrary (
190 OUT VOID *ModHandle
191 );
192
193 EFI_STATUS
194 EFIAPI
195 SecUnixFdAddress (
196 IN UINTN Index,
197 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
198 IN OUT UINT64 *FdSize,
199 IN OUT EFI_PHYSICAL_ADDRESS *FixUp
200 )
201 ;
202
203 EFI_STATUS
204 EFIAPI
205 GasketSecUnixFdAddress (
206 IN UINTN Index,
207 IN OUT EFI_PHYSICAL_ADDRESS *FdBase,
208 IN OUT UINT64 *FdSize,
209 IN OUT EFI_PHYSICAL_ADDRESS *FixUp
210 )
211 ;
212
213
214 EFI_STATUS
215 GetImageReadFunction (
216 IN PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext,
217 IN EFI_PHYSICAL_ADDRESS *TopOfMemory
218 );
219
220 EFI_STATUS
221 EFIAPI
222 SecImageRead (
223 IN VOID *FileHandle,
224 IN UINTN FileOffset,
225 IN OUT UINTN *ReadSize,
226 OUT VOID *Buffer
227 );
228
229 CHAR16 *
230 AsciiToUnicode (
231 IN CHAR8 *Ascii,
232 IN UINTN *StrLen OPTIONAL
233 );
234
235 UINTN
236 CountSeperatorsInString (
237 IN const CHAR16 *String,
238 IN CHAR16 Seperator
239 );
240
241 EFI_STATUS
242 EFIAPI
243 SecTemporaryRamSupport (
244 IN CONST EFI_PEI_SERVICES **PeiServices,
245 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
246 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
247 IN UINTN CopySize
248 );
249
250 EFI_STATUS
251 EFIAPI
252 GasketSecTemporaryRamSupport (
253 IN CONST EFI_PEI_SERVICES **PeiServices,
254 IN EFI_PHYSICAL_ADDRESS TemporaryMemoryBase,
255 IN EFI_PHYSICAL_ADDRESS PermanentMemoryBase,
256 IN UINTN CopySize
257 );
258
259
260 RETURN_STATUS
261 EFIAPI
262 SecPeCoffGetEntryPoint (
263 IN VOID *Pe32Data,
264 IN OUT VOID **EntryPoint
265 );
266
267 VOID
268 EFIAPI
269 SecPeCoffRelocateImageExtraAction (
270 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
271 );
272
273 VOID
274 EFIAPI
275 SecPeCoffLoaderUnloadImageExtraAction (
276 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
277 );
278
279
280 VOID
281 EFIAPI
282 PeiSwitchStacks (
283 IN SWITCH_STACK_ENTRY_POINT EntryPoint,
284 IN VOID *Context1, OPTIONAL
285 IN VOID *Context2, OPTIONAL
286 IN VOID *Context3, 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
323
324 #endif