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 __BIONIC__. | 5 #include <sys/types.h> // Include something that will define __BIONIC__. |
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-bionic build. | 8 // compiled, even on a non-bionic build. |
9 | 9 |
10 #if defined(__native_client__) && defined(__BIONIC__) | 10 #if defined(__native_client__) && defined(__BIONIC__) |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 static void assign_real_pointers() { | 332 static void assign_real_pointers() { |
333 static bool assigned = false; | 333 static bool assigned = false; |
334 if (!assigned) { | 334 if (!assigned) { |
335 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 335 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
336 assigned = true; | 336 assigned = true; |
337 } | 337 } |
338 } | 338 } |
339 | 339 |
340 #define CHECK_REAL(func) \ | 340 #define CHECK_REAL(func) \ |
341 if (!REAL(func)) \ | 341 if (!REAL(func)) { \ |
342 assign_real_pointers(); | 342 assign_real_pointers(); \ |
343 | 343 if (!REAL(func)) \ |
344 #define CHECK_REAL_NOSYS(func) \ | 344 return ENOSYS; \ |
345 CHECK_REAL(func) \ | 345 } |
346 if (!REAL(func)) \ | |
347 return ENOSYS; | |
348 | 346 |
349 // "real" functions, i.e. the unwrapped original functions. | 347 // "real" functions, i.e. the unwrapped original functions. |
350 | 348 |
351 int _real_close(int fd) { | 349 int _real_close(int fd) { |
352 CHECK_REAL(close); | 350 CHECK_REAL(close); |
353 return REAL(close)(fd); | 351 return REAL(close)(fd); |
354 } | 352 } |
355 | 353 |
356 void _real_exit(int status) { | 354 void _real_exit(int status) { |
357 REAL(exit)(status); | 355 REAL(exit)(status); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { | 427 int _real_lseek(int fd, int64_t offset, int whence, int64_t* new_offset) { |
430 CHECK_REAL(seek); | 428 CHECK_REAL(seek); |
431 nacl_abi_off_t nacl_new_offs; | 429 nacl_abi_off_t nacl_new_offs; |
432 int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); | 430 int ret = REAL(seek)(fd, offset, whence, &nacl_new_offs); |
433 *new_offset = static_cast<off_t>(nacl_new_offs); | 431 *new_offset = static_cast<off_t>(nacl_new_offs); |
434 return ret; | 432 return ret; |
435 } | 433 } |
436 | 434 |
437 int _real_lstat(const char* path, struct stat* buf) { | 435 int _real_lstat(const char* path, struct stat* buf) { |
438 struct nacl_abi_stat st; | 436 struct nacl_abi_stat st; |
439 CHECK_REAL(fstat); | 437 CHECK_REAL(lstat); |
440 | 438 |
441 int err = REAL(lstat)(path, (struct stat*)&st); | 439 int err = REAL(lstat)(path, (struct stat*)&st); |
442 if (err) { | 440 if (err) { |
443 errno = err; | 441 errno = err; |
444 return -1; | 442 return -1; |
445 } | 443 } |
446 | 444 |
447 nacl_stat_to_stat(&st, buf); | 445 nacl_stat_to_stat(&st, buf); |
448 return 0; | 446 return 0; |
449 } | 447 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
497 CHECK_REAL(truncate); | 495 CHECK_REAL(truncate); |
498 return REAL(truncate)(pathname, len); | 496 return REAL(truncate)(pathname, len); |
499 } | 497 } |
500 | 498 |
501 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { | 499 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
502 CHECK_REAL(write); | 500 CHECK_REAL(write); |
503 return REAL(write)(fd, buf, count, nwrote); | 501 return REAL(write)(fd, buf, count, nwrote); |
504 } | 502 } |
505 | 503 |
506 int _real_getcwd(char* pathname, size_t len) { | 504 int _real_getcwd(char* pathname, size_t len) { |
507 CHECK_REAL_NOSYS(getcwd); | 505 CHECK_REAL(getcwd); |
508 return REAL(getcwd)(pathname, len); | 506 return REAL(getcwd)(pathname, len); |
509 } | 507 } |
510 | 508 |
511 static bool s_wrapped = false; | 509 static bool s_wrapped = false; |
512 | 510 |
513 void kernel_wrap_init() { | 511 void kernel_wrap_init() { |
514 if (!s_wrapped) { | 512 if (!s_wrapped) { |
515 assign_real_pointers(); | 513 assign_real_pointers(); |
516 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 514 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
517 s_wrapped = true; | 515 s_wrapped = true; |
518 } | 516 } |
519 } | 517 } |
520 | 518 |
521 void kernel_wrap_uninit() { | 519 void kernel_wrap_uninit() { |
522 if (s_wrapped) { | 520 if (s_wrapped) { |
523 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 521 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
524 s_wrapped = false; | 522 s_wrapped = false; |
525 } | 523 } |
526 } | 524 } |
527 | 525 |
528 EXTERN_C_END | 526 EXTERN_C_END |
529 | 527 |
530 #endif // defined(__native_client__) && defined(__BIONIC__) | 528 #endif // defined(__native_client__) && defined(__BIONIC__) |
OLD | NEW |