Chromium Code Reviews| 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 #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 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 assert(s_saved_state.kp == NULL); | 41 assert(s_saved_state.kp == NULL); |
| 42 if (s_saved_state.kp != NULL) | 42 if (s_saved_state.kp != NULL) |
| 43 return 1; | 43 return 1; |
| 44 s_saved_state = s_state; | 44 s_saved_state = s_state; |
| 45 s_state.kp = NULL; | 45 s_state.kp = NULL; |
| 46 s_state.ppapi = NULL; | 46 s_state.ppapi = NULL; |
| 47 s_state.kp_owned = false; | 47 s_state.kp_owned = false; |
| 48 return 0; | 48 return 0; |
| 49 } | 49 } |
| 50 | 50 |
| 51 static void ki_pop_state() { | |
| 52 // Swap out the KernelProxy. This will normally reset the | |
| 53 // proxy to NULL, aside from in test code that has called | |
| 54 // ki_push_state_for_testing(). | |
| 55 s_state = s_saved_state; | |
| 56 s_saved_state.kp = NULL; | |
| 57 s_saved_state.ppapi = NULL; | |
| 58 s_saved_state.kp_owned = false; | |
| 59 } | |
| 60 | |
| 61 int ki_pop_state_for_testing() { | |
| 62 ki_pop_state(); | |
| 63 return 0; | |
| 64 } | |
| 65 | |
| 51 int ki_init(void* kp) { | 66 int ki_init(void* kp) { |
| 52 LOG_TRACE("ki_init: %p", kp); | 67 LOG_TRACE("ki_init: %p", kp); |
| 53 return ki_init_ppapi(kp, 0, NULL); | 68 return ki_init_ppapi(kp, 0, NULL); |
| 54 } | 69 } |
| 55 | 70 |
| 56 int ki_init_ppapi(void* kp, | 71 int ki_init_ppapi(void* kp, |
| 57 PP_Instance instance, | 72 PP_Instance instance, |
| 58 PPB_GetInterface get_browser_interface) { | 73 PPB_GetInterface get_browser_interface) { |
| 59 assert(!s_state.kp); | 74 assert(!s_state.kp); |
| 60 if (s_state.kp != NULL) | 75 if (s_state.kp != NULL) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 96 | 111 |
| 97 void ki_uninit() { | 112 void ki_uninit() { |
| 98 LOG_TRACE("ki_uninit"); | 113 LOG_TRACE("ki_uninit"); |
| 99 if (s_saved_state.kp == NULL) | 114 if (s_saved_state.kp == NULL) |
| 100 kernel_wrap_uninit(); | 115 kernel_wrap_uninit(); |
| 101 | 116 |
| 102 // If we are going to delete the KernelProxy don't do it | 117 // If we are going to delete the KernelProxy don't do it |
| 103 // until we've swapped it out. | 118 // until we've swapped it out. |
| 104 KernelInterceptState state_to_delete = s_state; | 119 KernelInterceptState state_to_delete = s_state; |
| 105 | 120 |
| 106 // Swap out the KernelProxy. This will normally reset the | 121 ki_pop_state(); |
| 107 // proxy to NULL, aside from in test code that has called | |
| 108 // ki_push_state_for_testing(). | |
| 109 s_state = s_saved_state; | |
| 110 s_saved_state.kp = NULL; | |
| 111 s_saved_state.ppapi = NULL; | |
| 112 s_saved_state.kp_owned = false; | |
| 113 | 122 |
| 114 if (state_to_delete.kp_owned) | 123 if (state_to_delete.kp_owned) |
| 115 delete state_to_delete.kp; | 124 delete state_to_delete.kp; |
| 116 | 125 |
| 117 delete state_to_delete.ppapi; | 126 delete state_to_delete.ppapi; |
| 118 } | 127 } |
| 119 | 128 |
| 120 nacl_io::KernelProxy* ki_get_proxy() { | 129 nacl_io::KernelProxy* ki_get_proxy() { |
| 121 return s_state.kp; | 130 return s_state.kp; |
| 122 } | 131 } |
| 123 | 132 |
| 124 int ki_chdir(const char* path) { | 133 int ki_chdir(const char* path) { |
| 125 ON_NOSYS_RETURN(-1); | 134 ON_NOSYS_RETURN(-1); |
| 126 return s_state.kp->chdir(path); | 135 return s_state.kp->chdir(path); |
| 127 } | 136 } |
| 128 | 137 |
| 129 void ki_exit(int status) { | 138 void ki_exit(int status) { |
| 130 if (ki_is_initialized()) | 139 if (ki_is_initialized()) |
| 131 s_state.kp->exit(status); | 140 s_state.kp->exit(status); |
| 132 | 141 |
| 133 _real_exit(status); | 142 _real_exit(status); |
| 134 } | 143 } |
| 135 | 144 |
| 136 char* ki_getcwd(char* buf, size_t size) { | 145 char* ki_getcwd(char* buf, size_t size) { |
| 137 // gtest uses getcwd in a static initializer. If we haven't initialized the | 146 // gtest uses getcwd in a static initializer and expects it to always |
| 138 // kernel-intercept yet, just return ".". | 147 // succeed. If we haven't initialized kernel-intercept yet, they try |
|
binji
2014/08/20 18:13:35
s/they/then/
Sam Clegg
2014/08/21 10:19:33
Done.
| |
| 148 // the IRT's getcwd, and fall back to just returning ".". | |
| 139 if (!ki_is_initialized()) { | 149 if (!ki_is_initialized()) { |
| 140 if (size < 2) { | 150 int rtn = _real_getcwd(buf, size); |
| 141 errno = ERANGE; | 151 if (rtn != 0) { |
| 142 return NULL; | 152 if (rtn == ENOSYS) { |
| 153 buf[0] = '.'; | |
| 154 buf[1] = 0; | |
| 155 } else { | |
| 156 errno = rtn; | |
| 157 return NULL; | |
| 158 } | |
| 143 } | 159 } |
| 144 buf[0] = '.'; | |
| 145 buf[1] = 0; | |
| 146 return buf; | 160 return buf; |
| 147 } | 161 } |
| 148 return s_state.kp->getcwd(buf, size); | 162 return s_state.kp->getcwd(buf, size); |
| 149 } | 163 } |
| 150 | 164 |
| 151 char* ki_getwd(char* buf) { | 165 char* ki_getwd(char* buf) { |
| 152 ON_NOSYS_RETURN(NULL); | 166 ON_NOSYS_RETURN(NULL); |
| 153 return s_state.kp->getwd(buf); | 167 return s_state.kp->getwd(buf); |
| 154 } | 168 } |
| 155 | 169 |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 557 int ki_socket(int domain, int type, int protocol) { | 571 int ki_socket(int domain, int type, int protocol) { |
| 558 ON_NOSYS_RETURN(-1); | 572 ON_NOSYS_RETURN(-1); |
| 559 return s_state.kp->socket(domain, type, protocol); | 573 return s_state.kp->socket(domain, type, protocol); |
| 560 } | 574 } |
| 561 | 575 |
| 562 int ki_socketpair(int domain, int type, int protocol, int* sv) { | 576 int ki_socketpair(int domain, int type, int protocol, int* sv) { |
| 563 ON_NOSYS_RETURN(-1); | 577 ON_NOSYS_RETURN(-1); |
| 564 return s_state.kp->socketpair(domain, type, protocol, sv); | 578 return s_state.kp->socketpair(domain, type, protocol, sv); |
| 565 } | 579 } |
| 566 #endif // PROVIDES_SOCKET_API | 580 #endif // PROVIDES_SOCKET_API |
| OLD | NEW |