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
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.
19 This protocol allows an EFI driver in the Unix emulation environment
22 NEVER make an Unix call directly, always make the call via this protocol.
24 There are no This pointers on the protocol member functions as they map
25 exactly into Unix system calls.
29 #ifndef _UNIX_THUNK_H_
30 #define _UNIX_THUNK_H_
32 #include <sys/termios.h>
37 #include <sys/dirent.h>
44 #include <sys/types.h>
52 #include <sys/ioctl.h>
54 #include <sys/socket.h>
56 #include <netinet/in.h>
58 #include <net/if_dl.h>
63 #include <sys/param.h>
64 #include <sys/mount.h>
67 #define _Bool char // for clang debug
77 #include <Library/PeCoffLib.h>
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
90 #if defined(__DARWIN_64_BIT_INO_T)
94 UINTN tv_sec
; /* seconds */
95 UINTN tv_nsec
; /* and nanoseconds */
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 */
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
;
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! */
126 #else /* !__DARWIN_64_BIT_INO_T */
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 */
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 */
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! */
165 typedef struct stat STAT_FIX
;
169 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
171 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
176 (EFIAPI
*UnixSleep
) (
177 unsigned long Milliseconds
183 int status
// exit code for all threads
188 (EFIAPI
*UnixSetTimer
) (
190 VOID (EFIAPI
*CallBack
)(UINT64 DeltaMs
)
195 (EFIAPI
*UnixGetLocalTime
) (
201 (EFIAPI
*UnixGmTime
)(
207 (EFIAPI
*UnixGetTimeZone
)(
213 (EFIAPI
*UnixGetDayLight
)(
235 (EFIAPI
*UnixWrite
) (
243 (EFIAPI
*UnixGetenv
) (const char *var
);
247 (EFIAPI
*UnixOpen
) (const char *name
, int flags
, int mode
);
251 (EFIAPI
*UnixSeek
) (int fd
, off_t off
, int whence
);
255 (EFIAPI
*UnixFtruncate
) (int fd
, long int len
);
259 (EFIAPI
*UnixClose
) (int fd
);
263 (EFIAPI
*UnixMkdir
)(const char *pathname
, mode_t mode
);
267 (EFIAPI
*UnixRmDir
)(const char *pathname
);
271 (EFIAPI
*UnixUnLink
)(const char *pathname
);
275 (EFIAPI
*UnixGetErrno
)(VOID
);
279 (EFIAPI
*UnixOpenDir
)(const char *pathname
);
283 (EFIAPI
*UnixRewindDir
)(DIR *dir
);
287 (EFIAPI
*UnixReadDir
)(DIR *dir
);
291 (EFIAPI
*UnixCloseDir
)(DIR *dir
);
295 (EFIAPI
*UnixStat
)(const char *path
, STAT_FIX
*buf
);
299 (EFIAPI
*UnixStatFs
)(const char *path
, struct statfs
*buf
);
303 (EFIAPI
*UnixRename
)(const char *oldpath
, const char *newpath
);
307 (EFIAPI
*UnixMkTime
)(struct tm
*tm
);
311 (EFIAPI
*UnixFSync
)(int fd
);
315 (EFIAPI
*UnixChmod
)(const char *path
, mode_t mode
);
319 (EFIAPI
*UnixUTime
)(const char *filename
, const struct utimbuf
*buf
);
321 struct _EFI_UNIX_UGA_IO_PROTOCOL
;
324 (EFIAPI
*UnixUgaCreate
)(struct _EFI_UNIX_UGA_IO_PROTOCOL
**UgaIo
,
325 CONST CHAR16
*Title
);
329 (EFIAPI
*UnixTcflush
) (int fildes
, int queue_selector
);
333 (EFIAPI
*UnixPerror
) (__const
char *__s
);
338 (EFIAPI
*UnixIoCtl
) (int fd
, int __request
, UINTN Arg
);
340 (EFIAPI
*UnixIoCtl
) (int fd
, unsigned long int __request
, void *Arg
);
345 (EFIAPI
*UnixFcntl
) (int __fd
, int __cmd
, void *Arg
);
349 (EFIAPI
*UnixCfsetispeed
) (struct termios
*__termios_p
, speed_t __speed
);
353 (EFIAPI
*UnixCfsetospeed
) (struct termios
*__termios_p
, speed_t __speed
);
357 (EFIAPI
*UnixTcgetattr
) (int __fd
, struct termios
*__termios_p
);
361 (EFIAPI
*UnixTcsetattr
) (int __fd
, int __optional_actions
,
362 __const
struct termios
*__termios_p
);
366 // Worker functions to enable source level debug in the emulator
371 (EFIAPI
*UnixPeCoffGetEntryPoint
) (
373 IN OUT VOID
**EntryPoint
378 (EFIAPI
*UnixPeCoffRelocateImageExtraAction
) (
379 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
384 (EFIAPI
*UnixPeCoffLoaderUnloadImageExtraAction
) (
385 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
390 (EFIAPI
*UnixGetIfAddrs
) (
391 struct ifaddrs
**ifap
396 (EFIAPI
*UnixFreeIfAddrs
) (
402 (EFIAPI
*UnixSocket
) (
410 (EFIAPI
*UnixDisableInterruptEmulation
) (void);
414 (EFIAPI
*UnixEnableInterruptEmulation
) (void);
419 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
421 typedef struct _EFI_UNIX_THUNK_PROTOCOL
{
426 UnixSetTimer SetTimer
;
427 UnixGetLocalTime GetLocalTime
;
429 UnixGetTimeZone GetTimeZone
;
430 UnixGetDayLight GetDayLight
;
437 UnixFtruncate FTruncate
;
442 UnixGetErrno GetErrno
;
444 UnixRewindDir RewindDir
;
446 UnixCloseDir CloseDir
;
455 UnixUgaCreate UgaCreate
;
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
;
469 UnixGetIfAddrs GetIfAddrs
;
470 UnixFreeIfAddrs FreeIfAddrs
;
472 } EFI_UNIX_THUNK_PROTOCOL
;
474 extern EFI_GUID gEfiUnixThunkProtocolGuid
;