Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(699)

Side by Side Diff: components/nacl/loader/nonsfi/irt_resource_open.cc

Issue 649603004: Non-SFI NaCl: Batch-open resource files (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: code review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <pthread.h>
6
7 #include <map>
8 #include <string>
9 #include <vector>
10
5 #include "components/nacl/loader/nonsfi/irt_interfaces.h" 11 #include "components/nacl/loader/nonsfi/irt_interfaces.h"
6 #include "ppapi/nacl_irt/irt_manifest.h" 12 #include "ppapi/nacl_irt/irt_manifest.h"
7 13
8 namespace nacl { 14 namespace nacl {
9 namespace nonsfi { 15 namespace nonsfi {
10 16
17 namespace {
18
19 pthread_mutex_t g_mu = PTHREAD_MUTEX_INITIALIZER;
20 std::map<std::string, int>* g_fds;
21
22 } // namespace
23
24 void RegisterPreopenedDescriptors(const std::vector<std::string>& keys,
25 const std::vector<int>& fds) {
26 pthread_mutex_lock(&g_mu);
27 g_fds = new std::map<std::string, int>;
28 for (size_t i = 0; i < keys.size(); ++i)
29 g_fds->insert(std::make_pair(keys[i], fds[i]));
30 pthread_mutex_unlock(&g_mu);
31 }
32
33 int IrtOpenResource(const char* file, int* fd) {
34 pthread_mutex_lock(&g_mu);
35 if (g_fds) {
36 std::map<std::string, int>::iterator it;
37 if (file[0] == '/')
38 it = g_fds->find(file + 1);
39 else
40 it = g_fds->find(file);
41 if (it != g_fds->end()) {
42 *fd = it->second;
43 g_fds->erase(it);
44 pthread_mutex_unlock(&g_mu);
45 return 0;
46 }
47 }
48 pthread_mutex_unlock(&g_mu);
49 return ppapi::IrtOpenResource(file, fd);
50 }
51
11 const nacl_irt_resource_open kIrtResourceOpen = { 52 const nacl_irt_resource_open kIrtResourceOpen = {
12 ppapi::IrtOpenResource, 53 nacl::nonsfi::IrtOpenResource,
13 }; 54 };
14 55
15 } // namespace nonsfi 56 } // namespace nonsfi
16 } // namespace nacl 57 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698