Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/file.h" | 8 #include "bin/file.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| 11 #include <fcntl.h> // NOLINT | 11 #include <fcntl.h> // NOLINT |
| 12 #include <sys/stat.h> // NOLINT | 12 #include <sys/stat.h> // NOLINT |
| 13 #include <sys/types.h> // NOLINT | 13 #include <sys/types.h> // NOLINT |
| 14 #include <sys/sendfile.h> // NOLINT | 14 #include <sys/sendfile.h> // NOLINT |
| 15 #include <unistd.h> // NOLINT | 15 #include <unistd.h> // NOLINT |
| 16 #include <libgen.h> // NOLINT | 16 #include <libgen.h> // NOLINT |
| 17 | 17 |
| 18 #include "bin/builtin.h" | 18 #include "bin/builtin.h" |
| 19 #include "bin/log.h" | 19 #include "bin/log.h" |
| 20 #include "bin/signal_blocker.h" | |
| 20 | 21 |
| 21 | 22 |
| 22 namespace dart { | 23 namespace dart { |
| 23 namespace bin { | 24 namespace bin { |
| 24 | 25 |
| 25 class FileHandle { | 26 class FileHandle { |
| 26 public: | 27 public: |
| 27 explicit FileHandle(int fd) : fd_(fd) { } | 28 explicit FileHandle(int fd) : fd_(fd) { } |
| 28 ~FileHandle() { } | 29 ~FileHandle() { } |
| 29 int fd() const { return fd_; } | 30 int fd() const { return fd_; } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 58 } | 59 } |
| 59 | 60 |
| 60 | 61 |
| 61 bool File::IsClosed() { | 62 bool File::IsClosed() { |
| 62 return handle_->fd() == kClosedFd; | 63 return handle_->fd() == kClosedFd; |
| 63 } | 64 } |
| 64 | 65 |
| 65 | 66 |
| 66 int64_t File::Read(void* buffer, int64_t num_bytes) { | 67 int64_t File::Read(void* buffer, int64_t num_bytes) { |
| 67 ASSERT(handle_->fd() >= 0); | 68 ASSERT(handle_->fd() >= 0); |
| 69 // Block profile interrupts while making I/O call. | |
| 70 ThreadSignalBlocker tsb(SIGPROF); | |
| 68 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 71 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
|
siva
2013/12/13 21:29:14
We should consider moving this blocking stuff into
Cutch
2013/12/13 22:40:18
Not sure how to do that. For now I'm going with Th
| |
| 69 } | 72 } |
| 70 | 73 |
| 71 | 74 |
| 72 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 75 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
| 73 ASSERT(handle_->fd() >= 0); | 76 ASSERT(handle_->fd() >= 0); |
| 77 // Block profile interrupts while making I/O call. | |
| 78 ThreadSignalBlocker tsb(SIGPROF); | |
| 74 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); | 79 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
| 75 } | 80 } |
| 76 | 81 |
| 77 | 82 |
| 78 off64_t File::Position() { | 83 off64_t File::Position() { |
| 79 ASSERT(handle_->fd() >= 0); | 84 ASSERT(handle_->fd() >= 0); |
| 80 return lseek64(handle_->fd(), 0, SEEK_CUR); | 85 return lseek64(handle_->fd(), 0, SEEK_CUR); |
| 81 } | 86 } |
| 82 | 87 |
| 83 | 88 |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 off64_t offset = 0; | 245 off64_t offset = 0; |
| 241 int result = 1; | 246 int result = 1; |
| 242 while (result > 0) { | 247 while (result > 0) { |
| 243 // Loop to ensure we copy everything, and not only up to 2GB. | 248 // Loop to ensure we copy everything, and not only up to 2GB. |
| 244 result = TEMP_FAILURE_RETRY( | 249 result = TEMP_FAILURE_RETRY( |
| 245 sendfile(new_fd, old_fd, &offset, kMaxUint32)); | 250 sendfile(new_fd, old_fd, &offset, kMaxUint32)); |
| 246 } | 251 } |
| 247 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { | 252 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
| 248 const intptr_t kBufferSize = 8 * 1024; | 253 const intptr_t kBufferSize = 8 * 1024; |
| 249 uint8_t buffer[kBufferSize]; | 254 uint8_t buffer[kBufferSize]; |
| 255 // Block profile interrupts while making I/O call. | |
| 256 ThreadSignalBlocker tsb(SIGPROF); | |
| 250 while ((result = TEMP_FAILURE_RETRY( | 257 while ((result = TEMP_FAILURE_RETRY( |
| 251 read(old_fd, buffer, kBufferSize))) > 0) { | 258 read(old_fd, buffer, kBufferSize))) > 0) { |
| 252 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); | 259 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
| 253 if (wrote != result) { | 260 if (wrote != result) { |
| 254 result = -1; | 261 result = -1; |
| 255 break; | 262 break; |
| 256 } | 263 } |
| 257 } | 264 } |
| 258 } | 265 } |
| 259 if (result < 0) { | 266 if (result < 0) { |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 return (file_1_info.st_ino == file_2_info.st_ino && | 419 return (file_1_info.st_ino == file_2_info.st_ino && |
| 413 file_1_info.st_dev == file_2_info.st_dev) ? | 420 file_1_info.st_dev == file_2_info.st_dev) ? |
| 414 File::kIdentical : | 421 File::kIdentical : |
| 415 File::kDifferent; | 422 File::kDifferent; |
| 416 } | 423 } |
| 417 | 424 |
| 418 } // namespace bin | 425 } // namespace bin |
| 419 } // namespace dart | 426 } // namespace dart |
| 420 | 427 |
| 421 #endif // defined(TARGET_OS_ANDROID) | 428 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |