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
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! */
135 typedef struct stat STAT_FIX
;
139 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
141 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
147 unsigned long Milliseconds
153 int status
// exit code for all threads
158 (*UnixSetTimer
) (UINT64 PeriodMs
, VOID (*CallBack
)(UINT64 DeltaMs
));
161 (*UnixGetLocalTime
) (EFI_TIME
*Time
);
164 (*UnixGmTime
)(const time_t *timep
);
167 (*UnixGetTimeZone
)(void);
170 (*UnixGetDayLight
)(void);
173 (*UnixPoll
)(struct pollfd
*pfd
, int nfds
, int timeout
);
176 (*UnixRead
) (int fd
, void *buf
, int count
);
179 (*UnixWrite
) (int fd
, const void *buf
, int count
);
182 (*UnixGetenv
) (const char *var
);
185 (*UnixOpen
) (const char *name
, int flags
, int mode
);
188 (*UnixSeek
) (int fd
, off_t off
, int whence
);
191 (*UnixFtruncate
) (int fd
, long int len
);
194 (*UnixClose
) (int fd
);
198 (*UnixMkdir
)(const char *pathname
, mode_t mode
);
201 (*UnixRmDir
)(const char *pathname
);
204 (*UnixUnLink
)(const char *pathname
);
207 (*UnixGetErrno
)(VOID
);
210 (*UnixOpenDir
)(const char *pathname
);
213 (*UnixRewindDir
)(DIR *dir
);
216 (*UnixReadDir
)(DIR *dir
);
219 (*UnixCloseDir
)(DIR *dir
);
222 (*UnixStat
)(const char *path
, STAT_FIX
*buf
);
225 (*UnixStatFs
)(const char *path
, struct statfs
*buf
);
228 (*UnixRename
)(const char *oldpath
, const char *newpath
);
231 (*UnixMkTime
)(struct tm
*tm
);
234 (*UnixFSync
)(int fd
);
237 (*UnixChmod
)(const char *path
, mode_t mode
);
240 (*UnixUTime
)(const char *filename
, const struct utimbuf
*buf
);
242 struct _EFI_UNIX_UGA_IO_PROTOCOL
;
245 (*UnixUgaCreate
)(struct _EFI_UNIX_UGA_IO_PROTOCOL
**UgaIo
,
246 CONST CHAR16
*Title
);
250 (*UnixTcflush
) (int fildes
, int queue_selector
);
254 (*UnixPerror
) (__const
char *__s
);
259 (*UnixIoCtl
) (int fd
, int __request
, ...);
261 (*UnixIoCtl
) (int fd
, unsigned long int __request
, ...);
266 (*UnixFcntl
) (int __fd
, int __cmd
, ...);
270 (*UnixCfsetispeed
) (struct termios
*__termios_p
, speed_t __speed
);
274 (*UnixCfsetospeed
) (struct termios
*__termios_p
, speed_t __speed
);
278 (*UnixTcgetattr
) (int __fd
, struct termios
*__termios_p
);
282 (*UnixTcsetattr
) (int __fd
, int __optional_actions
,
283 __const
struct termios
*__termios_p
);
287 (*UnixDlopen
) (const char *FileName
, int Flag
);
291 (*UnixDlerror
) (VOID
);
295 (*UnixDlsym
) (VOID
* Handle
, const char* Symbol
);
299 // Work functions to enable source level debug in the emulator
304 (EFIAPI
*UnixPeCoffGetEntryPoint
) (
306 IN OUT VOID
**EntryPoint
311 (EFIAPI
*UnixPeCoffRelocateImageExtraAction
) (
312 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
317 (EFIAPI
*UnixPeCoffLoaderUnloadImageExtraAction
) (
318 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT
*ImageContext
323 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
325 typedef struct _EFI_UNIX_THUNK_PROTOCOL
{
330 UnixSetTimer SetTimer
;
331 UnixGetLocalTime GetLocalTime
;
333 UnixGetTimeZone GetTimeZone
;
334 UnixGetDayLight GetDayLight
;
341 UnixFtruncate FTruncate
;
346 UnixGetErrno GetErrno
;
348 UnixRewindDir RewindDir
;
350 UnixCloseDir CloseDir
;
359 UnixUgaCreate UgaCreate
;
363 UnixCfsetispeed Cfsetispeed
;
364 UnixCfsetospeed Cfsetospeed
;
365 UnixTcgetattr Tcgetattr
;
366 UnixTcsetattr Tcsetattr
;
370 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint
;
371 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction
;
372 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction
;
375 } EFI_UNIX_THUNK_PROTOCOL
;
377 extern EFI_GUID gEfiUnixThunkProtocolGuid
;