]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Include/Protocol/UnixThunk.h
ShellPkg: Fix "unreachable code" warning with VS2005
[mirror_edk2.git] / UnixPkg / Include / Protocol / UnixThunk.h
CommitLineData
804405e7 1/*++
2
f9b8ab56
HT
3Copyright (c) 2004 - 2009, Intel Corporation. All rights reserved.<BR>
4Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
5This program and the accompanying materials
804405e7 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.
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
54#ifdef __APPLE__
55#include <sys/param.h>
56#include <sys/mount.h>
57#define _XOPEN_SOURCE
58#else
59#include <termio.h>
804405e7 60#include <sys/vfs.h>
ccd55824 61#endif
62
804405e7 63#include <utime.h>
64
ccd55824 65#include <Base.h>
66#include <Library/PeCoffLib.h>
67
68
7ee3b613
A
69#if __APPLE__
70//
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
74//
b9c8e50e 75#ifdef MDE_CPU_IA32
7ee3b613 76#pragma pack(4)
b9c8e50e 77#endif
7ee3b613
A
78
79#if __DARWIN_64_BIT_INO_T
80
81typedef 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! */
97} STAT_FIX;
98
99#else /* !__DARWIN_64_BIT_INO_T */
100
101typedef 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 */
113#else
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 */
120#endif
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! */
128} STAT_FIX;
129
7ee3b613 130#endif
b9c8e50e 131
132#ifdef MDE_CPU_IA32
133#pragma pack(4)
134#endif
7ee3b613
A
135
136#else
137
138 typedef struct stat STAT_FIX;
139
140#endif
141
804405e7 142#define EFI_UNIX_THUNK_PROTOCOL_GUID \
143 { \
144 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
145 }
146
147typedef
148VOID
149(*UnixSleep) (
150 unsigned long Milliseconds
151 );
152
153typedef
154VOID
155(*UnixExit) (
156 int status // exit code for all threads
157 );
158
159typedef
160VOID
b9c8e50e 161(*UnixSetTimer) (
162 UINT64 PeriodMs,
163 VOID (*CallBack)(UINT64 DeltaMs)
164 );
165
804405e7 166typedef
167VOID
b9c8e50e 168(*UnixGetLocalTime) (
169 EFI_TIME *Time
170 );
171
804405e7 172typedef
173struct tm *
b9c8e50e 174(*UnixGmTime)(
175 const time_t *timep
176 );
177
804405e7 178typedef
179long
b9c8e50e 180(*UnixGetTimeZone)(
181 void
182 );
183
804405e7 184typedef
185int
b9c8e50e 186(*UnixGetDayLight)(
187 void
188 );
189
804405e7 190typedef
191int
b9c8e50e 192(*UnixPoll)(
193 struct pollfd *pfd,
194 unsigned int nfds,
195 int timeout
196 );
197
804405e7 198typedef
b9c8e50e 199long
200(*UnixRead) (
201 int fd,
202 void *buf,
203 int count
204 );
205
804405e7 206typedef
b9c8e50e 207long
208(*UnixWrite) (
209 int fd,
210 const void *buf,
211 int count
212 );
213
804405e7 214typedef
215char *
216(*UnixGetenv) (const char *var);
b9c8e50e 217
804405e7 218typedef
219int
220(*UnixOpen) (const char *name, int flags, int mode);
b9c8e50e 221
804405e7 222typedef
7ee3b613
A
223off_t
224(*UnixSeek) (int fd, off_t off, int whence);
b9c8e50e 225
804405e7 226typedef
227int
228(*UnixFtruncate) (int fd, long int len);
b9c8e50e 229
804405e7 230typedef
231int
232(*UnixClose) (int fd);
233
234typedef
235int
236(*UnixMkdir)(const char *pathname, mode_t mode);
b9c8e50e 237
804405e7 238typedef
239int
240(*UnixRmDir)(const char *pathname);
b9c8e50e 241
804405e7 242typedef
243int
244(*UnixUnLink)(const char *pathname);
b9c8e50e 245
804405e7 246typedef
247int
248(*UnixGetErrno)(VOID);
b9c8e50e 249
804405e7 250typedef
251DIR *
252(*UnixOpenDir)(const char *pathname);
b9c8e50e 253
804405e7 254typedef
255void
256(*UnixRewindDir)(DIR *dir);
b9c8e50e 257
804405e7 258typedef
259struct dirent *
260(*UnixReadDir)(DIR *dir);
b9c8e50e 261
804405e7 262typedef
263int
264(*UnixCloseDir)(DIR *dir);
b9c8e50e 265
804405e7 266typedef
267int
7ee3b613 268(*UnixStat)(const char *path, STAT_FIX *buf);
b9c8e50e 269
804405e7 270typedef
271int
272(*UnixStatFs)(const char *path, struct statfs *buf);
b9c8e50e 273
804405e7 274typedef
275int
276(*UnixRename)(const char *oldpath, const char *newpath);
b9c8e50e 277
804405e7 278typedef
279time_t
280(*UnixMkTime)(struct tm *tm);
b9c8e50e 281
804405e7 282typedef
283int
284(*UnixFSync)(int fd);
b9c8e50e 285
804405e7 286typedef
287int
288(*UnixChmod)(const char *path, mode_t mode);
b9c8e50e 289
804405e7 290typedef
291int
292(*UnixUTime)(const char *filename, const struct utimbuf *buf);
293
294struct _EFI_UNIX_UGA_IO_PROTOCOL;
295typedef
296EFI_STATUS
297(*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
298 CONST CHAR16 *Title);
299
300typedef
301int
302(*UnixTcflush) (int fildes, int queue_selector);
303
304typedef
305void
306(*UnixPerror) (__const char *__s);
307
308typedef
309int
ccd55824 310#if __CYGWIN__
a4902ccc 311(*UnixIoCtl) (int fd, int __request, UINTN Arg);
ccd55824 312#else
a4902ccc 313(*UnixIoCtl) (int fd, unsigned long int __request, void *Arg);
ccd55824 314#endif
804405e7 315
316typedef
317int
a4902ccc 318(*UnixFcntl) (int __fd, int __cmd, void *Arg);
804405e7 319
320typedef
321int
322(*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
323
324typedef
325int
326(*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
327
328typedef
329int
330(*UnixTcgetattr) (int __fd, struct termios *__termios_p);
331
332typedef
333int
334(*UnixTcsetattr) (int __fd, int __optional_actions,
335 __const struct termios *__termios_p);
336
398b646f 337
804405e7 338//
b9c8e50e 339// Worker functions to enable source level debug in the emulator
804405e7 340//
ccd55824 341
7ee3b613 342typedef
ccd55824 343RETURN_STATUS
344(EFIAPI *UnixPeCoffGetEntryPoint) (
345 IN VOID *Pe32Data,
346 IN OUT VOID **EntryPoint
347 );
348
7ee3b613 349typedef
ccd55824 350VOID
351(EFIAPI *UnixPeCoffRelocateImageExtraAction) (
352 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
353 );
354
7ee3b613 355typedef
ccd55824 356VOID
357(EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) (
358 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
359 );
360
361
804405e7 362
208301e9 363#define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
804405e7 364
365typedef struct _EFI_UNIX_THUNK_PROTOCOL {
366 UINT64 Signature;
367
368 UnixSleep Sleep;
369 UnixExit Exit;
370 UnixSetTimer SetTimer;
371 UnixGetLocalTime GetLocalTime;
372 UnixGmTime GmTime;
373 UnixGetTimeZone GetTimeZone;
374 UnixGetDayLight GetDayLight;
375 UnixPoll Poll;
376 UnixRead Read;
377 UnixWrite Write;
378 UnixGetenv Getenv;
379 UnixOpen Open;
380 UnixSeek Lseek;
381 UnixFtruncate FTruncate;
382 UnixClose Close;
383 UnixMkdir MkDir;
384 UnixRmDir RmDir;
385 UnixUnLink UnLink;
386 UnixGetErrno GetErrno;
387 UnixOpenDir OpenDir;
388 UnixRewindDir RewindDir;
389 UnixReadDir ReadDir;
390 UnixCloseDir CloseDir;
391 UnixStat Stat;
392 UnixStatFs StatFs;
393 UnixRename Rename;
394 UnixMkTime MkTime;
395 UnixFSync FSync;
396 UnixChmod Chmod;
397 UnixUTime UTime;
398 UnixTcflush Tcflush;
399 UnixUgaCreate UgaCreate;
400 UnixPerror Perror;
401 UnixIoCtl IoCtl;
402 UnixFcntl Fcntl;
403 UnixCfsetispeed Cfsetispeed;
404 UnixCfsetospeed Cfsetospeed;
405 UnixTcgetattr Tcgetattr;
406 UnixTcsetattr Tcsetattr;
ccd55824 407 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint;
408 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction;
409 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction;
410
411
804405e7 412} EFI_UNIX_THUNK_PROTOCOL;
413
414extern EFI_GUID gEfiUnixThunkProtocolGuid;
415
416#endif