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>
68 #include <Library/PeCoffLib.h>
73 // EFI packing is not compatible witht he default OS packing for struct stat.
74 // st_size is 64-bit but starts on a 32-bit offset in the structure. The compiler
75 // flags used to produce compatible EFI images, break struct stat
81 #if __DARWIN_64_BIT_INO_T
83 typedef struct stat_fix
{ \
84 dev_t st_dev
; /* [XSI] ID of device containing file */
85 mode_t st_mode
; /* [XSI] Mode of file (see below) */
86 nlink_t st_nlink
; /* [XSI] Number of hard links */
87 __darwin_ino64_t st_ino
; /* [XSI] File serial number */
88 uid_t st_uid
; /* [XSI] User ID of the file */
89 gid_t st_gid
; /* [XSI] Group ID of the file */
90 dev_t st_rdev
; /* [XSI] Device ID */
91 __DARWIN_STRUCT_STAT64_TIMES
92 off_t st_size
; /* [XSI] file size, in bytes */
93 blkcnt_t st_blocks
; /* [XSI] blocks allocated for file */
94 blksize_t st_blksize
; /* [XSI] optimal blocksize for I/O */
95 __uint32_t st_flags
; /* user defined flags for file */
96 __uint32_t st_gen
; /* file generation number */
97 __int32_t st_lspare
; /* RESERVED: DO NOT USE! */
98 __int64_t st_qspare
[2]; /* RESERVED: DO NOT USE! */
101 #else /* !__DARWIN_64_BIT_INO_T */
103 typedef struct stat_fix
{
104 dev_t st_dev
; /* [XSI] ID of device containing file */
105 ino_t st_ino
; /* [XSI] File serial number */
106 mode_t st_mode
; /* [XSI] Mode of file (see below) */
107 nlink_t st_nlink
; /* [XSI] Number of hard links */
108 uid_t st_uid
; /* [XSI] User ID of the file */
109 gid_t st_gid
; /* [XSI] Group ID of the file */
110 dev_t st_rdev
; /* [XSI] Device ID */
111 #if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
112 struct timespec st_atimespec
; /* time of last access */
113 struct timespec st_mtimespec
; /* time of last data modification */
114 struct timespec st_ctimespec
; /* time of last status change */
116 time_t st_atime
; /* [XSI] Time of last access */
117 long st_atimensec
; /* nsec of last access */
118 time_t st_mtime
; /* [XSI] Last data modification time */
119 long st_mtimensec
; /* last data modification nsec */
120 time_t st_ctime
; /* [XSI] Time of last status change */
121 long st_ctimensec
; /* nsec of last status change */
123 off_t st_size
; /* [XSI] file size, in bytes */
124 blkcnt_t st_blocks
; /* [XSI] blocks allocated for file */
125 blksize_t st_blksize
; /* [XSI] optimal blocksize for I/O */
126 __uint32_t st_flags
; /* user defined flags for file */
127 __uint32_t st_gen
; /* file generation number */
128 __int32_t st_lspare
; /* RESERVED: DO NOT USE! */
129 __int64_t st_qspare
[2]; /* RESERVED: DO NOT USE! */
140 typedef struct stat STAT_FIX
;
144 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
146 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
152 unsigned long Milliseconds
158 int status
// exit code for all threads
165 VOID (*CallBack
)(UINT64 DeltaMs
)
170 (*UnixGetLocalTime
) (
218 (*UnixGetenv
) (const char *var
);
222 (*UnixOpen
) (const char *name
, int flags
, int mode
);
226 (*UnixSeek
) (int fd
, off_t off
, int whence
);
230 (*UnixFtruncate
) (int fd
, long int len
);
234 (*UnixClose
) (int fd
);
238 (*UnixMkdir
)(const char *pathname
, mode_t mode
);
242 (*UnixRmDir
)(const char *pathname
);
246 (*UnixUnLink
)(const char *pathname
);
250 (*UnixGetErrno
)(VOID
);
254 (*UnixOpenDir
)(const char *pathname
);
258 (*UnixRewindDir
)(DIR *dir
);
262 (*UnixReadDir
)(DIR *dir
);
266 (*UnixCloseDir
)(DIR *dir
);
270 (*UnixStat
)(const char *path
, STAT_FIX
*buf
);
274 (*UnixStatFs
)(const char *path
, struct statfs
*buf
);
278 (*UnixRename
)(const char *oldpath
, const char *newpath
);
282 (*UnixMkTime
)(struct tm
*tm
);
286 (*UnixFSync
)(int fd
);
290 (*UnixChmod
)(const char *path
, mode_t mode
);
294 (*UnixUTime
)(const char *filename
, const struct utimbuf
*buf
);
296 struct _EFI_UNIX_UGA_IO_PROTOCOL
;
299 (*UnixUgaCreate
)(struct _EFI_UNIX_UGA_IO_PROTOCOL
**UgaIo
,
300 CONST CHAR16
*Title
);
304 (*UnixTcflush
) (int fildes
, int queue_selector
);
308 (*UnixPerror
) (__const
char *__s
);
313 (*UnixIoCtl
) (int fd
, int __request
, ...);
315 (*UnixIoCtl
) (int fd
, unsigned long int __request
, ...);
320 (*UnixFcntl
) (int __fd
, int __cmd
, ...);
324 (*UnixCfsetispeed
) (struct termios
*__termios_p
, speed_t __speed
);
328 (*UnixCfsetospeed
) (struct termios
*__termios_p
, speed_t __speed
);
332 (*UnixTcgetattr
) (int __fd
, struct termios
*__termios_p
);
336 (*UnixTcsetattr
) (int __fd
, int __optional_actions
,
337 __const
struct termios
*__termios_p
);
341 // Worker functions to enable source level debug in the emulator
346 (EFIAPI
*UnixPeCoffGetEntryPoint
) (
348 IN OUT VOID
**EntryPoint
353 (EFIAPI
*UnixPeCoffRelocateImageExtraAction
) (
354 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
359 (EFIAPI
*UnixPeCoffLoaderUnloadImageExtraAction
) (
360 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
365 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
367 typedef struct _EFI_UNIX_THUNK_PROTOCOL
{
372 UnixSetTimer SetTimer
;
373 UnixGetLocalTime GetLocalTime
;
375 UnixGetTimeZone GetTimeZone
;
376 UnixGetDayLight GetDayLight
;
383 UnixFtruncate FTruncate
;
388 UnixGetErrno GetErrno
;
390 UnixRewindDir RewindDir
;
392 UnixCloseDir CloseDir
;
401 UnixUgaCreate UgaCreate
;
405 UnixCfsetispeed Cfsetispeed
;
406 UnixCfsetospeed Cfsetospeed
;
407 UnixTcgetattr Tcgetattr
;
408 UnixTcsetattr Tcsetattr
;
409 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint
;
410 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction
;
411 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction
;
414 } EFI_UNIX_THUNK_PROTOCOL
;
416 extern EFI_GUID gEfiUnixThunkProtocolGuid
;