]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Include/Protocol/UnixThunk.h
Adding Simple Pointer, GOP, SimpleTextInEx, and Networking protocols to the emulator...
[mirror_edk2.git] / UnixPkg / Include / Protocol / UnixThunk.h
1 /*++
2
3 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2010, 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 Module Name:
14
15 UnixThunk.h
16
17 Abstract:
18
19 This protocol allows an EFI driver in the Unix emulation environment
20 to make Posix calls.
21
22 NEVER make an Unix call directly, always make the call via this protocol.
23
24 There are no This pointers on the protocol member functions as they map
25 exactly into Unix system calls.
26
27 --*/
28
29 #ifndef _UNIX_THUNK_H_
30 #define _UNIX_THUNK_H_
31
32 #include <sys/termios.h>
33 #include <stdio.h>
34 #include <sys/time.h>
35
36 #if __CYGWIN__
37 #include <sys/dirent.h>
38 #else
39 #include <sys/dir.h>
40 #endif
41
42 #include <unistd.h>
43 #include <poll.h>
44 #include <sys/types.h>
45 #include <sys/stat.h>
46 #include <fcntl.h>
47 #include <time.h>
48 #include <signal.h>
49 #include <errno.h>
50 #include <string.h>
51 #include <stdlib.h>
52 #include <sys/ioctl.h>
53
54 #include <sys/socket.h>
55 #include <netdb.h>
56 #include <netinet/in.h>
57 #include <net/if.h>
58 #include <net/if_dl.h>
59 #include <ifaddrs.h>
60 #include <net/bpf.h>
61
62 #ifdef __APPLE__
63 #include <sys/param.h>
64 #include <sys/mount.h>
65 #define _XOPEN_SOURCE
66 #ifndef _Bool
67 #define _Bool char // for clang debug
68 #endif
69 #else
70 #include <termio.h>
71 #include <sys/vfs.h>
72 #endif
73
74 #include <utime.h>
75
76 #include <Base.h>
77 #include <Library/PeCoffLib.h>
78
79
80 #if __APPLE__
81 //
82 // EFI packing is not compatible witht he default OS packing for struct stat.
83 // st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler
84 // flags used to produce compatible EFI images, break struct stat
85 //
86 #ifdef MDE_CPU_IA32
87 #pragma pack(4)
88 #endif
89
90 #if defined(__DARWIN_64_BIT_INO_T)
91
92
93 typedef struct {
94 UINTN tv_sec; /* seconds */
95 UINTN tv_nsec; /* and nanoseconds */
96 } EFI_timespec;
97
98
99
100 typedef struct stat_fix { \
101 dev_t st_dev; /* [XSI] ID of device containing file */
102 mode_t st_mode; /* [XSI] Mode of file (see below) */
103 nlink_t st_nlink; /* [XSI] Number of hard links */
104 __darwin_ino64_t st_ino; /* [XSI] File serial number */
105 uid_t st_uid; /* [XSI] User ID of the file */
106 gid_t st_gid; /* [XSI] Group ID of the file */
107 dev_t st_rdev; /* [XSI] Device ID */
108
109 // clang for X64 ABI follows Windows and a long is 32-bits
110 // this breaks system inlcude files so that is why we need
111 // to redefine timespec as EFI_timespec
112 EFI_timespec st_atimespec;
113 EFI_timespec st_mtimespec;
114 EFI_timespec st_ctimespec;
115 EFI_timespec st_birthtimespec;
116
117 off_t st_size; /* [XSI] file size, in bytes */
118 blkcnt_t st_blocks; /* [XSI] blocks allocated for file */
119 blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */
120 __uint32_t st_flags; /* user defined flags for file */
121 __uint32_t st_gen; /* file generation number */
122 __int32_t st_lspare; /* RESERVED: DO NOT USE! */
123 __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
124 } STAT_FIX;
125
126 #else /* !__DARWIN_64_BIT_INO_T */
127
128 typedef struct stat_fix {
129 dev_t st_dev; /* [XSI] ID of device containing file */
130 ino_t st_ino; /* [XSI] File serial number */
131 mode_t st_mode; /* [XSI] Mode of file (see below) */
132 nlink_t st_nlink; /* [XSI] Number of hard links */
133 uid_t st_uid; /* [XSI] User ID of the file */
134 gid_t st_gid; /* [XSI] Group ID of the file */
135 dev_t st_rdev; /* [XSI] Device ID */
136 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
137 struct timespec st_atimespec; /* time of last access */
138 struct timespec st_mtimespec; /* time of last data modification */
139 struct timespec st_ctimespec; /* time of last status change */
140 #else
141 time_t st_atime; /* [XSI] Time of last access */
142 long st_atimensec; /* nsec of last access */
143 time_t st_mtime; /* [XSI] Last data modification time */
144 long st_mtimensec; /* last data modification nsec */
145 time_t st_ctime; /* [XSI] Time of last status change */
146 long st_ctimensec; /* nsec of last status change */
147 #endif
148 off_t st_size; /* [XSI] file size, in bytes */
149 blkcnt_t st_blocks; /* [XSI] blocks allocated for file */
150 blksize_t st_blksize; /* [XSI] optimal blocksize for I/O */
151 __uint32_t st_flags; /* user defined flags for file */
152 __uint32_t st_gen; /* file generation number */
153 __int32_t st_lspare; /* RESERVED: DO NOT USE! */
154 __int64_t st_qspare[2]; /* RESERVED: DO NOT USE! */
155 } STAT_FIX;
156
157 #endif
158
159 #ifdef MDE_CPU_IA32
160 #pragma pack(4)
161 #endif
162
163 #else
164
165 typedef struct stat STAT_FIX;
166
167 #endif
168
169 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
170 { \
171 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
172 }
173
174 typedef
175 VOID
176 (EFIAPI *UnixSleep) (
177 unsigned long Milliseconds
178 );
179
180 typedef
181 VOID
182 (EFIAPI *UnixExit) (
183 int status // exit code for all threads
184 );
185
186 typedef
187 VOID
188 (EFIAPI *UnixSetTimer) (
189 UINT64 PeriodMs,
190 VOID (EFIAPI *CallBack)(UINT64 DeltaMs)
191 );
192
193 typedef
194 VOID
195 (EFIAPI *UnixGetLocalTime) (
196 EFI_TIME *Time
197 );
198
199 typedef
200 struct tm *
201 (EFIAPI *UnixGmTime)(
202 const time_t *timep
203 );
204
205 typedef
206 long
207 (EFIAPI *UnixGetTimeZone)(
208 void
209 );
210
211 typedef
212 int
213 (EFIAPI *UnixGetDayLight)(
214 void
215 );
216
217 typedef
218 int
219 (EFIAPI *UnixPoll)(
220 struct pollfd *pfd,
221 unsigned int nfds,
222 int timeout
223 );
224
225 typedef
226 long
227 (EFIAPI *UnixRead) (
228 int fd,
229 void *buf,
230 int count
231 );
232
233 typedef
234 long
235 (EFIAPI *UnixWrite) (
236 int fd,
237 const void *buf,
238 int count
239 );
240
241 typedef
242 char *
243 (EFIAPI *UnixGetenv) (const char *var);
244
245 typedef
246 int
247 (EFIAPI *UnixOpen) (const char *name, int flags, int mode);
248
249 typedef
250 off_t
251 (EFIAPI *UnixSeek) (int fd, off_t off, int whence);
252
253 typedef
254 int
255 (EFIAPI *UnixFtruncate) (int fd, long int len);
256
257 typedef
258 int
259 (EFIAPI *UnixClose) (int fd);
260
261 typedef
262 int
263 (EFIAPI *UnixMkdir)(const char *pathname, mode_t mode);
264
265 typedef
266 int
267 (EFIAPI *UnixRmDir)(const char *pathname);
268
269 typedef
270 int
271 (EFIAPI *UnixUnLink)(const char *pathname);
272
273 typedef
274 int
275 (EFIAPI *UnixGetErrno)(VOID);
276
277 typedef
278 DIR *
279 (EFIAPI *UnixOpenDir)(const char *pathname);
280
281 typedef
282 void
283 (EFIAPI *UnixRewindDir)(DIR *dir);
284
285 typedef
286 struct dirent *
287 (EFIAPI *UnixReadDir)(DIR *dir);
288
289 typedef
290 int
291 (EFIAPI *UnixCloseDir)(DIR *dir);
292
293 typedef
294 int
295 (EFIAPI *UnixStat)(const char *path, STAT_FIX *buf);
296
297 typedef
298 int
299 (EFIAPI *UnixStatFs)(const char *path, struct statfs *buf);
300
301 typedef
302 int
303 (EFIAPI *UnixRename)(const char *oldpath, const char *newpath);
304
305 typedef
306 time_t
307 (EFIAPI *UnixMkTime)(struct tm *tm);
308
309 typedef
310 int
311 (EFIAPI *UnixFSync)(int fd);
312
313 typedef
314 int
315 (EFIAPI *UnixChmod)(const char *path, mode_t mode);
316
317 typedef
318 int
319 (EFIAPI *UnixUTime)(const char *filename, const struct utimbuf *buf);
320
321 struct _EFI_UNIX_UGA_IO_PROTOCOL;
322 typedef
323 EFI_STATUS
324 (EFIAPI *UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
325 CONST CHAR16 *Title);
326
327 typedef
328 int
329 (EFIAPI *UnixTcflush) (int fildes, int queue_selector);
330
331 typedef
332 void
333 (EFIAPI *UnixPerror) (__const char *__s);
334
335 typedef
336 int
337 #if __CYGWIN__
338 (EFIAPI *UnixIoCtl) (int fd, int __request, UINTN Arg);
339 #else
340 (EFIAPI *UnixIoCtl) (int fd, unsigned long int __request, void *Arg);
341 #endif
342
343 typedef
344 int
345 (EFIAPI *UnixFcntl) (int __fd, int __cmd, void *Arg);
346
347 typedef
348 int
349 (EFIAPI *UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
350
351 typedef
352 int
353 (EFIAPI *UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
354
355 typedef
356 int
357 (EFIAPI *UnixTcgetattr) (int __fd, struct termios *__termios_p);
358
359 typedef
360 int
361 (EFIAPI *UnixTcsetattr) (int __fd, int __optional_actions,
362 __const struct termios *__termios_p);
363
364
365 //
366 // Worker functions to enable source level debug in the emulator
367 //
368
369 typedef
370 RETURN_STATUS
371 (EFIAPI *UnixPeCoffGetEntryPoint) (
372 IN VOID *Pe32Data,
373 IN OUT VOID **EntryPoint
374 );
375
376 typedef
377 VOID
378 (EFIAPI *UnixPeCoffRelocateImageExtraAction) (
379 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
380 );
381
382 typedef
383 VOID
384 (EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) (
385 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
386 );
387
388 typedef
389 int
390 (EFIAPI *UnixGetIfAddrs) (
391 struct ifaddrs **ifap
392 );
393
394 typedef
395 void
396 (EFIAPI *UnixFreeIfAddrs) (
397 struct ifaddrs *ifap
398 );
399
400 typedef
401 int
402 (EFIAPI *UnixSocket) (
403 int domain,
404 int type,
405 int protocol
406 );
407
408 typedef
409 void
410 (EFIAPI *UnixDisableInterruptEmulation) (void);
411
412 typedef
413 void
414 (EFIAPI *UnixEnableInterruptEmulation) (void);
415
416
417
418
419 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
420
421 typedef struct _EFI_UNIX_THUNK_PROTOCOL {
422 UINT64 Signature;
423
424 UnixSleep Sleep;
425 UnixExit Exit;
426 UnixSetTimer SetTimer;
427 UnixGetLocalTime GetLocalTime;
428 UnixGmTime GmTime;
429 UnixGetTimeZone GetTimeZone;
430 UnixGetDayLight GetDayLight;
431 UnixPoll Poll;
432 UnixRead Read;
433 UnixWrite Write;
434 UnixGetenv Getenv;
435 UnixOpen Open;
436 UnixSeek Lseek;
437 UnixFtruncate FTruncate;
438 UnixClose Close;
439 UnixMkdir MkDir;
440 UnixRmDir RmDir;
441 UnixUnLink UnLink;
442 UnixGetErrno GetErrno;
443 UnixOpenDir OpenDir;
444 UnixRewindDir RewindDir;
445 UnixReadDir ReadDir;
446 UnixCloseDir CloseDir;
447 UnixStat Stat;
448 UnixStatFs StatFs;
449 UnixRename Rename;
450 UnixMkTime MkTime;
451 UnixFSync FSync;
452 UnixChmod Chmod;
453 UnixUTime UTime;
454 UnixTcflush Tcflush;
455 UnixUgaCreate UgaCreate;
456 UnixPerror Perror;
457 UnixIoCtl IoCtl;
458 UnixFcntl Fcntl;
459 UnixCfsetispeed Cfsetispeed;
460 UnixCfsetospeed Cfsetospeed;
461 UnixTcgetattr Tcgetattr;
462 UnixTcsetattr Tcsetattr;
463 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint;
464 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction;
465 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction;
466 UnixEnableInterruptEmulation EnableInterrupt;
467 UnixDisableInterruptEmulation DisableInterrupt;
468
469 UnixGetIfAddrs GetIfAddrs;
470 UnixFreeIfAddrs FreeIfAddrs;
471 UnixSocket Socket;
472 } EFI_UNIX_THUNK_PROTOCOL;
473
474 extern EFI_GUID gEfiUnixThunkProtocolGuid;
475
476 #endif