]> git.proxmox.com Git - mirror_edk2.git/blame - UnixPkg/Include/Protocol/UnixThunk.h
Update the copyright notice format
[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>
398b646f 64#include <dlfcn.h>
7ee3b613 65#include <ucontext.h>
804405e7 66
ccd55824 67#include <Base.h>
68#include <Library/PeCoffLib.h>
69
70
7ee3b613
A
71#if __APPLE__
72//
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
76//
77#pragma pack(4)
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
130#pragma pack()
131#endif
132
133#else
134
135 typedef struct stat STAT_FIX;
136
137#endif
138
804405e7 139#define EFI_UNIX_THUNK_PROTOCOL_GUID \
140 { \
141 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
142 }
143
144typedef
145VOID
146(*UnixSleep) (
147 unsigned long Milliseconds
148 );
149
150typedef
151VOID
152(*UnixExit) (
153 int status // exit code for all threads
154 );
155
156typedef
157VOID
158(*UnixSetTimer) (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs));
159typedef
160VOID
161(*UnixGetLocalTime) (EFI_TIME *Time);
162typedef
163struct tm *
164(*UnixGmTime)(const time_t *timep);
165typedef
166long
167(*UnixGetTimeZone)(void);
168typedef
169int
170(*UnixGetDayLight)(void);
171typedef
172int
173(*UnixPoll)(struct pollfd *pfd, int nfds, int timeout);
174typedef
175int
176(*UnixRead) (int fd, void *buf, int count);
177typedef
178int
179(*UnixWrite) (int fd, const void *buf, int count);
180typedef
181char *
182(*UnixGetenv) (const char *var);
183typedef
184int
185(*UnixOpen) (const char *name, int flags, int mode);
186typedef
7ee3b613
A
187off_t
188(*UnixSeek) (int fd, off_t off, int whence);
804405e7 189typedef
190int
191(*UnixFtruncate) (int fd, long int len);
192typedef
193int
194(*UnixClose) (int fd);
195
196typedef
197int
198(*UnixMkdir)(const char *pathname, mode_t mode);
199typedef
200int
201(*UnixRmDir)(const char *pathname);
202typedef
203int
204(*UnixUnLink)(const char *pathname);
205typedef
206int
207(*UnixGetErrno)(VOID);
208typedef
209DIR *
210(*UnixOpenDir)(const char *pathname);
211typedef
212void
213(*UnixRewindDir)(DIR *dir);
214typedef
215struct dirent *
216(*UnixReadDir)(DIR *dir);
217typedef
218int
219(*UnixCloseDir)(DIR *dir);
220typedef
221int
7ee3b613 222(*UnixStat)(const char *path, STAT_FIX *buf);
804405e7 223typedef
224int
225(*UnixStatFs)(const char *path, struct statfs *buf);
226typedef
227int
228(*UnixRename)(const char *oldpath, const char *newpath);
229typedef
230time_t
231(*UnixMkTime)(struct tm *tm);
232typedef
233int
234(*UnixFSync)(int fd);
235typedef
236int
237(*UnixChmod)(const char *path, mode_t mode);
238typedef
239int
240(*UnixUTime)(const char *filename, const struct utimbuf *buf);
241
242struct _EFI_UNIX_UGA_IO_PROTOCOL;
243typedef
244EFI_STATUS
245(*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
246 CONST CHAR16 *Title);
247
248typedef
249int
250(*UnixTcflush) (int fildes, int queue_selector);
251
252typedef
253void
254(*UnixPerror) (__const char *__s);
255
256typedef
257int
ccd55824 258#if __CYGWIN__
259(*UnixIoCtl) (int fd, int __request, ...);
260#else
804405e7 261(*UnixIoCtl) (int fd, unsigned long int __request, ...);
ccd55824 262#endif
804405e7 263
264typedef
265int
266(*UnixFcntl) (int __fd, int __cmd, ...);
267
268typedef
269int
270(*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
271
272typedef
273int
274(*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
275
276typedef
277int
278(*UnixTcgetattr) (int __fd, struct termios *__termios_p);
279
280typedef
281int
282(*UnixTcsetattr) (int __fd, int __optional_actions,
283 __const struct termios *__termios_p);
284
7ee3b613 285typedef
398b646f 286VOID *
287(*UnixDlopen) (const char *FileName, int Flag);
288
289typedef
290char *
291(*UnixDlerror) (VOID);
292
293typedef
294VOID *
295(*UnixDlsym) (VOID* Handle, const char* Symbol);
296
297
804405e7 298//
ccd55824 299// Work functions to enable source level debug in the emulator
804405e7 300//
ccd55824 301
7ee3b613 302typedef
ccd55824 303RETURN_STATUS
304(EFIAPI *UnixPeCoffGetEntryPoint) (
305 IN VOID *Pe32Data,
306 IN OUT VOID **EntryPoint
307 );
308
7ee3b613 309typedef
ccd55824 310VOID
311(EFIAPI *UnixPeCoffRelocateImageExtraAction) (
312 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
313 );
314
7ee3b613 315typedef
ccd55824 316VOID
317(EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) (
318 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
319 );
320
321
804405e7 322
208301e9 323#define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
804405e7 324
325typedef struct _EFI_UNIX_THUNK_PROTOCOL {
326 UINT64 Signature;
327
328 UnixSleep Sleep;
329 UnixExit Exit;
330 UnixSetTimer SetTimer;
331 UnixGetLocalTime GetLocalTime;
332 UnixGmTime GmTime;
333 UnixGetTimeZone GetTimeZone;
334 UnixGetDayLight GetDayLight;
335 UnixPoll Poll;
336 UnixRead Read;
337 UnixWrite Write;
338 UnixGetenv Getenv;
339 UnixOpen Open;
340 UnixSeek Lseek;
341 UnixFtruncate FTruncate;
342 UnixClose Close;
343 UnixMkdir MkDir;
344 UnixRmDir RmDir;
345 UnixUnLink UnLink;
346 UnixGetErrno GetErrno;
347 UnixOpenDir OpenDir;
348 UnixRewindDir RewindDir;
349 UnixReadDir ReadDir;
350 UnixCloseDir CloseDir;
351 UnixStat Stat;
352 UnixStatFs StatFs;
353 UnixRename Rename;
354 UnixMkTime MkTime;
355 UnixFSync FSync;
356 UnixChmod Chmod;
357 UnixUTime UTime;
358 UnixTcflush Tcflush;
359 UnixUgaCreate UgaCreate;
360 UnixPerror Perror;
361 UnixIoCtl IoCtl;
362 UnixFcntl Fcntl;
363 UnixCfsetispeed Cfsetispeed;
364 UnixCfsetospeed Cfsetospeed;
365 UnixTcgetattr Tcgetattr;
366 UnixTcsetattr Tcsetattr;
398b646f 367 UnixDlopen Dlopen;
368 UnixDlerror Dlerror;
369 UnixDlsym Dlsym;
ccd55824 370 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint;
371 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction;
372 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction;
373
374
804405e7 375} EFI_UNIX_THUNK_PROTOCOL;
376
377extern EFI_GUID gEfiUnixThunkProtocolGuid;
378
379#endif