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-glibc build. | 8 // compiled, even on a non-glibc build. |
9 #if defined(__native_client__) && defined(__GLIBC__) | 9 #if defined(__native_client__) && defined(__GLIBC__) |
10 | 10 |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 } | 517 } |
518 | 518 |
519 static void assign_real_pointers() { | 519 static void assign_real_pointers() { |
520 static bool assigned = false; | 520 static bool assigned = false; |
521 if (!assigned) { | 521 if (!assigned) { |
522 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 522 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
523 assigned = true; | 523 assigned = true; |
524 } | 524 } |
525 } | 525 } |
526 | 526 |
527 #define CHECK_REAL(func) \ | 527 #define CHECK_REAL(func) \ |
528 if (!REAL(func)) \ | 528 if (!REAL(func)) { \ |
529 assign_real_pointers(); | 529 assign_real_pointers(); \ |
530 | 530 if (!REAL(func)) \ |
531 #define CHECK_REAL_NOSYS(func) \ | 531 return ENOSYS; \ |
532 CHECK_REAL(func) \ | 532 } |
533 if (!REAL(func)) \ | |
534 return ENOSYS; | |
535 | 533 |
536 // "real" functions, i.e. the unwrapped original functions. | 534 // "real" functions, i.e. the unwrapped original functions. |
537 | 535 |
538 int _real_close(int fd) { | 536 int _real_close(int fd) { |
539 CHECK_REAL(close); | 537 CHECK_REAL(close); |
540 return REAL(close)(fd); | 538 return REAL(close)(fd); |
541 } | 539 } |
542 | 540 |
543 void _real_exit(int status) { | 541 void _real_exit(int status) { |
544 CHECK_REAL(exit); | 542 if (!REAL(exit)) |
| 543 assign_real_pointers(); |
545 REAL(exit)(status); | 544 REAL(exit)(status); |
546 } | 545 } |
547 | 546 |
548 int _real_fstat(int fd, struct stat* buf) { | 547 int _real_fstat(int fd, struct stat* buf) { |
549 struct nacl_abi_stat st; | 548 struct nacl_abi_stat st; |
550 CHECK_REAL(fstat); | 549 CHECK_REAL(fstat); |
551 int err = REAL(fstat)(fd, &st); | 550 int err = REAL(fstat)(fd, &st); |
552 if (err) { | 551 if (err) { |
553 errno = err; | 552 errno = err; |
554 return -1; | 553 return -1; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
632 CHECK_REAL(rmdir); | 631 CHECK_REAL(rmdir); |
633 return REAL(rmdir)(pathname); | 632 return REAL(rmdir)(pathname); |
634 } | 633 } |
635 | 634 |
636 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { | 635 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
637 CHECK_REAL(write); | 636 CHECK_REAL(write); |
638 return REAL(write)(fd, buf, count, nwrote); | 637 return REAL(write)(fd, buf, count, nwrote); |
639 } | 638 } |
640 | 639 |
641 int _real_getcwd(char* pathname, size_t len) { | 640 int _real_getcwd(char* pathname, size_t len) { |
642 CHECK_REAL_NOSYS(getcwd); | 641 CHECK_REAL(getcwd); |
643 return REAL(getcwd)(pathname, len); | 642 return REAL(getcwd)(pathname, len); |
644 } | 643 } |
645 | 644 |
646 static bool s_wrapped = false; | 645 static bool s_wrapped = false; |
647 void kernel_wrap_init() { | 646 void kernel_wrap_init() { |
648 if (!s_wrapped) { | 647 if (!s_wrapped) { |
649 LOG_TRACE("kernel_wrap_init"); | 648 LOG_TRACE("kernel_wrap_init"); |
650 assign_real_pointers(); | 649 assign_real_pointers(); |
651 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 650 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
652 s_wrapped = true; | 651 s_wrapped = true; |
653 } | 652 } |
654 } | 653 } |
655 | 654 |
656 void kernel_wrap_uninit() { | 655 void kernel_wrap_uninit() { |
657 if (s_wrapped) { | 656 if (s_wrapped) { |
658 LOG_TRACE("kernel_wrap_uninit"); | 657 LOG_TRACE("kernel_wrap_uninit"); |
659 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 658 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
660 s_wrapped = false; | 659 s_wrapped = false; |
661 } | 660 } |
662 } | 661 } |
663 | 662 |
664 EXTERN_C_END | 663 EXTERN_C_END |
665 | 664 |
666 #endif // defined(__native_client__) && defined(__GLIBC__) | 665 #endif // defined(__native_client__) && defined(__GLIBC__) |
OLD | NEW |