| 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 "native_client/src/trusted/plugin/temporary_file.h" | 5 #include "native_client/src/trusted/plugin/temporary_file.h" |
| 6 | 6 |
| 7 #include "native_client/src/include/portability_io.h" | 7 #include "native_client/src/include/portability_io.h" |
| 8 #include "native_client/src/shared/platform/nacl_check.h" | 8 #include "native_client/src/shared/platform/nacl_check.h" |
| 9 #include "native_client/src/trusted/plugin/plugin.h" | 9 #include "native_client/src/trusted/plugin/plugin.h" |
| 10 #include "native_client/src/trusted/plugin/utility.h" | 10 #include "native_client/src/trusted/plugin/utility.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 #else | 62 #else |
| 63 int32_t fd = file_handle; | 63 int32_t fd = file_handle; |
| 64 #endif | 64 #endif |
| 65 | 65 |
| 66 if (fd < 0) { | 66 if (fd < 0) { |
| 67 PLUGIN_PRINTF(("TempFile::Open failed\n")); | 67 PLUGIN_PRINTF(("TempFile::Open failed\n")); |
| 68 core->CallOnMainThread(0, cb, PP_ERROR_FAILED); | 68 core->CallOnMainThread(0, cb, PP_ERROR_FAILED); |
| 69 return; | 69 return; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // dup the fd to make allow making a non-Quota-based wrapper. |
| 73 // sel_ldr currently does not allow loading from Quota-backed descs, |
| 74 // only plain host descs. It's probably good hygene to separate the |
| 75 // read wrapper from the write wrapper anyway. |
| 76 int32_t read_fd = DUP(fd); |
| 77 if (read_fd == NACL_NO_FILE_DESC) { |
| 78 PLUGIN_PRINTF(("TempFile::Open DUP failed\n")); |
| 79 core->CallOnMainThread(0, cb, PP_ERROR_FAILED); |
| 80 return; |
| 81 } |
| 82 |
| 72 // The descriptor for a writeable file needs to have quota management. | 83 // The descriptor for a writeable file needs to have quota management. |
| 73 wrapper_.reset( | 84 write_wrapper_.reset( |
| 74 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); | 85 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); |
| 86 read_wrapper_.reset( |
| 87 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); |
| 75 core->CallOnMainThread(0, cb, PP_OK); | 88 core->CallOnMainThread(0, cb, PP_OK); |
| 76 } | 89 } |
| 77 | 90 |
| 78 bool TempFile::Reset() { | 91 bool TempFile::Reset() { |
| 79 PLUGIN_PRINTF(("TempFile::Reset\n")); | 92 PLUGIN_PRINTF(("TempFile::Reset\n")); |
| 80 CHECK(wrapper_.get() != NULL); | 93 // Use the write_wrapper_ to reset the file pos. The read_wrapper_ is also |
| 81 nacl_off64_t newpos = wrapper_->Seek(0, SEEK_SET); | 94 // backed by the same file, so it should also reset. |
| 95 CHECK(write_wrapper_.get() != NULL); |
| 96 nacl_off64_t newpos = write_wrapper_->Seek(0, SEEK_SET); |
| 82 return newpos >= 0; | 97 return newpos >= 0; |
| 83 } | 98 } |
| 84 | 99 |
| 85 } // namespace plugin | 100 } // namespace plugin |
| OLD | NEW |