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