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 hygiene 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 | |
83 // The descriptor for a writeable file needs to have quota management. | 72 // The descriptor for a writeable file needs to have quota management. |
84 write_wrapper_.reset( | 73 wrapper_.reset( |
85 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); | 74 plugin_->wrapper_factory()->MakeFileDescQuota(fd, O_RDWR, identifier_)); |
86 read_wrapper_.reset( | |
87 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY)); | |
88 core->CallOnMainThread(0, cb, PP_OK); | 75 core->CallOnMainThread(0, cb, PP_OK); |
89 } | 76 } |
90 | 77 |
91 bool TempFile::Reset() { | 78 bool TempFile::Reset() { |
92 PLUGIN_PRINTF(("TempFile::Reset\n")); | 79 PLUGIN_PRINTF(("TempFile::Reset\n")); |
93 // Use the write_wrapper_ to reset the file pos. The read_wrapper_ is also | 80 CHECK(wrapper_.get() != NULL); |
94 // backed by the same file, so it should also reset. | 81 nacl_off64_t newpos = wrapper_->Seek(0, SEEK_SET); |
95 CHECK(write_wrapper_.get() != NULL); | |
96 nacl_off64_t newpos = write_wrapper_->Seek(0, SEEK_SET); | |
97 return newpos >= 0; | 82 return newpos >= 0; |
98 } | 83 } |
99 | 84 |
100 } // namespace plugin | 85 } // namespace plugin |
OLD | NEW |