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 #include "nacl_io/kernel_wrap.h" // IRT_EXT is turned on in this header. | 6 #include "nacl_io/kernel_wrap.h" // IRT_EXT is turned on in this header. |
7 | 7 |
8 #if !defined(NACL_IO_IRT_EXT) && defined(__native_client__) && \ | 8 #if !defined(NACL_IO_IRT_EXT) && defined(__native_client__) && \ |
9 defined(__GLIBC__) | 9 defined(__GLIBC__) |
10 | 10 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 int err = REAL(fstat)(fd, &st); | 525 int err = REAL(fstat)(fd, &st); |
526 if (err) { | 526 if (err) { |
527 errno = err; | 527 errno = err; |
528 return -1; | 528 return -1; |
529 } | 529 } |
530 | 530 |
531 nacl_stat_to_stat(&st, buf); | 531 nacl_stat_to_stat(&st, buf); |
532 return 0; | 532 return 0; |
533 } | 533 } |
534 | 534 |
535 int _real_getdents(int fd, void* buf, size_t count, size_t* nread) { | 535 int _real_getdents(int fd, struct dirent* buf, size_t count, size_t* nread) { |
536 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). | 536 // "buf" contains dirent(s); "nacl_buf" contains nacl_abi_dirent(s). |
537 // See WRAP(getdents) above. | 537 // See WRAP(getdents) above. |
| 538 |
538 char* nacl_buf = (char*)alloca(count); | 539 char* nacl_buf = (char*)alloca(count); |
539 size_t offset = 0; | 540 size_t offset = 0; |
540 size_t nacl_offset = 0; | 541 size_t nacl_offset = 0; |
541 size_t nacl_nread; | 542 size_t nacl_nread; |
542 CHECK_REAL(getdents); | 543 CHECK_REAL(getdents); |
543 int err = REAL(getdents)(fd, (dirent*)nacl_buf, count, &nacl_nread); | 544 int err = REAL(getdents)(fd, (struct dirent*)nacl_buf, count, &nacl_nread); |
544 if (err) | 545 if (err) |
545 return err; | 546 return err; |
546 | 547 |
547 while (nacl_offset < nacl_nread) { | 548 while (nacl_offset < nacl_nread) { |
548 dirent* d = (dirent*)((char*)buf + offset); | 549 dirent* d = (dirent*)((char*)buf + offset); |
549 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset); | 550 nacl_abi_dirent* nacl_d = (nacl_abi_dirent*)(nacl_buf + nacl_offset); |
550 d->d_ino = nacl_d->nacl_abi_d_ino; | 551 d->d_ino = nacl_d->nacl_abi_d_ino; |
551 d->d_off = nacl_d->nacl_abi_d_off; | 552 d->d_off = nacl_d->nacl_abi_d_off; |
552 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift; | 553 d->d_reclen = nacl_d->nacl_abi_d_reclen + d_name_shift; |
553 size_t d_name_len = | 554 size_t name_len = |
554 nacl_d->nacl_abi_d_reclen - offsetof(nacl_abi_dirent, nacl_abi_d_name); | 555 nacl_d->nacl_abi_d_reclen - offsetof(nacl_abi_dirent, nacl_abi_d_name); |
555 memcpy(d->d_name, nacl_d->nacl_abi_d_name, d_name_len); | 556 memcpy(d->d_name, nacl_d->nacl_abi_d_name, name_len); |
556 | 557 |
557 offset += d->d_reclen; | 558 offset += d->d_reclen; |
558 offset += nacl_d->nacl_abi_d_reclen; | 559 nacl_offset += nacl_d->nacl_abi_d_reclen; |
559 } | 560 } |
560 | 561 |
561 *nread = offset; | 562 *nread = offset; |
562 return 0; | 563 return 0; |
563 } | 564 } |
564 | 565 |
565 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { | 566 int _real_lseek(int fd, off_t offset, int whence, off_t* new_offset) { |
566 CHECK_REAL(seek); | 567 CHECK_REAL(seek); |
567 return REAL(seek)(fd, offset, whence, new_offset); | 568 return REAL(seek)(fd, offset, whence, new_offset); |
568 } | 569 } |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 if (s_wrapped) { | 632 if (s_wrapped) { |
632 LOG_TRACE("kernel_wrap_uninit"); | 633 LOG_TRACE("kernel_wrap_uninit"); |
633 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) | 634 EXPAND_SYMBOL_LIST_OPERATION(USE_REAL) |
634 s_wrapped = false; | 635 s_wrapped = false; |
635 } | 636 } |
636 } | 637 } |
637 | 638 |
638 EXTERN_C_END | 639 EXTERN_C_END |
639 | 640 |
640 #endif // defined(__native_client__) && defined(__GLIBC__) | 641 #endif // defined(__native_client__) && defined(__GLIBC__) |
OLD | NEW |