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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 static bool assigned = false; | 262 static bool assigned = false; |
263 if (!assigned) { | 263 if (!assigned) { |
264 __libnacl_irt_dev_filename_init(); | 264 __libnacl_irt_dev_filename_init(); |
265 __libnacl_irt_dev_fdio_init(); | 265 __libnacl_irt_dev_fdio_init(); |
266 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 266 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
267 assigned = true; | 267 assigned = true; |
268 } | 268 } |
269 } | 269 } |
270 | 270 |
271 #define CHECK_REAL(func) \ | 271 #define CHECK_REAL(func) \ |
272 if (!REAL(func)) \ | 272 if (!REAL(func)) { \ |
273 assign_real_pointers(); | 273 assign_real_pointers(); \ |
274 | 274 if (!REAL(func)) \ |
275 #define CHECK_REAL_NOSYS(func) \ | 275 return ENOSYS; \ |
276 CHECK_REAL(func) \ | 276 } |
277 if (!REAL(func)) \ | |
278 return ENOSYS; | |
279 | 277 |
280 // "real" functions, i.e. the unwrapped original functions. | 278 // "real" functions, i.e. the unwrapped original functions. |
281 | 279 |
282 int _real_close(int fd) { | 280 int _real_close(int fd) { |
283 CHECK_REAL(close); | 281 CHECK_REAL(close); |
284 return REAL(close)(fd); | 282 return REAL(close)(fd); |
285 } | 283 } |
286 | 284 |
287 void _real_exit(int status) { | 285 void _real_exit(int status) { |
288 CHECK_REAL(exit); | 286 if (!REAL(exit)) |
| 287 assign_real_pointers(); |
289 REAL(exit)(status); | 288 REAL(exit)(status); |
290 } | 289 } |
291 | 290 |
292 int _real_fstat(int fd, struct stat* buf) { | 291 int _real_fstat(int fd, struct stat* buf) { |
293 CHECK_REAL(fstat); | 292 CHECK_REAL(fstat); |
294 return REAL(fstat)(fd, buf); | 293 return REAL(fstat)(fd, buf); |
295 } | 294 } |
296 | 295 |
297 int _real_isatty(int fd, int* result) { | 296 int _real_isatty(int fd, int* result) { |
298 CHECK_REAL(isatty); | 297 CHECK_REAL(isatty); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 CHECK_REAL(rmdir); | 352 CHECK_REAL(rmdir); |
354 return REAL(rmdir)(pathname); | 353 return REAL(rmdir)(pathname); |
355 } | 354 } |
356 | 355 |
357 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { | 356 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
358 CHECK_REAL(write); | 357 CHECK_REAL(write); |
359 return REAL(write)(fd, buf, count, nwrote); | 358 return REAL(write)(fd, buf, count, nwrote); |
360 } | 359 } |
361 | 360 |
362 int _real_getcwd(char* pathname, size_t len) { | 361 int _real_getcwd(char* pathname, size_t len) { |
363 CHECK_REAL_NOSYS(getcwd); | 362 CHECK_REAL(getcwd); |
364 return REAL(getcwd)(pathname, len); | 363 return REAL(getcwd)(pathname, len); |
365 } | 364 } |
366 | 365 |
367 static bool s_wrapped = false; | 366 static bool s_wrapped = false; |
368 | 367 |
369 void kernel_wrap_init() { | 368 void kernel_wrap_init() { |
370 if (!s_wrapped) { | 369 if (!s_wrapped) { |
371 LOG_TRACE("kernel_wrap_init"); | 370 LOG_TRACE("kernel_wrap_init"); |
372 assign_real_pointers(); | 371 assign_real_pointers(); |
373 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 372 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
374 s_wrapped = true; | 373 s_wrapped = true; |
375 } | 374 } |
376 } | 375 } |
377 | 376 |
378 void kernel_wrap_uninit() { | 377 void kernel_wrap_uninit() { |
379 if (s_wrapped) { | 378 if (s_wrapped) { |
380 LOG_TRACE("kernel_wrap_uninit"); | 379 LOG_TRACE("kernel_wrap_uninit"); |
381 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 380 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
382 s_wrapped = false; | 381 s_wrapped = false; |
383 } | 382 } |
384 } | 383 } |
385 | 384 |
386 EXTERN_C_END | 385 EXTERN_C_END |
387 | 386 |
388 #endif // defined(__native_client__) && !defined(__GLIBC__) ... | 387 #endif // defined(__native_client__) && !defined(__GLIBC__) ... |
OLD | NEW |