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 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ | 5 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ |
6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ | 6 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 // as it is passed in with PutBytes. | 41 // as it is passed in with PutBytes. |
42 void RunTranslate(const pp::CompletionCallback& finish_callback, | 42 void RunTranslate(const pp::CompletionCallback& finish_callback, |
43 const Manifest* manifest, | 43 const Manifest* manifest, |
44 const Manifest* ld_manifest, | 44 const Manifest* ld_manifest, |
45 TempFile* obj_file, | 45 TempFile* obj_file, |
46 LocalTempFile* nexe_file, | 46 LocalTempFile* nexe_file, |
47 ErrorInfo* error_info, | 47 ErrorInfo* error_info, |
48 PnaclResources* resources, | 48 PnaclResources* resources, |
49 Plugin* plugin); | 49 Plugin* plugin); |
50 | 50 |
51 // Signal the translate thread and subprocesses that they should stop. | 51 // Kill the llc and/or ld subprocesses. This happens by closing the command |
52 void SetSubprocessesShouldDie(); | 52 // channel on the plugin side, which causes the trusted code in the nexe to |
| 53 // exit, which will cause any pending SRPCs to error. Because this is called |
| 54 // on the main thread, the translation thread must not use the subprocess |
| 55 // objects without the lock, other than InvokeSrpcMethod, which does not |
| 56 // race with service runtime shutdown. |
| 57 void AbortSubprocesses(); |
53 | 58 |
54 // Send bitcode bytes to the translator. Called from the main thread. | 59 // Send bitcode bytes to the translator. Called from the main thread. |
55 void PutBytes(std::vector<char>* data, int count); | 60 void PutBytes(std::vector<char>* data, int count); |
56 | 61 |
57 private: | 62 private: |
58 // Returns true if the translate thread and subprocesses should stop. | |
59 bool SubprocessesShouldDie(); | |
60 | |
61 // Starts an individual llc or ld subprocess used for translation. | 63 // Starts an individual llc or ld subprocess used for translation. |
62 NaClSubprocess* StartSubprocess(const nacl::string& url, | 64 NaClSubprocess* StartSubprocess(const nacl::string& url, |
63 const Manifest* manifest, | 65 const Manifest* manifest, |
64 ErrorInfo* error_info); | 66 ErrorInfo* error_info); |
65 // Helper thread entry point for translation. Takes a pointer to | 67 // Helper thread entry point for translation. Takes a pointer to |
66 // PnaclTranslateThread and calls DoTranslate(). | 68 // PnaclTranslateThread and calls DoTranslate(). |
67 static void WINAPI DoTranslateThread(void* arg); | 69 static void WINAPI DoTranslateThread(void* arg); |
68 // Runs the streaming translation. Called from the helper thread. | 70 // Runs the streaming translation. Called from the helper thread. |
69 void DoTranslate() ; | 71 void DoTranslate() ; |
70 // Signal that Pnacl translation failed, from the translation thread only. | 72 // Signal that Pnacl translation failed, from the translation thread only. |
71 void TranslateFailed(const nacl::string& error_string); | 73 void TranslateFailed(const nacl::string& error_string); |
72 // Run the LD subprocess, returning true on success | 74 // Run the LD subprocess, returning true on success |
73 bool RunLdSubprocess(int is_shared_library, | 75 bool RunLdSubprocess(int is_shared_library, |
74 const nacl::string& soname, | 76 const nacl::string& soname, |
75 const nacl::string& lib_dependencies); | 77 const nacl::string& lib_dependencies); |
76 | 78 |
77 // Register a reverse service interface which will be shutdown if the | |
78 // plugin is shutdown. The reverse service pointer must be available on the | |
79 // main thread because the translation thread could be blocked on SRPC | |
80 // waiting for the translator, which could be waiting on a reverse | |
81 // service call. | |
82 // (see also the comments in Plugin::~Plugin about ShutdownSubprocesses, | |
83 // but that only handles the main nexe and not the translator nexes.) | |
84 void RegisterReverseInterface(PluginReverseInterface *iface); | |
85 | 79 |
86 // Callback to run when tasks are completed or an error has occurred. | 80 // Callback to run when tasks are completed or an error has occurred. |
87 pp::CompletionCallback report_translate_finished_; | 81 pp::CompletionCallback report_translate_finished_; |
88 // True if the translation thread and related subprocesses should exit. | |
89 bool subprocesses_should_die_; | |
90 // Used to guard and publish subprocesses_should_die_. | |
91 struct NaClMutex subprocess_mu_; | |
92 | 82 |
93 nacl::scoped_ptr<NaClThread> translate_thread_; | 83 nacl::scoped_ptr<NaClThread> translate_thread_; |
94 | 84 |
95 // Reverse interface to shutdown on SetSubprocessesShouldDie | 85 // Used to guard llc_subprocess and ld_subprocess |
96 PluginReverseInterface* current_rev_interface_; | 86 struct NaClMutex subprocess_mu_; |
97 | 87 nacl::scoped_ptr<NaClSubprocess> llc_subprocess_; |
98 | 88 nacl::scoped_ptr<NaClSubprocess> ld_subprocess_; |
| 89 // Used to ensure the subprocesses don't get shutdown more than once. |
| 90 bool llc_subprocess_active_; |
| 91 bool ld_subprocess_active_; |
99 | 92 |
100 // Condition variable to synchronize communication with the SRPC thread. | 93 // Condition variable to synchronize communication with the SRPC thread. |
101 // SRPC thread waits on this condvar if data_buffers_ is empty (meaning | 94 // SRPC thread waits on this condvar if data_buffers_ is empty (meaning |
102 // there is no bitcode to send to the translator), and the main thread | 95 // there is no bitcode to send to the translator), and the main thread |
103 // appends to data_buffers_ and signals it when it receives bitcode. | 96 // appends to data_buffers_ and signals it when it receives bitcode. |
104 struct NaClCondVar buffer_cond_; | 97 struct NaClCondVar buffer_cond_; |
105 // Mutex for buffer_cond_. | 98 // Mutex for buffer_cond_. |
106 struct NaClMutex cond_mu_; | 99 struct NaClMutex cond_mu_; |
107 // Data buffers from FileDownloader are enqueued here to pass from the | 100 // Data buffers from FileDownloader are enqueued here to pass from the |
108 // main thread to the SRPC thread. Protected by cond_mu_ | 101 // main thread to the SRPC thread. Protected by cond_mu_ |
109 std::deque<std::vector<char> > data_buffers_; | 102 std::deque<std::vector<char> > data_buffers_; |
110 // Whether all data has been downloaded and copied to translation thread. | 103 // Whether all data has been downloaded and copied to translation thread. |
111 // Associated with buffer_cond_ | 104 // Associated with buffer_cond_ |
112 bool done_; | 105 bool done_; |
113 | 106 |
114 // Data about the translation files, owned by the coordinator | 107 // Data about the translation files, owned by the coordinator |
115 const Manifest* manifest_; | 108 const Manifest* manifest_; |
116 const Manifest* ld_manifest_; | 109 const Manifest* ld_manifest_; |
117 TempFile* obj_file_; | 110 TempFile* obj_file_; |
118 LocalTempFile* nexe_file_; | 111 LocalTempFile* nexe_file_; |
119 ErrorInfo* coordinator_error_info_; | 112 ErrorInfo* coordinator_error_info_; |
120 PnaclResources* resources_; | 113 PnaclResources* resources_; |
121 Plugin* plugin_; | 114 Plugin* plugin_; |
122 private: | 115 private: |
123 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclTranslateThread); | 116 NACL_DISALLOW_COPY_AND_ASSIGN(PnaclTranslateThread); |
124 }; | 117 }; |
125 | 118 |
126 } | 119 } |
127 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ | 120 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PNACL_TRANSLATE_THREAD_H_ |
OLD | NEW |