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