| OLD | NEW |
| 1 // Copyright (c) 2012 The Native Client Authors. All rights reserved. | 1 // Copyright (c) 2012 The Native Client 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 | 5 |
| 6 #include "native_client/src/trusted/sel_universal/reverse_emulate.h" | 6 #include "native_client/src/trusted/sel_universal/reverse_emulate.h" |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "native_client/src/include/portability_io.h" | 14 #include "native_client/src/include/portability_io.h" |
| 15 #include "native_client/src/shared/platform/nacl_check.h" | 15 #include "native_client/src/shared/platform/nacl_check.h" |
| 16 #include "native_client/src/shared/platform/nacl_log.h" | 16 #include "native_client/src/shared/platform/nacl_log.h" |
| 17 #include "native_client/src/shared/platform/nacl_sync.h" | 17 #include "native_client/src/shared/platform/nacl_sync.h" |
| 18 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 18 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 19 #include "native_client/src/shared/platform/nacl_sync_raii.h" | 19 #include "native_client/src/shared/platform/nacl_sync_raii.h" |
| 20 #include "native_client/src/shared/platform/nacl_threads.h" | 20 #include "native_client/src/shared/platform/nacl_threads.h" |
| 21 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" | 21 #include "native_client/src/shared/platform/scoped_ptr_refcount.h" |
| 22 #include "native_client/src/shared/srpc/nacl_srpc.h" | 22 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 23 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" | 23 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" |
| 24 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" | 24 #include "native_client/src/trusted/nonnacl_util/sel_ldr_launcher.h" |
| 25 #include "native_client/src/trusted/reverse_service/nacl_file_info.h" |
| 25 #include "native_client/src/trusted/reverse_service/reverse_service.h" | 26 #include "native_client/src/trusted/reverse_service/reverse_service.h" |
| 26 #include "native_client/src/trusted/sel_universal/rpc_universal.h" | 27 #include "native_client/src/trusted/sel_universal/rpc_universal.h" |
| 27 #include "native_client/src/trusted/sel_universal/srpc_helper.h" | 28 #include "native_client/src/trusted/sel_universal/srpc_helper.h" |
| 28 | 29 |
| 29 | 30 |
| 30 // Mock of ReverseInterface for use by nexes. | 31 // Mock of ReverseInterface for use by nexes. |
| 31 class ReverseEmulate : public nacl::ReverseInterface { | 32 class ReverseEmulate : public nacl::ReverseInterface { |
| 32 public: | 33 public: |
| 33 ReverseEmulate(); | 34 ReverseEmulate(); |
| 34 virtual ~ReverseEmulate(); | 35 virtual ~ReverseEmulate(); |
| 35 | 36 |
| 36 // debugging, messaging | 37 // debugging, messaging |
| 37 virtual void Log(nacl::string message); | 38 virtual void Log(nacl::string message); |
| 38 | 39 |
| 39 // Startup handshake | 40 // Startup handshake |
| 40 virtual void StartupInitializationComplete(); | 41 virtual void StartupInitializationComplete(); |
| 41 | 42 |
| 42 // Name service use. | 43 // Name service use. |
| 43 virtual bool EnumerateManifestKeys(std::set<nacl::string>* keys); | 44 virtual bool EnumerateManifestKeys(std::set<nacl::string>* keys); |
| 44 virtual bool OpenManifestEntry(nacl::string url_key, int32_t* out_desc); | 45 virtual bool OpenManifestEntry(nacl::string url_key, |
| 46 struct NaClFileInfo* info); |
| 45 virtual bool CloseManifestEntry(int32_t desc); | 47 virtual bool CloseManifestEntry(int32_t desc); |
| 46 virtual void ReportCrash(); | 48 virtual void ReportCrash(); |
| 47 | 49 |
| 48 // The low-order 8 bits of the |exit_status| should be reported to | 50 // The low-order 8 bits of the |exit_status| should be reported to |
| 49 // any interested parties. | 51 // any interested parties. |
| 50 virtual void ReportExitStatus(int exit_status); | 52 virtual void ReportExitStatus(int exit_status); |
| 51 | 53 |
| 52 // Send a string as a PostMessage to the browser. | 54 // Send a string as a PostMessage to the browser. |
| 53 virtual void DoPostMessage(nacl::string message); | 55 virtual void DoPostMessage(nacl::string message); |
| 54 | 56 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 for (KeyToFileMap::iterator i = g_key_to_file.begin(); | 235 for (KeyToFileMap::iterator i = g_key_to_file.begin(); |
| 234 i != g_key_to_file.end(); | 236 i != g_key_to_file.end(); |
| 235 ++i) { | 237 ++i) { |
| 236 manifest_keys.insert(i->first); | 238 manifest_keys.insert(i->first); |
| 237 } | 239 } |
| 238 *keys = manifest_keys; | 240 *keys = manifest_keys; |
| 239 return true; | 241 return true; |
| 240 } | 242 } |
| 241 | 243 |
| 242 bool ReverseEmulate::OpenManifestEntry(nacl::string url_key, | 244 bool ReverseEmulate::OpenManifestEntry(nacl::string url_key, |
| 243 int32_t* out_desc) { | 245 struct NaClFileInfo* info) { |
| 244 NaClLog(1, "ReverseEmulate::OpenManifestEntry (url_key=%s)\n", | 246 NaClLog(1, "ReverseEmulate::OpenManifestEntry (url_key=%s)\n", |
| 245 url_key.c_str()); | 247 url_key.c_str()); |
| 246 *out_desc = -1; | 248 info->desc = -1; |
| 247 // Find the pathname for the key. | 249 // Find the pathname for the key. |
| 248 if (g_key_to_file.find(url_key) == g_key_to_file.end()) { | 250 if (g_key_to_file.find(url_key) == g_key_to_file.end()) { |
| 249 NaClLog(1, "ReverseEmulate::OpenManifestEntry: no pathname for key.\n"); | 251 NaClLog(1, "ReverseEmulate::OpenManifestEntry: no pathname for key.\n"); |
| 250 return false; | 252 return false; |
| 251 } | 253 } |
| 252 nacl::string pathname = g_key_to_file[url_key]; | 254 nacl::string pathname = g_key_to_file[url_key]; |
| 253 NaClLog(1, "ReverseEmulate::OpenManifestEntry: pathname is %s.\n", | 255 NaClLog(1, "ReverseEmulate::OpenManifestEntry: pathname is %s.\n", |
| 254 pathname.c_str()); | 256 pathname.c_str()); |
| 255 *out_desc = OPEN(pathname.c_str(), O_RDONLY); | 257 // TODO(ncbray): provide more information so that fast validation caching and |
| 256 return *out_desc >= 0; | 258 // mmaping can be enabled. |
| 259 info->desc = OPEN(pathname.c_str(), O_RDONLY); |
| 260 info->nonce = 0; |
| 261 return info->desc >= 0; |
| 257 } | 262 } |
| 258 | 263 |
| 259 bool ReverseEmulate::CloseManifestEntry(int32_t desc) { | 264 bool ReverseEmulate::CloseManifestEntry(int32_t desc) { |
| 260 NaClLog(1, "ReverseEmulate::CloseManifestEntry (desc=%d)\n", desc); | 265 NaClLog(1, "ReverseEmulate::CloseManifestEntry (desc=%d)\n", desc); |
| 261 CLOSE(desc); | 266 CLOSE(desc); |
| 262 return true; | 267 return true; |
| 263 } | 268 } |
| 264 | 269 |
| 265 void ReverseEmulate::ReportCrash() { | 270 void ReverseEmulate::ReportCrash() { |
| 266 NaClLog(1, "ReverseEmulate::ReportCrash\n"); | 271 NaClLog(1, "ReverseEmulate::ReportCrash\n"); |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 return false; | 441 return false; |
| 437 } | 442 } |
| 438 if (!subprocesses_[pid].first || subprocesses_[pid].second == NULL) { | 443 if (!subprocesses_[pid].first || subprocesses_[pid].second == NULL) { |
| 439 return false; | 444 return false; |
| 440 } | 445 } |
| 441 subprocesses_[pid].first = false; | 446 subprocesses_[pid].first = false; |
| 442 delete subprocesses_[pid].second; | 447 delete subprocesses_[pid].second; |
| 443 subprocesses_[pid].second = NULL; | 448 subprocesses_[pid].second = NULL; |
| 444 return true; | 449 return true; |
| 445 } | 450 } |
| OLD | NEW |