3 Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2008 - 2009, 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>
55 #include <sys/param.h>
56 #include <sys/mount.h>
66 #include <Library/PeCoffLib.h>
71 // EFI packing is not compatible witht he default OS packing for struct stat.
72 // st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler
73 // flags used to produce compatible EFI images, break struct stat
79 #if __DARWIN_64_BIT_INO_T
81 typedef struct stat_fix
{ \
82 dev_t st_dev
; /* [XSI] ID of device containing file */
83 mode_t st_mode
; /* [XSI] Mode of file (see below) */
84 nlink_t st_nlink
; /* [XSI] Number of hard links */
85 __darwin_ino64_t st_ino
; /* [XSI] File serial number */
86 uid_t st_uid
; /* [XSI] User ID of the file */
87 gid_t st_gid
; /* [XSI] Group ID of the file */
88 dev_t st_rdev
; /* [XSI] Device ID */
89 __DARWIN_STRUCT_STAT64_TIMES
90 off_t st_size
; /* [XSI] file size, in bytes */
91 blkcnt_t st_blocks
; /* [XSI] blocks allocated for file */
92 blksize_t st_blksize
; /* [XSI] optimal blocksize for I/O */
93 __uint32_t st_flags
; /* user defined flags for file */
94 __uint32_t st_gen
; /* file generation number */
95 __int32_t st_lspare
; /* RESERVED: DO NOT USE! */
96 __int64_t st_qspare
[2]; /* RESERVED: DO NOT USE! */
99 #else /* !__DARWIN_64_BIT_INO_T */
101 typedef struct stat_fix
{
102 dev_t st_dev
; /* [XSI] ID of device containing file */
103 ino_t st_ino
; /* [XSI] File serial number */
104 mode_t st_mode
; /* [XSI] Mode of file (see below) */
105 nlink_t st_nlink
; /* [XSI] Number of hard links */
106 uid_t st_uid
; /* [XSI] User ID of the file */
107 gid_t st_gid
; /* [XSI] Group ID of the file */
108 dev_t st_rdev
; /* [XSI] Device ID */
109 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
110 struct timespec st_atimespec
; /* time of last access */
111 struct timespec st_mtimespec
; /* time of last data modification */
112 struct timespec st_ctimespec
; /* time of last status change */
114 time_t st_atime
; /* [XSI] Time of last access */
115 long st_atimensec
; /* nsec of last access */
116 time_t st_mtime
; /* [XSI] Last data modification time */
117 long st_mtimensec
; /* last data modification nsec */
118 time_t st_ctime
; /* [XSI] Time of last status change */
119 long st_ctimensec
; /* nsec of last status change */
121 off_t st_size
; /* [XSI] file size, in bytes */
122 blkcnt_t st_blocks
; /* [XSI] blocks allocated for file */
123 blksize_t st_blksize
; /* [XSI] optimal blocksize for I/O */
124 __uint32_t st_flags
; /* user defined flags for file */
125 __uint32_t st_gen
; /* file generation number */
126 __int32_t st_lspare
; /* RESERVED: DO NOT USE! */
127 __int64_t st_qspare
[2]; /* RESERVED: DO NOT USE! */
138 typedef struct stat STAT_FIX
;
142 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
144 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
150 unsigned long Milliseconds
156 int status
// exit code for all threads
163 VOID (*CallBack
)(UINT64 DeltaMs
)
168 (*UnixGetLocalTime
) (
216 (*UnixGetenv
) (const char *var
);
220 (*UnixOpen
) (const char *name
, int flags
, int mode
);
224 (*UnixSeek
) (int fd
, off_t off
, int whence
);
228 (*UnixFtruncate
) (int fd
, long int len
);
232 (*UnixClose
) (int fd
);
236 (*UnixMkdir
)(const char *pathname
, mode_t mode
);
240 (*UnixRmDir
)(const char *pathname
);
244 (*UnixUnLink
)(const char *pathname
);
248 (*UnixGetErrno
)(VOID
);
252 (*UnixOpenDir
)(const char *pathname
);
256 (*UnixRewindDir
)(DIR *dir
);
260 (*UnixReadDir
)(DIR *dir
);
264 (*UnixCloseDir
)(DIR *dir
);
268 (*UnixStat
)(const char *path
, STAT_FIX
*buf
);
272 (*UnixStatFs
)(const char *path
, struct statfs
*buf
);
276 (*UnixRename
)(const char *oldpath
, const char *newpath
);
280 (*UnixMkTime
)(struct tm
*tm
);
284 (*UnixFSync
)(int fd
);
288 (*UnixChmod
)(const char *path
, mode_t mode
);
292 (*UnixUTime
)(const char *filename
, const struct utimbuf
*buf
);
294 struct _EFI_UNIX_UGA_IO_PROTOCOL
;
297 (*UnixUgaCreate
)(struct _EFI_UNIX_UGA_IO_PROTOCOL
**UgaIo
,
298 CONST CHAR16
*Title
);
302 (*UnixTcflush
) (int fildes
, int queue_selector
);
306 (*UnixPerror
) (__const
char *__s
);
311 (*UnixIoCtl
) (int fd
, int __request
, UINTN Arg
);
313 (*UnixIoCtl
) (int fd
, unsigned long int __request
, void *Arg
);
318 (*UnixFcntl
) (int __fd
, int __cmd
, void *Arg
);
322 (*UnixCfsetispeed
) (struct termios
*__termios_p
, speed_t __speed
);
326 (*UnixCfsetospeed
) (struct termios
*__termios_p
, speed_t __speed
);
330 (*UnixTcgetattr
) (int __fd
, struct termios
*__termios_p
);
334 (*UnixTcsetattr
) (int __fd
, int __optional_actions
,
335 __const
struct termios
*__termios_p
);
339 // Worker functions to enable source level debug in the emulator
344 (EFIAPI
*UnixPeCoffGetEntryPoint
) (
346 IN OUT VOID
**EntryPoint
351 (EFIAPI
*UnixPeCoffRelocateImageExtraAction
) (
352 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
357 (EFIAPI
*UnixPeCoffLoaderUnloadImageExtraAction
) (
358 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
363 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
365 typedef struct _EFI_UNIX_THUNK_PROTOCOL
{
370 UnixSetTimer SetTimer
;
371 UnixGetLocalTime GetLocalTime
;
373 UnixGetTimeZone GetTimeZone
;
374 UnixGetDayLight GetDayLight
;
381 UnixFtruncate FTruncate
;
386 UnixGetErrno GetErrno
;
388 UnixRewindDir RewindDir
;
390 UnixCloseDir CloseDir
;
399 UnixUgaCreate UgaCreate
;
403 UnixCfsetispeed Cfsetispeed
;
404 UnixCfsetospeed Cfsetospeed
;
405 UnixTcgetattr Tcgetattr
;
406 UnixTcsetattr Tcsetattr
;
407 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint
;
408 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction
;
409 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction
;
412 } EFI_UNIX_THUNK_PROTOCOL
;
414 extern EFI_GUID gEfiUnixThunkProtocolGuid
;