]>
Commit | Line | Data |
---|---|---|
804405e7 | 1 | /*++ |
2 | ||
f9b8ab56 HT |
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 | |
804405e7 | 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> | |
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 | ||
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 | #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 | ||
144 | typedef | |
145 | VOID | |
146 | (*UnixSleep) ( | |
147 | unsigned long Milliseconds | |
148 | ); | |
149 | ||
150 | typedef | |
151 | VOID | |
152 | (*UnixExit) ( | |
153 | int status // exit code for all threads | |
154 | ); | |
155 | ||
156 | typedef | |
157 | VOID | |
158 | (*UnixSetTimer) (UINT64 PeriodMs, VOID (*CallBack)(UINT64 DeltaMs)); | |
159 | typedef | |
160 | VOID | |
161 | (*UnixGetLocalTime) (EFI_TIME *Time); | |
162 | typedef | |
163 | struct tm * | |
164 | (*UnixGmTime)(const time_t *timep); | |
165 | typedef | |
166 | long | |
167 | (*UnixGetTimeZone)(void); | |
168 | typedef | |
169 | int | |
170 | (*UnixGetDayLight)(void); | |
171 | typedef | |
172 | int | |
173 | (*UnixPoll)(struct pollfd *pfd, int nfds, int timeout); | |
174 | typedef | |
175 | int | |
176 | (*UnixRead) (int fd, void *buf, int count); | |
177 | typedef | |
178 | int | |
179 | (*UnixWrite) (int fd, const void *buf, int count); | |
180 | typedef | |
181 | char * | |
182 | (*UnixGetenv) (const char *var); | |
183 | typedef | |
184 | int | |
185 | (*UnixOpen) (const char *name, int flags, int mode); | |
186 | typedef | |
7ee3b613 A |
187 | off_t |
188 | (*UnixSeek) (int fd, off_t off, int whence); | |
804405e7 | 189 | typedef |
190 | int | |
191 | (*UnixFtruncate) (int fd, long int len); | |
192 | typedef | |
193 | int | |
194 | (*UnixClose) (int fd); | |
195 | ||
196 | typedef | |
197 | int | |
198 | (*UnixMkdir)(const char *pathname, mode_t mode); | |
199 | typedef | |
200 | int | |
201 | (*UnixRmDir)(const char *pathname); | |
202 | typedef | |
203 | int | |
204 | (*UnixUnLink)(const char *pathname); | |
205 | typedef | |
206 | int | |
207 | (*UnixGetErrno)(VOID); | |
208 | typedef | |
209 | DIR * | |
210 | (*UnixOpenDir)(const char *pathname); | |
211 | typedef | |
212 | void | |
213 | (*UnixRewindDir)(DIR *dir); | |
214 | typedef | |
215 | struct dirent * | |
216 | (*UnixReadDir)(DIR *dir); | |
217 | typedef | |
218 | int | |
219 | (*UnixCloseDir)(DIR *dir); | |
220 | typedef | |
221 | int | |
7ee3b613 | 222 | (*UnixStat)(const char *path, STAT_FIX *buf); |
804405e7 | 223 | typedef |
224 | int | |
225 | (*UnixStatFs)(const char *path, struct statfs *buf); | |
226 | typedef | |
227 | int | |
228 | (*UnixRename)(const char *oldpath, const char *newpath); | |
229 | typedef | |
230 | time_t | |
231 | (*UnixMkTime)(struct tm *tm); | |
232 | typedef | |
233 | int | |
234 | (*UnixFSync)(int fd); | |
235 | typedef | |
236 | int | |
237 | (*UnixChmod)(const char *path, mode_t mode); | |
238 | typedef | |
239 | int | |
240 | (*UnixUTime)(const char *filename, const struct utimbuf *buf); | |
241 | ||
242 | struct _EFI_UNIX_UGA_IO_PROTOCOL; | |
243 | typedef | |
244 | EFI_STATUS | |
245 | (*UnixUgaCreate)(struct _EFI_UNIX_UGA_IO_PROTOCOL **UgaIo, | |
246 | CONST CHAR16 *Title); | |
247 | ||
248 | typedef | |
249 | int | |
250 | (*UnixTcflush) (int fildes, int queue_selector); | |
251 | ||
252 | typedef | |
253 | void | |
254 | (*UnixPerror) (__const char *__s); | |
255 | ||
256 | typedef | |
257 | int | |
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 | |
264 | typedef | |
265 | int | |
266 | (*UnixFcntl) (int __fd, int __cmd, ...); | |
267 | ||
268 | typedef | |
269 | int | |
270 | (*UnixCfsetispeed) (struct termios *__termios_p, speed_t __speed); | |
271 | ||
272 | typedef | |
273 | int | |
274 | (*UnixCfsetospeed) (struct termios *__termios_p, speed_t __speed); | |
275 | ||
276 | typedef | |
277 | int | |
278 | (*UnixTcgetattr) (int __fd, struct termios *__termios_p); | |
279 | ||
280 | typedef | |
281 | int | |
282 | (*UnixTcsetattr) (int __fd, int __optional_actions, | |
283 | __const struct termios *__termios_p); | |
284 | ||
7ee3b613 | 285 | typedef |
398b646f | 286 | VOID * |
287 | (*UnixDlopen) (const char *FileName, int Flag); | |
288 | ||
289 | typedef | |
290 | char * | |
291 | (*UnixDlerror) (VOID); | |
292 | ||
293 | typedef | |
294 | VOID * | |
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 | 302 | typedef |
ccd55824 | 303 | RETURN_STATUS |
304 | (EFIAPI *UnixPeCoffGetEntryPoint) ( | |
305 | IN VOID *Pe32Data, | |
306 | IN OUT VOID **EntryPoint | |
307 | ); | |
308 | ||
7ee3b613 | 309 | typedef |
ccd55824 | 310 | VOID |
311 | (EFIAPI *UnixPeCoffRelocateImageExtraAction) ( | |
312 | IN OUT PE_COFF_LOADER_IMAGE_CONTEXT *ImageContext | |
313 | ); | |
314 | ||
7ee3b613 | 315 | typedef |
ccd55824 | 316 | VOID |
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 | |
325 | typedef 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 | ||
377 | extern EFI_GUID gEfiUnixThunkProtocolGuid; | |
378 | ||
379 | #endif |