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
3 : // found in the LICENSE file.
4 : //
5 :
6 : #include <map>
7 : #include <string>
8 :
9 : #include "native_client/src/shared/platform/nacl_check.h"
10 : #include "native_client/src/shared/platform/nacl_log.h"
11 : #include "native_client/src/shared/srpc/nacl_srpc.h"
12 : #include "native_client/src/trusted/sel_universal/pnacl_emu.h"
13 : #include "native_client/src/trusted/sel_universal/rpc_universal.h"
14 : #include "native_client/src/trusted/sel_universal/srpc_helper.h"
15 :
16 : using std::string;
17 :
18 : namespace {
19 :
20 : NaClCommandLoop* g_ncl;
21 :
22 : // Maps from a saved key to the sel_universal variable name that refers to
23 : // a file.
24 14 : std::map<string, string> g_key_to_varname;
25 :
26 : // LookupInputFile:s:h
27 0 : void LookupInputFile(SRPC_PARAMS) {
28 0 : string key(ins[0]->arrays.str);
29 0 : rpc->result = NACL_SRPC_RESULT_APP_ERROR;
30 0 : NaClLog(1, "LookupInputFile(%s)\n", key.c_str());
31 0 : if (g_key_to_varname.find(key) == g_key_to_varname.end()) {
32 0 : return;
33 : }
34 0 : string varname = g_key_to_varname[key];
35 0 : NaClLog(1, "LookupInputFile(%s) -> %s\n", key.c_str(), varname.c_str());
36 0 : outs[0]->u.hval = g_ncl->FindDescByName(varname);
37 0 : rpc->result = NACL_SRPC_RESULT_OK;
38 0 : done->Run(done);
39 0 : }
40 :
41 : } // end namespace
42 :
43 :
44 : #define TUPLE(a, b) #a #b, a
45 0 : void PnaclEmulateCoordinator(NaClCommandLoop* ncl) {
46 : // Register file lookup RPC.
47 0 : ncl->AddUpcallRpc(TUPLE(LookupInputFile, :s:h));
48 0 : g_ncl = ncl;
49 0 : }
50 :
51 0 : void PnaclEmulateAddKeyVarnameMapping(const std::string& key,
52 0 : const std::string& varname) {
53 0 : NaClLog(1, "AddKeyVarnameMapping(%s) -> %s\n", key.c_str(),
54 0 : varname.c_str());
55 0 : CHECK(g_key_to_varname.find(key) == g_key_to_varname.end());
56 0 : g_key_to_varname[string(key)] = string(varname);
57 0 : }
|