| 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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 OP(recv); \ | 152 OP(recv); \ |
| 153 OP(recvmsg); \ | 153 OP(recvmsg); \ |
| 154 OP(recvfrom); \ | 154 OP(recvfrom); \ |
| 155 OP(getpeername); \ | 155 OP(getpeername); \ |
| 156 OP(getsockname); \ | 156 OP(getsockname); \ |
| 157 OP(getsockopt); \ | 157 OP(getsockopt); \ |
| 158 OP(setsockopt); \ | 158 OP(setsockopt); \ |
| 159 OP(socketpair); \ | 159 OP(socketpair); \ |
| 160 OP(shutdown); \ | 160 OP(shutdown); \ |
| 161 \ | 161 \ |
| 162 OP(chmod); \ |
| 162 OP(access); \ | 163 OP(access); \ |
| 163 OP(unlink); \ | 164 OP(unlink); \ |
| 164 OP(fchdir); \ | 165 OP(fchdir); \ |
| 165 OP(fchmod); \ | 166 OP(fchmod); \ |
| 166 OP(fsync); \ | 167 OP(fsync); \ |
| 167 OP(fdatasync); \ | 168 OP(fdatasync); \ |
| 168 OP(lstat); \ | 169 OP(lstat); \ |
| 170 OP(link); \ |
| 169 OP(readlink); \ | 171 OP(readlink); \ |
| 170 OP(utimes); | 172 OP(utimes); |
| 171 | 173 |
| 172 // TODO(bradnelson): Add these as well. | 174 // TODO(bradnelson): Add these as well. |
| 173 // OP(epoll_create); | 175 // OP(epoll_create); |
| 174 // OP(epoll_create1); | 176 // OP(epoll_create1); |
| 175 // OP(epoll_ctl); | 177 // OP(epoll_ctl); |
| 176 // OP(epoll_pwait); | 178 // OP(epoll_pwait); |
| 177 // OP(ppoll); | 179 // OP(ppoll); |
| 178 // OP(pselect); | 180 // OP(pselect); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 | 330 |
| 329 int WRAP(lstat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { | 331 int WRAP(lstat)(const char* pathname, struct nacl_abi_stat* nacl_buf) { |
| 330 struct stat buf; | 332 struct stat buf; |
| 331 memset(&buf, 0, sizeof(struct stat)); | 333 memset(&buf, 0, sizeof(struct stat)); |
| 332 int res = ki_lstat(pathname, &buf); | 334 int res = ki_lstat(pathname, &buf); |
| 333 RTN_ERRNO_IF(res < 0); | 335 RTN_ERRNO_IF(res < 0); |
| 334 stat_to_nacl_stat(&buf, nacl_buf); | 336 stat_to_nacl_stat(&buf, nacl_buf); |
| 335 return 0; | 337 return 0; |
| 336 } | 338 } |
| 337 | 339 |
| 340 int WRAP(link)(const char* pathname, const char* newpath) { |
| 341 ERRNO_RTN(ki_link(pathname, newpath)); |
| 342 } |
| 343 |
| 338 int WRAP(readlink)(const char* pathname, | 344 int WRAP(readlink)(const char* pathname, |
| 339 char* buf, | 345 char* buf, |
| 340 size_t count, | 346 size_t count, |
| 341 size_t* nread) { | 347 size_t* nread) { |
| 342 int rtn = ki_readlink(pathname, buf, count); | 348 int rtn = ki_readlink(pathname, buf, count); |
| 343 RTN_ERRNO_IF(rtn < 0); | 349 RTN_ERRNO_IF(rtn < 0); |
| 344 *nread = rtn; | 350 *nread = rtn; |
| 345 return 0; | 351 return 0; |
| 346 } | 352 } |
| 347 | 353 |
| 348 int WRAP(utimes)(const char *filename, const struct timeval *times) { | 354 int WRAP(utimes)(const char *filename, const struct timeval *times) { |
| 349 ERRNO_RTN(ki_utimes(filename, times)); | 355 ERRNO_RTN(ki_utimes(filename, times)); |
| 350 } | 356 } |
| 351 | 357 |
| 358 int WRAP(chmod)(const char* pathname, mode_t mode) { |
| 359 ERRNO_RTN(ki_chmod(pathname, mode)); |
| 360 } |
| 361 |
| 352 int WRAP(access)(const char* pathname, int amode) { | 362 int WRAP(access)(const char* pathname, int amode) { |
| 353 ERRNO_RTN(ki_access(pathname, amode)); | 363 ERRNO_RTN(ki_access(pathname, amode)); |
| 354 } | 364 } |
| 355 | 365 |
| 356 int WRAP(unlink)(const char* pathname) { | 366 int WRAP(unlink)(const char* pathname) { |
| 357 ERRNO_RTN(ki_unlink(pathname)); | 367 ERRNO_RTN(ki_unlink(pathname)); |
| 358 } | 368 } |
| 359 | 369 |
| 360 int WRAP(fchdir)(int fd) { | 370 int WRAP(fchdir)(int fd) { |
| 361 ERRNO_RTN(ki_fchdir(fd)); | 371 ERRNO_RTN(ki_fchdir(fd)); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 if (!assigned) { | 514 if (!assigned) { |
| 505 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) | 515 EXPAND_SYMBOL_LIST_OPERATION(ASSIGN_REAL_PTR) |
| 506 assigned = true; | 516 assigned = true; |
| 507 } | 517 } |
| 508 } | 518 } |
| 509 | 519 |
| 510 #define CHECK_REAL(func) \ | 520 #define CHECK_REAL(func) \ |
| 511 if (!REAL(func)) \ | 521 if (!REAL(func)) \ |
| 512 assign_real_pointers(); | 522 assign_real_pointers(); |
| 513 | 523 |
| 524 #define CHECK_REAL_NOSYS(func) \ |
| 525 CHECK_REAL(func) \ |
| 526 if (!REAL(func)) \ |
| 527 return ENOSYS; |
| 528 |
| 514 // "real" functions, i.e. the unwrapped original functions. | 529 // "real" functions, i.e. the unwrapped original functions. |
| 515 | 530 |
| 516 int _real_close(int fd) { | 531 int _real_close(int fd) { |
| 517 CHECK_REAL(close); | 532 CHECK_REAL(close); |
| 518 return REAL(close)(fd); | 533 return REAL(close)(fd); |
| 519 } | 534 } |
| 520 | 535 |
| 521 void _real_exit(int status) { | 536 void _real_exit(int status) { |
| 522 CHECK_REAL(exit); | 537 CHECK_REAL(exit); |
| 523 REAL(exit)(status); | 538 REAL(exit)(status); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 int _real_rmdir(const char* pathname) { | 624 int _real_rmdir(const char* pathname) { |
| 610 CHECK_REAL(rmdir); | 625 CHECK_REAL(rmdir); |
| 611 return REAL(rmdir)(pathname); | 626 return REAL(rmdir)(pathname); |
| 612 } | 627 } |
| 613 | 628 |
| 614 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { | 629 int _real_write(int fd, const void* buf, size_t count, size_t* nwrote) { |
| 615 CHECK_REAL(write); | 630 CHECK_REAL(write); |
| 616 return REAL(write)(fd, buf, count, nwrote); | 631 return REAL(write)(fd, buf, count, nwrote); |
| 617 } | 632 } |
| 618 | 633 |
| 634 int _real_getcwd(char* pathname, size_t len) { |
| 635 CHECK_REAL_NOSYS(getcwd); |
| 636 return REAL(getcwd)(pathname, len); |
| 637 } |
| 638 |
| 619 static bool s_wrapped = false; | 639 static bool s_wrapped = false; |
| 620 void kernel_wrap_init() { | 640 void kernel_wrap_init() { |
| 621 if (!s_wrapped) { | 641 if (!s_wrapped) { |
| 622 LOG_TRACE("kernel_wrap_init"); | 642 LOG_TRACE("kernel_wrap_init"); |
| 623 assign_real_pointers(); | 643 assign_real_pointers(); |
| 624 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) | 644 EXPAND_SYMBOL_LIST_OPERATION(USE_WRAP) |
| 625 s_wrapped = true; | 645 s_wrapped = true; |
| 626 } | 646 } |
| 627 } | 647 } |
| 628 | 648 |
| 629 void kernel_wrap_uninit() { | 649 void kernel_wrap_uninit() { |
| 630 if (s_wrapped) { | 650 if (s_wrapped) { |
| 631 LOG_TRACE("kernel_wrap_uninit"); | 651 LOG_TRACE("kernel_wrap_uninit"); |
| 632 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 652 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
| 633 s_wrapped = false; | 653 s_wrapped = false; |
| 634 } | 654 } |
| 635 } | 655 } |
| 636 | 656 |
| 637 EXTERN_C_END | 657 EXTERN_C_END |
| 638 | 658 |
| 639 #endif // defined(__native_client__) && defined(__GLIBC__) | 659 #endif // defined(__native_client__) && defined(__GLIBC__) |
| OLD | NEW |