]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Include/Protocol/UnixThunk.h
Adding Simple Pointer, GOP, SimpleTextInEx, and Networking protocols to the emulator...
[mirror_edk2.git] / UnixPkg / Include / Protocol / UnixThunk.h
CommitLineData
804405e7 1/*++
2
f9b8ab56 3Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
2ff79f2e 4Portions copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
124f761f 5This program and the accompanying materials
6are licensed and made available under the terms and conditions of the BSD License
7which accompanies this distribution. The full text of the license may be found at
8http://opensource.org/licenses/bsd-license.php
9
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
804405e7 12
13Module Name:
14
15 UnixThunk.h
16
17Abstract:
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>
ccd55824 35
36#if __CYGWIN__
37#include <sys/dirent.h>
38#else
804405e7 39#include <sys/dir.h>
ccd55824 40#endif
41
804405e7 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>
804405e7 52#include <sys/ioctl.h>
ccd55824 53
2ff79f2e 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
ccd55824 62#ifdef __APPLE__
63#include <sys/param.h>
64#include <sys/mount.h>
65#define _XOPEN_SOURCE
2ff79f2e 66#ifndef _Bool
67 #define _Bool char // for clang debug
68#endif
ccd55824 69#else
70#include <termio.h>
804405e7 71#include <sys/vfs.h>
124f761f 72#endif
ccd55824 73
804405e7 74#include <utime.h>
75
ccd55824 76#include <Base.h>
77#include <Library/PeCoffLib.h>
78
79
7ee3b613
A
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//
b9c8e50e 86#ifdef MDE_CPU_IA32
7ee3b613 87#pragma pack(4)
b9c8e50e 88#endif
7ee3b613 89
2ff79f2e 90#if defined(__DARWIN_64_BIT_INO_T)
91
92
93typedef struct {
94 UINTN tv_sec; /* seconds */
95 UINTN tv_nsec; /* and nanoseconds */
96} EFI_timespec;
97
98
7ee3b613
A
99
100typedef struct stat_fix { \
124f761f 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 */
2ff79f2e 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
124f761f 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! */
7ee3b613
A
124} STAT_FIX;
125
126#else /* !__DARWIN_64_BIT_INO_T */
127
128typedef 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
7ee3b613 157#endif
b9c8e50e 158
159#ifdef MDE_CPU_IA32
160#pragma pack(4)
161#endif
7ee3b613 162
124f761f 163#else
7ee3b613
A
164
165 typedef struct stat STAT_FIX;
166
167#endif
168
804405e7 169#define EFI_UNIX_THUNK_PROTOCOL_GUID \
170 { \
171 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
172 }
173
174typedef
175VOID
124f761f 176(EFIAPI *UnixSleep) (
804405e7 177 unsigned long Milliseconds
178 );
179
180typedef
181VOID
124f761f 182(EFIAPI *UnixExit) (
804405e7 183 int status // exit code for all threads
184 );
185
186typedef
187VOID
124f761f 188(EFIAPI *UnixSetTimer) (
189 UINT64 PeriodMs,
190 VOID (EFIAPI *CallBack)(UINT64 DeltaMs)
b9c8e50e 191 );
192
804405e7 193typedef
194VOID
124f761f 195(EFIAPI *UnixGetLocalTime) (
b9c8e50e 196 EFI_TIME *Time
197 );
198
804405e7 199typedef
200struct tm *
124f761f 201(EFIAPI *UnixGmTime)(
b9c8e50e 202 const time_t *timep
203 );
204
804405e7 205typedef
206long
124f761f 207(EFIAPI *UnixGetTimeZone)(
b9c8e50e 208 void
209 );
210
804405e7 211typedef
212int
124f761f 213(EFIAPI *UnixGetDayLight)(
b9c8e50e 214 void
215 );
216
804405e7 217typedef
218int
124f761f 219(EFIAPI *UnixPoll)(
220 struct pollfd *pfd,
221 unsigned int nfds,
b9c8e50e 222 int timeout
223 );
224
804405e7 225typedef
b9c8e50e 226long
124f761f 227(EFIAPI *UnixRead) (
228 int fd,
229 void *buf,
b9c8e50e 230 int count
231 );
232
804405e7 233typedef
b9c8e50e 234long
124f761f 235(EFIAPI *UnixWrite) (
236 int fd,
237 const void *buf,
b9c8e50e 238 int count
239 );
240
804405e7 241typedef
242char *
124f761f 243(EFIAPI *UnixGetenv) (const char *var);
b9c8e50e 244
804405e7 245typedef
246int
124f761f 247(EFIAPI *UnixOpen) (const char *name, int flags, int mode);
b9c8e50e 248
804405e7 249typedef
7ee3b613 250off_t
124f761f 251(EFIAPI *UnixSeek) (int fd, off_t off, int whence);
b9c8e50e 252
804405e7 253typedef
254int
124f761f 255(EFIAPI *UnixFtruncate) (int fd, long int len);
b9c8e50e 256
804405e7 257typedef
258int
124f761f 259(EFIAPI *UnixClose) (int fd);
804405e7 260
261typedef
262int
124f761f 263(EFIAPI *UnixMkdir)(const char *pathname, mode_t mode);
b9c8e50e 264
804405e7 265typedef
266int
124f761f 267(EFIAPI *UnixRmDir)(const char *pathname);
b9c8e50e 268
804405e7 269typedef
270int
124f761f 271(EFIAPI *UnixUnLink)(const char *pathname);
b9c8e50e 272
804405e7 273typedef
274int
124f761f 275(EFIAPI *UnixGetErrno)(VOID);
b9c8e50e 276
804405e7 277typedef
278DIR *
124f761f 279(EFIAPI *UnixOpenDir)(const char *pathname);
b9c8e50e 280
804405e7 281typedef
282void
124f761f 283(EFIAPI *UnixRewindDir)(DIR *dir);
b9c8e50e 284
804405e7 285typedef
286struct dirent *
124f761f 287(EFIAPI *UnixReadDir)(DIR *dir);
b9c8e50e 288
804405e7 289typedef
290int
124f761f 291(EFIAPI *UnixCloseDir)(DIR *dir);
b9c8e50e 292
804405e7 293typedef
294int
124f761f 295(EFIAPI *UnixStat)(const char *path, STAT_FIX *buf);
b9c8e50e 296
804405e7 297typedef
298int
124f761f 299(EFIAPI *UnixStatFs)(const char *path, struct statfs *buf);
b9c8e50e 300
804405e7 301typedef
302int
124f761f 303(EFIAPI *UnixRename)(const char *oldpath, const char *newpath);
b9c8e50e 304
804405e7 305typedef
306time_t
124f761f 307(EFIAPI *UnixMkTime)(struct tm *tm);
b9c8e50e 308
804405e7 309typedef
310int
124f761f 311(EFIAPI *UnixFSync)(int fd);
b9c8e50e 312
804405e7 313typedef
314int
124f761f 315(EFIAPI *UnixChmod)(const char *path, mode_t mode);
b9c8e50e 316
804405e7 317typedef
318int
124f761f 319(EFIAPI *UnixUTime)(const char *filename, const struct utimbuf *buf);
804405e7 320
321struct _EFI_UNIX_UGA_IO_PROTOCOL;
322typedef
323EFI_STATUS
124f761f 324(EFIAPI *UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
804405e7 325 CONST CHAR16 *Title);
326
327typedef
328int
124f761f 329(EFIAPI *UnixTcflush) (int fildes, int queue_selector);
804405e7 330
331typedef
332void
124f761f 333(EFIAPI *UnixPerror) (__const char *__s);
804405e7 334
124f761f 335typedef
336int
ccd55824 337#if __CYGWIN__
124f761f 338(EFIAPI *UnixIoCtl) (int fd, int __request, UINTN Arg);
ccd55824 339#else
124f761f 340(EFIAPI *UnixIoCtl) (int fd, unsigned long int __request, void *Arg);
ccd55824 341#endif
804405e7 342
124f761f 343typedef
344int
345(EFIAPI *UnixFcntl) (int __fd, int __cmd, void *Arg);
804405e7 346
347typedef
124f761f 348int
349(EFIAPI *UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
804405e7 350
124f761f 351typedef
352int
353(EFIAPI *UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
804405e7 354
355typedef
124f761f 356int
357(EFIAPI *UnixTcgetattr) (int __fd, struct termios *__termios_p);
804405e7 358
124f761f 359typedef
360int
361(EFIAPI *UnixTcsetattr) (int __fd, int __optional_actions,
804405e7 362 __const struct termios *__termios_p);
363
398b646f 364
804405e7 365//
b9c8e50e 366// Worker functions to enable source level debug in the emulator
804405e7 367//
ccd55824 368
124f761f 369typedef
ccd55824 370RETURN_STATUS
371(EFIAPI *UnixPeCoffGetEntryPoint) (
372 IN VOID *Pe32Data,
373 IN OUT VOID **EntryPoint
374 );
375
124f761f 376typedef
ccd55824 377VOID
378(EFIAPI *UnixPeCoffRelocateImageExtraAction) (
379 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
380 );
381
124f761f 382typedef
ccd55824 383VOID
384(EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) (
385 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
386 );
387
2ff79f2e 388typedef
389int
390(EFIAPI *UnixGetIfAddrs) (
391 struct ifaddrs **ifap
392 );
393
394typedef
395void
396(EFIAPI *UnixFreeIfAddrs) (
397 struct ifaddrs *ifap
398 );
399
400typedef
401int
402(EFIAPI *UnixSocket) (
403 int domain,
404 int type,
405 int protocol
406 );
407
408typedef
409void
410(EFIAPI *UnixDisableInterruptEmulation) (void);
411
412typedef
413void
414(EFIAPI *UnixEnableInterruptEmulation) (void);
415
416
ccd55824 417
804405e7 418
208301e9 419#define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
804405e7 420
421typedef 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;
69cf40e0 432 UnixRead Read;
433 UnixWrite Write;
434 UnixGetenv Getenv;
435 UnixOpen Open;
436 UnixSeek Lseek;
437 UnixFtruncate FTruncate;
438 UnixClose Close;
804405e7 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;
ccd55824 463 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint;
464 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction;
465 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction;
2ff79f2e 466 UnixEnableInterruptEmulation EnableInterrupt;
467 UnixDisableInterruptEmulation DisableInterrupt;
124f761f 468
2ff79f2e 469 UnixGetIfAddrs GetIfAddrs;
470 UnixFreeIfAddrs FreeIfAddrs;
471 UnixSocket Socket;
804405e7 472} EFI_UNIX_THUNK_PROTOCOL;
473
474extern EFI_GUID gEfiUnixThunkProtocolGuid;
475
476#endif