OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <sys/types.h> // Include something that will define __GLIBC__. | 5 #include <sys/types.h> // Include something that will define __GLIBC__. |
6 | 6 |
7 // The entire file is wrapped in this #if. We do this so this .cc file can be | 7 // The entire file is wrapped in this #if. We do this so this .cc file can be |
8 // compiled, even on a non-newlib build. | 8 // compiled, even on a non-newlib build. |
9 #if defined(__native_client__) && !defined(__GLIBC__) && !defined(__BIONIC__) | 9 #if defined(__native_client__) && !defined(__GLIBC__) && !defined(__BIONIC__) |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 #define REAL(name) __nacl_irt_##name##_real | 28 #define REAL(name) __nacl_irt_##name##_real |
29 | 29 |
30 // Macro to get the WRAP function | 30 // Macro to get the WRAP function |
31 #define WRAP(name) __nacl_irt_##name##_wrap | 31 #define WRAP(name) __nacl_irt_##name##_wrap |
32 | 32 |
33 // Declare REAL function pointer. | 33 // Declare REAL function pointer. |
34 #define DECLARE_REAL_PTR(group, name) \ | 34 #define DECLARE_REAL_PTR(group, name) \ |
35 typeof(__libnacl_irt_##group.name) REAL(name); | 35 typeof(__libnacl_irt_##group.name) REAL(name); |
36 | 36 |
37 // Assign the REAL function pointer. | 37 // Assign the REAL function pointer. |
38 #define ASSIGN_REAL_PTR(group, name) \ | 38 #define ASSIGN_REAL_PTR(group, name) REAL(name) = __libnacl_irt_##group.name; |
39 REAL(name) = __libnacl_irt_##group.name; | |
40 | 39 |
41 // Switch IRT's pointer to the REAL pointer | 40 // Switch IRT's pointer to the REAL pointer |
42 #define USE_REAL(group, name) \ | 41 #define USE_REAL(group, name) \ |
43 __libnacl_irt_##group.name = (typeof(REAL(name))) REAL(name); \ | 42 __libnacl_irt_##group.name = (typeof(REAL(name)))REAL(name); |
44 | 43 |
45 // Switch the IRT's pointer to the WRAP function | 44 // Switch the IRT's pointer to the WRAP function |
46 #define USE_WRAP(group, name) \ | 45 #define USE_WRAP(group, name) \ |
47 __libnacl_irt_##group.name = (typeof(REAL(name))) WRAP(name); \ | 46 __libnacl_irt_##group.name = (typeof(REAL(name)))WRAP(name); |
48 | 47 |
49 extern void __libnacl_irt_dev_filename_init(void); | 48 extern void __libnacl_irt_dev_filename_init(void); |
50 | 49 |
51 extern struct nacl_irt_basic __libnacl_irt_basic; | 50 extern struct nacl_irt_basic __libnacl_irt_basic; |
52 extern struct nacl_irt_fdio __libnacl_irt_fdio; | 51 extern struct nacl_irt_fdio __libnacl_irt_fdio; |
53 extern struct nacl_irt_dev_fdio __libnacl_irt_dev_fdio; | 52 extern struct nacl_irt_dev_fdio __libnacl_irt_dev_fdio; |
54 extern struct nacl_irt_dev_filename __libnacl_irt_dev_filename; | 53 extern struct nacl_irt_dev_filename __libnacl_irt_dev_filename; |
55 extern struct nacl_irt_memory __libnacl_irt_memory; | 54 extern struct nacl_irt_memory __libnacl_irt_memory; |
56 | 55 |
57 // Create function pointers to the REAL implementation | 56 // Create function pointers to the REAL implementation |
58 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ | 57 #define EXPAND_SYMBOL_LIST_OPERATION(OP) \ |
59 OP(basic, exit); \ | 58 OP(basic, exit); \ |
60 OP(fdio, close); \ | 59 OP(fdio, close); \ |
61 OP(fdio, dup); \ | 60 OP(fdio, dup); \ |
62 OP(fdio, dup2); \ | 61 OP(fdio, dup2); \ |
63 OP(fdio, read); \ | 62 OP(fdio, read); \ |
64 OP(fdio, write); \ | 63 OP(fdio, write); \ |
65 OP(fdio, seek); \ | 64 OP(fdio, seek); \ |
66 OP(fdio, fstat); \ | 65 OP(fdio, fstat); \ |
67 OP(fdio, getdents); \ | 66 OP(fdio, getdents); \ |
68 OP(dev_fdio, fchdir); \ | 67 OP(dev_fdio, fchdir); \ |
69 OP(dev_fdio, fchmod); \ | 68 OP(dev_fdio, fchmod); \ |
70 OP(dev_fdio, fsync); \ | 69 OP(dev_fdio, fsync); \ |
71 OP(dev_fdio, fdatasync); \ | 70 OP(dev_fdio, fdatasync); \ |
72 OP(dev_fdio, ftruncate); \ | 71 OP(dev_fdio, ftruncate); \ |
73 OP(dev_fdio, isatty); \ | 72 OP(dev_fdio, isatty); \ |
74 OP(dev_filename, open); \ | 73 OP(dev_filename, open); \ |
75 OP(dev_filename, stat); \ | 74 OP(dev_filename, stat); \ |
76 OP(dev_filename, mkdir); \ | 75 OP(dev_filename, mkdir); \ |
77 OP(dev_filename, rmdir); \ | 76 OP(dev_filename, rmdir); \ |
78 OP(dev_filename, chdir); \ | 77 OP(dev_filename, chdir); \ |
79 OP(dev_filename, getcwd); \ | 78 OP(dev_filename, getcwd); \ |
80 OP(dev_filename, unlink); \ | 79 OP(dev_filename, unlink); \ |
81 OP(dev_filename, truncate); \ | 80 OP(dev_filename, truncate); \ |
82 OP(dev_filename, lstat); \ | 81 OP(dev_filename, lstat); \ |
83 OP(dev_filename, link); \ | 82 OP(dev_filename, link); \ |
84 OP(dev_filename, rename); \ | 83 OP(dev_filename, rename); \ |
85 OP(dev_filename, symlink); \ | 84 OP(dev_filename, symlink); \ |
86 OP(dev_filename, chmod); \ | 85 OP(dev_filename, chmod); \ |
87 OP(dev_filename, access); \ | 86 OP(dev_filename, access); \ |
88 OP(dev_filename, readlink); \ | 87 OP(dev_filename, readlink); \ |
89 OP(dev_filename, utimes); \ | 88 OP(dev_filename, utimes); \ |
90 OP(memory, mmap); \ | 89 OP(memory, mmap); \ |
91 OP(memory, munmap); | 90 OP(memory, munmap); |
92 | 91 |
93 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); | 92 EXPAND_SYMBOL_LIST_OPERATION(DECLARE_REAL_PTR); |
94 | 93 |
95 int WRAP(close)(int fd) { | 94 int WRAP(close)(int fd) { |
96 ERRNO_RTN(ki_close(fd)); | 95 ERRNO_RTN(ki_close(fd)); |
97 } | 96 } |
98 | 97 |
99 int WRAP(dup)(int fd, int* newfd) { | 98 int WRAP(dup)(int fd, int* newfd) { |
100 *newfd = ki_dup(fd); | 99 *newfd = ki_dup(fd); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 int WRAP(ftruncate)(int fd, off_t length) { | 156 int WRAP(ftruncate)(int fd, off_t length) { |
158 ERRNO_RTN(ki_ftruncate(fd, length)); | 157 ERRNO_RTN(ki_ftruncate(fd, length)); |
159 } | 158 } |
160 | 159 |
161 int WRAP(isatty)(int fd, int* result) { | 160 int WRAP(isatty)(int fd, int* result) { |
162 *result = ki_isatty(fd); | 161 *result = ki_isatty(fd); |
163 RTN_ERRNO_IF(*result == 0); | 162 RTN_ERRNO_IF(*result == 0); |
164 return 0; | 163 return 0; |
165 } | 164 } |
166 | 165 |
167 int WRAP(mmap)(void** addr, size_t length, int prot, int flags, int fd, | 166 int WRAP(mmap)(void** addr, |
| 167 size_t length, |
| 168 int prot, |
| 169 int flags, |
| 170 int fd, |
168 off_t offset) { | 171 off_t offset) { |
169 if (flags & MAP_ANONYMOUS) | 172 if (flags & MAP_ANONYMOUS) |
170 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 173 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
171 | 174 |
172 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); | 175 *addr = ki_mmap(*addr, length, prot, flags, fd, offset); |
173 RTN_ERRNO_IF(*addr == (void*)-1); | 176 RTN_ERRNO_IF(*addr == (void*)-1); |
174 return 0; | 177 return 0; |
175 } | 178 } |
176 | 179 |
177 int WRAP(munmap)(void* addr, size_t length) { | 180 int WRAP(munmap)(void* addr, size_t length) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 236 } |
234 | 237 |
235 int WRAP(chmod)(const char* pathname, mode_t mode) { | 238 int WRAP(chmod)(const char* pathname, mode_t mode) { |
236 ERRNO_RTN(ki_chmod(pathname, mode)); | 239 ERRNO_RTN(ki_chmod(pathname, mode)); |
237 } | 240 } |
238 | 241 |
239 int WRAP(access)(const char* pathname, int amode) { | 242 int WRAP(access)(const char* pathname, int amode) { |
240 ERRNO_RTN(ki_access(pathname, amode)); | 243 ERRNO_RTN(ki_access(pathname, amode)); |
241 } | 244 } |
242 | 245 |
243 int WRAP(readlink)(const char* pathname, char *buf, | 246 int WRAP(readlink)(const char* pathname, |
244 size_t count, size_t *nread) { | 247 char* buf, |
| 248 size_t count, |
| 249 size_t* nread) { |
245 int rtn = ki_readlink(pathname, buf, count); | 250 int rtn = ki_readlink(pathname, buf, count); |
246 RTN_ERRNO_IF(rtn < 0); | 251 RTN_ERRNO_IF(rtn < 0); |
247 *nread = rtn; | 252 *nread = rtn; |
248 return 0; | 253 return 0; |
249 } | 254 } |
250 | 255 |
251 int WRAP(utimes)(const char* pathname, const struct timeval times[2]) { | 256 int WRAP(utimes)(const char* pathname, const struct timeval times[2]) { |
252 ERRNO_RTN(ki_utimes(pathname, times)); | 257 ERRNO_RTN(ki_utimes(pathname, times)); |
253 } | 258 } |
254 | 259 |
255 static void assign_real_pointers() { | 260 static void assign_real_pointers() { |
256 static bool assigned = false; | 261 static bool assigned = false; |
257 if (!assigned) { | 262 if (!assigned) { |
258 __libnacl_irt_dev_filename_init(); | 263 __libnacl_irt_dev_filename_init(); |
259 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 264 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
260 assigned = true; | 265 assigned = true; |
261 } | 266 } |
262 } | 267 } |
263 | 268 |
264 #define CHECK_REAL(func) \ | 269 #define CHECK_REAL(func) \ |
265 if (!REAL(func)) \ | 270 if (!REAL(func)) \ |
266 assign_real_pointers(); | 271 assign_real_pointers(); |
267 | 272 |
268 // "real" functions, i.e. the unwrapped original functions. | 273 // "real" functions, i.e. the unwrapped original functions. |
269 | 274 |
270 int _real_close(int fd) { | 275 int _real_close(int fd) { |
271 CHECK_REAL(close); | 276 CHECK_REAL(close); |
272 return REAL(close)(fd); | 277 return REAL(close)(fd); |
273 } | 278 } |
274 | 279 |
275 void _real_exit(int status) { | 280 void _real_exit(int status) { |
(...skipping 18 matching lines...) Expand all Loading... |
294 | 299 |
295 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { | 300 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { |
296 CHECK_REAL(seek); | 301 CHECK_REAL(seek); |
297 return REAL(seek)(fd, offset, whence, new_offset); | 302 return REAL(seek)(fd, offset, whence, new_offset); |
298 } | 303 } |
299 | 304 |
300 int _real_mkdir(const char* pathname, mode_t mode) { | 305 int _real_mkdir(const char* pathname, mode_t mode) { |
301 return ENOSYS; | 306 return ENOSYS; |
302 } | 307 } |
303 | 308 |
304 int _real_mmap(void** addr, size_t length, int prot, int flags, int fd, | 309 int _real_mmap(void** addr, |
| 310 size_t length, |
| 311 int prot, |
| 312 int flags, |
| 313 int fd, |
305 off_t offset) { | 314 off_t offset) { |
306 CHECK_REAL(mmap); | 315 CHECK_REAL(mmap); |
307 return REAL(mmap)(addr, length, prot, flags, fd, offset); | 316 return REAL(mmap)(addr, length, prot, flags, fd, offset); |
308 } | 317 } |
309 | 318 |
310 int _real_munmap(void* addr, size_t length) { | 319 int _real_munmap(void* addr, size_t length) { |
311 CHECK_REAL(munmap); | 320 CHECK_REAL(munmap); |
312 return REAL(munmap)(addr, length); | 321 return REAL(munmap)(addr, length); |
313 } | 322 } |
314 | 323 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 if (s_wrapped) { | 359 if (s_wrapped) { |
351 LOG_TRACE("kernel_wrap_uninit"); | 360 LOG_TRACE("kernel_wrap_uninit"); |
352 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 361 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
353 s_wrapped = false; | 362 s_wrapped = false; |
354 } | 363 } |
355 } | 364 } |
356 | 365 |
357 EXTERN_C_END | 366 EXTERN_C_END |
358 | 367 |
359 #endif // defined(__native_client__) && !defined(__GLIBC__) ... | 368 #endif // defined(__native_client__) && !defined(__GLIBC__) ... |
OLD | NEW |