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

Side by Side Diff: native_client_sdk/src/libraries/nacl_io/kernel_intercept.cc

Issue 271513002: [NaCl SDK] nacl_io: Make IRT intercepts (and their test code) more robust. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_wrap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "nacl_io/kernel_intercept.h" 5 #include "nacl_io/kernel_intercept.h"
6 6
7 #include <assert.h> 7 #include <assert.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <string.h> 9 #include <string.h>
10 10
11 #include "nacl_io/kernel_proxy.h" 11 #include "nacl_io/kernel_proxy.h"
12 #include "nacl_io/kernel_wrap.h" 12 #include "nacl_io/kernel_wrap.h"
13 #include "nacl_io/kernel_wrap_real.h" 13 #include "nacl_io/kernel_wrap_real.h"
14 #include "nacl_io/log.h"
14 #include "nacl_io/osmman.h" 15 #include "nacl_io/osmman.h"
15 #include "nacl_io/ossocket.h" 16 #include "nacl_io/ossocket.h"
16 #include "nacl_io/pepper_interface.h" 17 #include "nacl_io/pepper_interface.h"
17 #include "nacl_io/real_pepper_interface.h" 18 #include "nacl_io/real_pepper_interface.h"
18 19
19 using namespace nacl_io; 20 using namespace nacl_io;
20 21
21 #define ON_NOSYS_RETURN(x) \ 22 #define ON_NOSYS_RETURN(x) \
22 if (!ki_is_initialized()) { \ 23 if (!ki_is_initialized()) { \
23 errno = ENOSYS; \ 24 errno = ENOSYS; \
(...skipping 17 matching lines...) Expand all
41 if (s_saved_state.kp != NULL) 42 if (s_saved_state.kp != NULL)
42 return 1; 43 return 1;
43 s_saved_state = s_state; 44 s_saved_state = s_state;
44 s_state.kp = NULL; 45 s_state.kp = NULL;
45 s_state.ppapi = NULL; 46 s_state.ppapi = NULL;
46 s_state.kp_owned = false; 47 s_state.kp_owned = false;
47 return 0; 48 return 0;
48 } 49 }
49 50
50 int ki_init(void* kp) { 51 int ki_init(void* kp) {
52 LOG_TRACE("ki_init: %p", kp);
51 return ki_init_ppapi(kp, 0, NULL); 53 return ki_init_ppapi(kp, 0, NULL);
52 } 54 }
53 55
54 int ki_init_ppapi(void* kp, 56 int ki_init_ppapi(void* kp,
55 PP_Instance instance, 57 PP_Instance instance,
56 PPB_GetInterface get_browser_interface) { 58 PPB_GetInterface get_browser_interface) {
57 assert(!s_state.kp); 59 assert(!s_state.kp);
58 if (s_state.kp != NULL) 60 if (s_state.kp != NULL)
59 return 1; 61 return 1;
60 PepperInterface* ppapi = NULL; 62 PepperInterface* ppapi = NULL;
61 if (instance && get_browser_interface) { 63 if (instance && get_browser_interface) {
62 ppapi = new RealPepperInterface(instance, get_browser_interface); 64 ppapi = new RealPepperInterface(instance, get_browser_interface);
63 s_state.ppapi = ppapi; 65 s_state.ppapi = ppapi;
64 } 66 }
65 int rtn = ki_init_interface(kp, ppapi); 67 int rtn = ki_init_interface(kp, ppapi);
66 return rtn; 68 return rtn;
67 } 69 }
68 70
69 int ki_init_interface(void* kp, void* pepper_interface) { 71 int ki_init_interface(void* kp, void* pepper_interface) {
72 LOG_TRACE("ki_init_interface: %p %p", kp, pepper_interface);
70 assert(!s_state.kp); 73 assert(!s_state.kp);
71 if (s_state.kp != NULL) 74 if (s_state.kp != NULL)
72 return 1; 75 return 1;
73 PepperInterface* ppapi = static_cast<PepperInterface*>(pepper_interface); 76 PepperInterface* ppapi = static_cast<PepperInterface*>(pepper_interface);
74 kernel_wrap_init(); 77 kernel_wrap_init();
75 78
76 if (kp == NULL) { 79 if (kp == NULL) {
77 s_state.kp = new KernelProxy(); 80 s_state.kp = new KernelProxy();
78 s_state.kp_owned = true; 81 s_state.kp_owned = true;
79 } else { 82 } else {
80 s_state.kp = static_cast<KernelProxy*>(kp); 83 s_state.kp = static_cast<KernelProxy*>(kp);
81 s_state.kp_owned = false; 84 s_state.kp_owned = false;
82 } 85 }
83 86
84 if (s_state.kp->Init(ppapi) != 0) 87 if (s_state.kp->Init(ppapi) != 0)
85 return 1; 88 return 1;
86 89
87 return 0; 90 return 0;
88 } 91 }
89 92
90 int ki_is_initialized() { 93 int ki_is_initialized() {
91 return s_state.kp != NULL; 94 return s_state.kp != NULL;
92 } 95 }
93 96
94 void ki_uninit() { 97 void ki_uninit() {
98 LOG_TRACE("ki_uninit");
95 if (s_saved_state.kp == NULL) 99 if (s_saved_state.kp == NULL)
96 kernel_wrap_uninit(); 100 kernel_wrap_uninit();
97 101
98 // If we are going to delete the KernelProxy don't do it 102 // If we are going to delete the KernelProxy don't do it
99 // until we've swapped it out. 103 // until we've swapped it out.
100 KernelInterceptState state_to_delete = s_state; 104 KernelInterceptState state_to_delete = s_state;
101 105
102 // Swap out the KernelProxy. This will normally reset the 106 // Swap out the KernelProxy. This will normally reset the
103 // proxy to NULL, aside from in test code that has called 107 // proxy to NULL, aside from in test code that has called
104 // ki_push_state_for_testing(). 108 // ki_push_state_for_testing().
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 int ki_socket(int domain, int type, int protocol) { 532 int ki_socket(int domain, int type, int protocol) {
529 ON_NOSYS_RETURN(-1); 533 ON_NOSYS_RETURN(-1);
530 return s_state.kp->socket(domain, type, protocol); 534 return s_state.kp->socket(domain, type, protocol);
531 } 535 }
532 536
533 int ki_socketpair(int domain, int type, int protocol, int* sv) { 537 int ki_socketpair(int domain, int type, int protocol, int* sv) {
534 ON_NOSYS_RETURN(-1); 538 ON_NOSYS_RETURN(-1);
535 return s_state.kp->socketpair(domain, type, protocol, sv); 539 return s_state.kp->socketpair(domain, type, protocol, sv);
536 } 540 }
537 #endif // PROVIDES_SOCKET_API 541 #endif // PROVIDES_SOCKET_API
OLDNEW
« no previous file with comments | « no previous file | native_client_sdk/src/libraries/nacl_io/kernel_wrap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698