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