]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/Include/Protocol/UnixThunk.h
689e32fd7d40d003e27715d194d60d6a312ea526
[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
65 #include <Base.h>
66 #include <Library/PeCoffLib.h>
67
68
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 //
75 #ifdef MDE_CPU_IA32
76 #pragma pack(4)
77 #endif
78
79 #if __DARWIN_64_BIT_INO_T
80
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! */
97 } STAT_FIX;
98
99 #else /* !__DARWIN_64_BIT_INO_T */
100
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 */
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 #endif
131
132 #ifdef MDE_CPU_IA32
133 #pragma pack(4)
134 #endif
135
136 #else
137
138 typedef struct stat STAT_FIX;
139
140 #endif
141
142 #define EFI_UNIX_THUNK_PROTOCOL_GUID \
143 { \
144 0xf2e98868, 0x8985, 0x11db, {0x9a, 0x59, 0x00, 0x40, 0xd0, 0x2b, 0x18, 0x35 } \
145 }
146
147 typedef
148 VOID
149 (*UnixSleep) (
150 unsigned long Milliseconds
151 );
152
153 typedef
154 VOID
155 (*UnixExit) (
156 int status // exit code for all threads
157 );
158
159 typedef
160 VOID
161 (*UnixSetTimer) (
162 UINT64 PeriodMs,
163 VOID (*CallBack)(UINT64 DeltaMs)
164 );
165
166 typedef
167 VOID
168 (*UnixGetLocalTime) (
169 EFI_TIME *Time
170 );
171
172 typedef
173 struct tm *
174 (*UnixGmTime)(
175 const time_t *timep
176 );
177
178 typedef
179 long
180 (*UnixGetTimeZone)(
181 void
182 );
183
184 typedef
185 int
186 (*UnixGetDayLight)(
187 void
188 );
189
190 typedef
191 int
192 (*UnixPoll)(
193 struct pollfd *pfd,
194 unsigned int nfds,
195 int timeout
196 );
197
198 typedef
199 long
200 (*UnixRead) (
201 int fd,
202 void *buf,
203 int count
204 );
205
206 typedef
207 long
208 (*UnixWrite) (
209 int fd,
210 const void *buf,
211 int count
212 );
213
214 typedef
215 char *
216 (*UnixGetenv) (const char *var);
217
218 typedef
219 int
220 (*UnixOpen) (const char *name, int flags, int mode);
221
222 typedef
223 off_t
224 (*UnixSeek) (int fd, off_t off, int whence);
225
226 typedef
227 int
228 (*UnixFtruncate) (int fd, long int len);
229
230 typedef
231 int
232 (*UnixClose) (int fd);
233
234 typedef
235 int
236 (*UnixMkdir)(const char *pathname, mode_t mode);
237
238 typedef
239 int
240 (*UnixRmDir)(const char *pathname);
241
242 typedef
243 int
244 (*UnixUnLink)(const char *pathname);
245
246 typedef
247 int
248 (*UnixGetErrno)(VOID);
249
250 typedef
251 DIR *
252 (*UnixOpenDir)(const char *pathname);
253
254 typedef
255 void
256 (*UnixRewindDir)(DIR *dir);
257
258 typedef
259 struct dirent *
260 (*UnixReadDir)(DIR *dir);
261
262 typedef
263 int
264 (*UnixCloseDir)(DIR *dir);
265
266 typedef
267 int
268 (*UnixStat)(const char *path, STAT_FIX *buf);
269
270 typedef
271 int
272 (*UnixStatFs)(const char *path, struct statfs *buf);
273
274 typedef
275 int
276 (*UnixRename)(const char *oldpath, const char *newpath);
277
278 typedef
279 time_t
280 (*UnixMkTime)(struct tm *tm);
281
282 typedef
283 int
284 (*UnixFSync)(int fd);
285
286 typedef
287 int
288 (*UnixChmod)(const char *path, mode_t mode);
289
290 typedef
291 int
292 (*UnixUTime)(const char *filename, const struct utimbuf *buf);
293
294 struct _EFI_UNIX_UGA_IO_PROTOCOL;
295 typedef
296 EFI_STATUS
297 (*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo,
298 CONST CHAR16 *Title);
299
300 typedef
301 int
302 (*UnixTcflush) (int fildes, int queue_selector);
303
304 typedef
305 void
306 (*UnixPerror) (__const char *__s);
307
308 typedef
309 int
310 #if __CYGWIN__
311 (*UnixIoCtl) (int fd, int __request, UINTN Arg);
312 #else
313 (*UnixIoCtl) (int fd, unsigned long int __request, void *Arg);
314 #endif
315
316 typedef
317 int
318 (*UnixFcntl) (int __fd, int __cmd, void *Arg);
319
320 typedef
321 int
322 (*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed);
323
324 typedef
325 int
326 (*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed);
327
328 typedef
329 int
330 (*UnixTcgetattr) (int __fd, struct termios *__termios_p);
331
332 typedef
333 int
334 (*UnixTcsetattr) (int __fd, int __optional_actions,
335 __const struct termios *__termios_p);
336
337
338 //
339 // Worker functions to enable source level debug in the emulator
340 //
341
342 typedef
343 RETURN_STATUS
344 (EFIAPI *UnixPeCoffGetEntryPoint) (
345 IN VOID *Pe32Data,
346 IN OUT VOID **EntryPoint
347 );
348
349 typedef
350 VOID
351 (EFIAPI *UnixPeCoffRelocateImageExtraAction) (
352 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
353 );
354
355 typedef
356 VOID
357 (EFIAPI *UnixPeCoffLoaderUnloadImageExtraAction) (
358 IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext
359 );
360
361
362
363 #define EFI_UNIX_THUNK_PROTOCOL_SIGNATURE SIGNATURE_32 ('L', 'N', 'X', 'T')
364
365 typedef 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;
407 UnixPeCoffGetEntryPoint PeCoffGetEntryPoint;
408 UnixPeCoffRelocateImageExtraAction PeCoffRelocateImageExtraAction;
409 UnixPeCoffLoaderUnloadImageExtraAction PeCoffUnloadImageExtraAction;
410
411
412 } EFI_UNIX_THUNK_PROTOCOL;
413
414 extern EFI_GUID gEfiUnixThunkProtocolGuid;
415
416 #endif