]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Include/Protocol/UnixThunk.h
UnixPkg: Added missing EFIAPI for many Gasket functions
[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>
124f761f 5This program and the accompanying materials
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.
804405e7 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>
124f761f 61#endif
ccd55824 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 { \
124f761f 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! */
7ee3b613
A
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 135
124f761f 136#else
7ee3b613
A
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
124f761f 149(EFIAPI *UnixSleep) (
804405e7 150 unsigned long Milliseconds
151 );
152
153typedef
154VOID
124f761f 155(EFIAPI *UnixExit) (
804405e7 156 int status // exit code for all threads
157 );
158
159typedef
160VOID
124f761f 161(EFIAPI *UnixSetTimer) (
162 UINT64 PeriodMs,
163 VOID (EFIAPI *CallBack)(UINT64 DeltaMs)
b9c8e50e 164 );
165
804405e7 166typedef
167VOID
124f761f 168(EFIAPI *UnixGetLocalTime) (
b9c8e50e 169 EFI_TIME *Time
170 );
171
804405e7 172typedef
173struct tm *
124f761f 174(EFIAPI *UnixGmTime)(
b9c8e50e 175 const time_t *timep
176 );
177
804405e7 178typedef
179long
124f761f 180(EFIAPI *UnixGetTimeZone)(
b9c8e50e 181 void
182 );
183
804405e7 184typedef
185int
124f761f 186(EFIAPI *UnixGetDayLight)(
b9c8e50e 187 void
188 );
189
804405e7 190typedef
191int
124f761f 192(EFIAPI *UnixPoll)(
193 struct pollfd *pfd,
194 unsigned int nfds,
b9c8e50e 195 int timeout
196 );
197
804405e7 198typedef
b9c8e50e 199long
124f761f 200(EFIAPI *UnixRead) (
201 int fd,
202 void *buf,
b9c8e50e 203 int count
204 );
205
804405e7 206typedef
b9c8e50e 207long
124f761f 208(EFIAPI *UnixWrite) (
209 int fd,
210 const void *buf,
b9c8e50e 211 int count
212 );
213
804405e7 214typedef
215char *
124f761f 216(EFIAPI *UnixGetenv) (const char *var);
b9c8e50e 217
804405e7 218typedef
219int
124f761f 220(EFIAPI *UnixOpen) (const char *name, int flags, int mode);
b9c8e50e 221
804405e7 222typedef
7ee3b613 223off_t
124f761f 224(EFIAPI *UnixSeek) (int fd, off_t off, int whence);
b9c8e50e 225
804405e7 226typedef
227int
124f761f 228(EFIAPI *UnixFtruncate) (int fd, long int len);
b9c8e50e 229
804405e7 230typedef
231int
124f761f 232(EFIAPI *UnixClose) (int fd);
804405e7 233
234typedef
235int
124f761f 236(EFIAPI *UnixMkdir)(const char *pathname, mode_t mode);
b9c8e50e 237
804405e7 238typedef
239int
124f761f 240(EFIAPI *UnixRmDir)(const char *pathname);
b9c8e50e 241
804405e7 242typedef
243int
124f761f 244(EFIAPI *UnixUnLink)(const char *pathname);
b9c8e50e 245
804405e7 246typedef
247int
124f761f 248(EFIAPI *UnixGetErrno)(VOID);
b9c8e50e 249
804405e7 250typedef
251DIR *
124f761f 252(EFIAPI *UnixOpenDir)(const char *pathname);
b9c8e50e 253
804405e7 254typedef
255void
124f761f 256(EFIAPI *UnixRewindDir)(DIR *dir);
b9c8e50e 257
804405e7 258typedef
259struct dirent *
124f761f 260(EFIAPI *UnixReadDir)(DIR *dir);
b9c8e50e 261
804405e7 262typedef
263int
124f761f 264(EFIAPI *UnixCloseDir)(DIR *dir);
b9c8e50e 265
804405e7 266typedef
267int
124f761f 268(EFIAPI *UnixStat)(const char *path, STAT_FIX *buf);
b9c8e50e 269
804405e7 270typedef
271int
124f761f 272(EFIAPI *UnixStatFs)(const char *path, struct statfs *buf);
b9c8e50e 273
804405e7 274typedef
275int
124f761f 276(EFIAPI *UnixRename)(const char *oldpath, const char *newpath);
b9c8e50e 277
804405e7 278typedef
279time_t
124f761f 280(EFIAPI *UnixMkTime)(struct tm *tm);
b9c8e50e 281
804405e7 282typedef
283int
124f761f 284(EFIAPI *UnixFSync)(int fd);
b9c8e50e 285
804405e7 286typedef
287int
124f761f 288(EFIAPI *UnixChmod)(const char *path, mode_t mode);
b9c8e50e 289
804405e7 290typedef
291int
124f761f 292(EFIAPI *UnixUTime)(const char *filename, const struct utimbuf *buf);
804405e7 293
294struct _EFI_UNIX_UGA_IO_PROTOCOL;
295typedef
296EFI_STATUS
124f761f 297(EFIAPI *UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
804405e7 298 CONST CHAR16 *Title);
299
300typedef
301int
124f761f 302(EFIAPI *UnixTcflush) (int fildes, int queue_selector);
804405e7 303
304typedef
305void
124f761f 306(EFIAPI *UnixPerror) (__const char *__s);
804405e7 307
124f761f 308typedef
309int
ccd55824 310#if __CYGWIN__
124f761f 311(EFIAPI *UnixIoCtl) (int fd, int __request, UINTN Arg);
ccd55824 312#else
124f761f 313(EFIAPI *UnixIoCtl) (int fd, unsigned long int __request, void *Arg);
ccd55824 314#endif
804405e7 315
124f761f 316typedef
317int
318(EFIAPI *UnixFcntl) (int __fd, int __cmd, void *Arg);
804405e7 319
320typedef
124f761f 321int
322(EFIAPI *UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
804405e7 323
124f761f 324typedef
325int
326(EFIAPI *UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
804405e7 327
328typedef
124f761f 329int
330(EFIAPI *UnixTcgetattr) (int __fd, struct termios *__termios_p);
804405e7 331
124f761f 332typedef
333int
334(EFIAPI *UnixTcsetattr) (int __fd, int __optional_actions,
804405e7 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
124f761f 342typedef
ccd55824 343RETURN_STATUS
344(EFIAPI *UnixPeCoffGetEntryPoint) (
345 IN VOID *Pe32Data,
346 IN OUT VOID **EntryPoint
347 );
348
124f761f 349typedef
ccd55824 350VOID
351(EFIAPI *UnixPeCoffRelocateImageExtraAction) (
352 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
353 );
354
124f761f 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;
69cf40e0 376 UnixRead Read;
377 UnixWrite Write;
378 UnixGetenv Getenv;
379 UnixOpen Open;
380 UnixSeek Lseek;
381 UnixFtruncate FTruncate;
382 UnixClose Close;
804405e7 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;
124f761f 410
411
804405e7 412} EFI_UNIX_THUNK_PROTOCOL;
413
414extern EFI_GUID gEfiUnixThunkProtocolGuid;
415
416#endif