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