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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
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 |
26 | |
27 | |
siva
2013/12/13 21:29:14
???
| |
25 class FileHandle { | 28 class FileHandle { |
26 public: | 29 public: |
27 explicit FileHandle(int fd) : fd_(fd) { } | 30 explicit FileHandle(int fd) : fd_(fd) { } |
28 ~FileHandle() { } | 31 ~FileHandle() { } |
29 int fd() const { return fd_; } | 32 int fd() const { return fd_; } |
30 void set_fd(int fd) { fd_ = fd; } | 33 void set_fd(int fd) { fd_ = fd; } |
31 | 34 |
32 private: | 35 private: |
33 int fd_; | 36 int fd_; |
34 | 37 |
(...skipping 22 matching lines...) Expand all Loading... | |
57 } | 60 } |
58 | 61 |
59 | 62 |
60 bool File::IsClosed() { | 63 bool File::IsClosed() { |
61 return handle_->fd() == kClosedFd; | 64 return handle_->fd() == kClosedFd; |
62 } | 65 } |
63 | 66 |
64 | 67 |
65 int64_t File::Read(void* buffer, int64_t num_bytes) { | 68 int64_t File::Read(void* buffer, int64_t num_bytes) { |
66 ASSERT(handle_->fd() >= 0); | 69 ASSERT(handle_->fd() >= 0); |
70 // Block profile interrupts while making I/O call. | |
71 ThreadSignalBlocker tsb(SIGPROF); | |
67 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); | 72 return TEMP_FAILURE_RETRY(read(handle_->fd(), buffer, num_bytes)); |
68 } | 73 } |
69 | 74 |
70 | 75 |
71 int64_t File::Write(const void* buffer, int64_t num_bytes) { | 76 int64_t File::Write(const void* buffer, int64_t num_bytes) { |
72 ASSERT(handle_->fd() >= 0); | 77 ASSERT(handle_->fd() >= 0); |
78 // Block profile interrupts while making I/O call. | |
79 ThreadSignalBlocker tsb(SIGPROF); | |
73 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); | 80 return TEMP_FAILURE_RETRY(write(handle_->fd(), buffer, num_bytes)); |
74 } | 81 } |
75 | 82 |
76 | 83 |
77 off64_t File::Position() { | 84 off64_t File::Position() { |
78 ASSERT(handle_->fd() >= 0); | 85 ASSERT(handle_->fd() >= 0); |
79 return lseek64(handle_->fd(), 0, SEEK_CUR); | 86 return lseek64(handle_->fd(), 0, SEEK_CUR); |
80 } | 87 } |
81 | 88 |
82 | 89 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 off64_t offset = 0; | 248 off64_t offset = 0; |
242 int result = 1; | 249 int result = 1; |
243 while (result > 0) { | 250 while (result > 0) { |
244 // Loop to ensure we copy everything, and not only up to 2GB. | 251 // Loop to ensure we copy everything, and not only up to 2GB. |
245 result = TEMP_FAILURE_RETRY( | 252 result = TEMP_FAILURE_RETRY( |
246 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); | 253 sendfile64(new_fd, old_fd, &offset, kMaxUint32)); |
247 } | 254 } |
248 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { | 255 if (result < 0 && (errno == EINVAL || errno == ENOSYS)) { |
249 const intptr_t kBufferSize = 8 * 1024; | 256 const intptr_t kBufferSize = 8 * 1024; |
250 uint8_t buffer[kBufferSize]; | 257 uint8_t buffer[kBufferSize]; |
258 // Block profile interrupts while making I/O call. | |
259 ThreadSignalBlocker tsb(SIGPROF); | |
251 while ((result = TEMP_FAILURE_RETRY( | 260 while ((result = TEMP_FAILURE_RETRY( |
252 read(old_fd, buffer, kBufferSize))) > 0) { | 261 read(old_fd, buffer, kBufferSize))) > 0) { |
253 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); | 262 int wrote = TEMP_FAILURE_RETRY(write(new_fd, buffer, result)); |
254 if (wrote != result) { | 263 if (wrote != result) { |
255 result = -1; | 264 result = -1; |
256 break; | 265 break; |
257 } | 266 } |
258 } | 267 } |
259 } | 268 } |
260 if (result < 0) { | 269 if (result < 0) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 return (file_1_info.st_ino == file_2_info.st_ino && | 415 return (file_1_info.st_ino == file_2_info.st_ino && |
407 file_1_info.st_dev == file_2_info.st_dev) ? | 416 file_1_info.st_dev == file_2_info.st_dev) ? |
408 File::kIdentical : | 417 File::kIdentical : |
409 File::kDifferent; | 418 File::kDifferent; |
410 } | 419 } |
411 | 420 |
412 } // namespace bin | 421 } // namespace bin |
413 } // namespace dart | 422 } // namespace dart |
414 | 423 |
415 #endif // defined(TARGET_OS_LINUX) | 424 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |