| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. |
| 3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
| 4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
| 5 */ | 5 */ |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 /* | 9 /* |
| 10 * NaCl Simple/secure ELF loader (NaCl SEL). | 10 * NaCl Simple/secure ELF loader (NaCl SEL). |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 | 24 |
| 25 #include "native_client/src/trusted/desc/nacl_desc_base.h" | 25 #include "native_client/src/trusted/desc/nacl_desc_base.h" |
| 26 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" | 26 #include "native_client/src/trusted/desc/nacl_desc_conn_cap.h" |
| 27 #include "native_client/src/trusted/desc/nacl_desc_imc.h" | 27 #include "native_client/src/trusted/desc/nacl_desc_imc.h" |
| 28 #include "native_client/src/trusted/desc/nacl_desc_io.h" | 28 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
| 29 #include "native_client/src/trusted/desc/nrd_xfer.h" | 29 #include "native_client/src/trusted/desc/nrd_xfer.h" |
| 30 | 30 |
| 31 #include "native_client/src/trusted/handle_pass/ldr_handle.h" | 31 #include "native_client/src/trusted/handle_pass/ldr_handle.h" |
| 32 | 32 |
| 33 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" | 33 #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h" |
| 34 |
| 34 #include "native_client/src/trusted/gio/gio_nacl_desc.h" | 35 #include "native_client/src/trusted/gio/gio_nacl_desc.h" |
| 35 #include "native_client/src/trusted/gio/gio_shm.h" | 36 #include "native_client/src/trusted/gio/gio_shm.h" |
| 37 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" |
| 36 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 38 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 37 #include "native_client/src/trusted/service_runtime/nacl_app.h" | 39 #include "native_client/src/trusted/service_runtime/nacl_app.h" |
| 38 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" | 40 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" |
| 39 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" | 41 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" |
| 40 #include "native_client/src/trusted/service_runtime/nacl_globals.h" | 42 #include "native_client/src/trusted/service_runtime/nacl_globals.h" |
| 41 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" | 43 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" |
| 42 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" | 44 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" |
| 43 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" | 45 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" |
| 44 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 46 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 45 #include "native_client/src/trusted/service_runtime/sel_memory.h" | 47 #include "native_client/src/trusted/service_runtime/sel_memory.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 nap->dynamic_regions_allocated = 0; | 119 nap->dynamic_regions_allocated = 0; |
| 118 nap->dynamic_delete_generation = 0; | 120 nap->dynamic_delete_generation = 0; |
| 119 | 121 |
| 120 nap->dynamic_mapcache_offset = 0; | 122 nap->dynamic_mapcache_offset = 0; |
| 121 nap->dynamic_mapcache_size = 0; | 123 nap->dynamic_mapcache_size = 0; |
| 122 nap->dynamic_mapcache_ret = 0; | 124 nap->dynamic_mapcache_ret = 0; |
| 123 | 125 |
| 124 nap->service_port = NULL; | 126 nap->service_port = NULL; |
| 125 nap->service_address = NULL; | 127 nap->service_address = NULL; |
| 126 nap->secure_service = NULL; | 128 nap->secure_service = NULL; |
| 129 nap->manifest_proxy = NULL; |
| 127 nap->reverse_client = NULL; | 130 nap->reverse_client = NULL; |
| 128 nap->reverse_channel_initialized = 0; | 131 nap->reverse_channel_initialized = 0; |
| 129 | 132 |
| 130 if (!NaClMutexCtor(&nap->mu)) { | 133 if (!NaClMutexCtor(&nap->mu)) { |
| 131 goto cleanup_dynamic_load_mutex; | 134 goto cleanup_dynamic_load_mutex; |
| 132 } | 135 } |
| 133 if (!NaClCondVarCtor(&nap->cv)) { | 136 if (!NaClCondVarCtor(&nap->cv)) { |
| 134 goto cleanup_mu; | 137 goto cleanup_mu; |
| 135 } | 138 } |
| 136 | 139 |
| 137 nap->vm_hole_may_exist = 0; | 140 nap->vm_hole_may_exist = 0; |
| 138 nap->threads_launching = 0; | 141 nap->threads_launching = 0; |
| 139 | 142 |
| 140 nap->module_load_status = LOAD_STATUS_UNKNOWN; | 143 nap->module_load_status = LOAD_STATUS_UNKNOWN; |
| 141 nap->module_may_start = 0; /* only when secure_service != NULL */ | 144 nap->module_may_start = 0; /* only when secure_service != NULL */ |
| 142 | 145 |
| 143 nap->name_service = (struct NaClNameService *) malloc( | 146 nap->name_service = (struct NaClNameService *) malloc( |
| 144 sizeof *nap->name_service); | 147 sizeof *nap->name_service); |
| 145 if (NULL == nap->name_service) { | 148 if (NULL == nap->name_service) { |
| 146 goto cleanup_cv; | 149 goto cleanup_cv; |
| 147 } | 150 } |
| 148 if (!NaClNameServiceCtor(nap->name_service, | 151 if (!NaClNameServiceCtor(nap->name_service, |
| 149 NaClAddrSpSquattingThreadIfFactoryFunction, | 152 NaClAddrSpSquattingThreadIfFactoryFunction, |
| 150 nap)) { | 153 (void *) nap)) { |
| 151 free(nap->name_service); | 154 free(nap->name_service); |
| 152 goto cleanup_cv; | 155 goto cleanup_cv; |
| 153 } | 156 } |
| 154 nap->name_service_conn_cap = NaClDescRef(nap->name_service-> | 157 nap->name_service_conn_cap = NaClDescRef(nap->name_service-> |
| 155 base.base.bound_and_cap[1]); | 158 base.base.bound_and_cap[1]); |
| 156 if (!NaClDefaultNameServiceInit(nap->name_service)) { | 159 if (!NaClDefaultNameServiceInit(nap->name_service)) { |
| 157 goto cleanup_name_service; | 160 goto cleanup_name_service; |
| 158 } | 161 } |
| 159 | 162 |
| 160 nap->ignore_validator_result = 0; | 163 nap->ignore_validator_result = 0; |
| (...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 struct NaClConnectionHandler *queue_head; | 1118 struct NaClConnectionHandler *queue_head; |
| 1116 struct NaClConnectionHandler **queue_insert; | 1119 struct NaClConnectionHandler **queue_insert; |
| 1117 }; | 1120 }; |
| 1118 | 1121 |
| 1119 struct NaClSimpleRevClientVtbl const kNaClSecureReverseClientVtbl; | 1122 struct NaClSimpleRevClientVtbl const kNaClSecureReverseClientVtbl; |
| 1120 | 1123 |
| 1121 | 1124 |
| 1122 int NaClSecureServiceCtor(struct NaClSecureService *self, | 1125 int NaClSecureServiceCtor(struct NaClSecureService *self, |
| 1123 struct NaClSrpcHandlerDesc const *srpc_handlers, | 1126 struct NaClSrpcHandlerDesc const *srpc_handlers, |
| 1124 struct NaClApp *nap) { | 1127 struct NaClApp *nap) { |
| 1128 NaClLog(4, |
| 1129 "Entered NaClSecureServiceCtor: self 0x%"NACL_PRIxPTR"\n", |
| 1130 (uintptr_t) self); |
| 1125 if (!NaClSimpleServiceWithSocketCtor(&self->base, | 1131 if (!NaClSimpleServiceWithSocketCtor(&self->base, |
| 1126 srpc_handlers, | 1132 srpc_handlers, |
| 1127 NaClThreadInterfaceThreadFactory, | 1133 NaClThreadInterfaceThreadFactory, |
| 1128 (void *) NULL, | 1134 (void *) NULL, |
| 1129 nap->service_port, | 1135 nap->service_port, |
| 1130 nap->service_address)) { | 1136 nap->service_address)) { |
| 1131 goto failure_simple_ctor; | 1137 goto failure_simple_ctor; |
| 1132 } | 1138 } |
| 1133 self->nap = nap; | 1139 self->nap = nap; |
| 1134 | 1140 |
| 1135 NACL_VTBL(NaClRefCount, self) = | 1141 NACL_VTBL(NaClRefCount, self) = |
| 1136 (struct NaClRefCountVtbl *) &kNaClSecureServiceVtbl; | 1142 (struct NaClRefCountVtbl *) &kNaClSecureServiceVtbl; |
| 1137 return 1; | 1143 return 1; |
| 1138 failure_simple_ctor: | 1144 failure_simple_ctor: |
| 1139 return 0; | 1145 return 0; |
| 1140 } | 1146 } |
| 1141 | 1147 |
| 1142 void NaClSecureServiceDtor(struct NaClRefCount *vself) { | 1148 void NaClSecureServiceDtor(struct NaClRefCount *vself) { |
| 1143 struct NaClSecureService *self = (struct NaClSecureService *) vself; | 1149 struct NaClSecureService *self = (struct NaClSecureService *) vself; |
| 1144 | 1150 |
| 1145 NACL_VTBL(NaClRefCount, self) = (struct NaClRefCountVtbl const *) | 1151 NACL_VTBL(NaClRefCount, self) = (struct NaClRefCountVtbl const *) |
| 1146 &kNaClSimpleServiceVtbl; | 1152 &kNaClSimpleServiceVtbl; |
| 1147 (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself); | 1153 (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself); |
| 1148 } | 1154 } |
| 1149 | 1155 |
| 1150 /* fwd */ | |
| 1151 int NaClSecureReverseClientCtor( | |
| 1152 struct NaClSecureReverseClient *self, | |
| 1153 void (*client_callback)( | |
| 1154 void *, struct NaClThreadInterface *, struct NaClDesc *), | |
| 1155 void *state, | |
| 1156 struct NaClApp *nap); | |
| 1157 | |
| 1158 /* | 1156 /* |
| 1159 * The first connection is performed by this callback handler. This | 1157 * The first connection is performed by this callback handler. This |
| 1160 * spawns a client thread that will bootstrap the other connections by | 1158 * spawns a client thread that will bootstrap the other connections by |
| 1161 * stashing the connection represented by |conn| to make reverse RPCs | 1159 * stashing the connection represented by |conn| to make reverse RPCs |
| 1162 * to ask the peer to connect to us. No thread is spawned; we just | 1160 * to ask the peer to connect to us. No thread is spawned; we just |
| 1163 * wrap access to the connection with a lock. | 1161 * wrap access to the connection with a lock. |
| 1164 * | 1162 * |
| 1165 * Subsequent connection callbacks will pass the connection to the | 1163 * Subsequent connection callbacks will pass the connection to the |
| 1166 * actual thread that made the connection request using |conn| | 1164 * actual thread that made the connection request using |conn| |
| 1167 * received in the first connection. | 1165 * received in the first connection. |
| 1168 */ | 1166 */ |
| 1169 static void NaClSecureReverseClientCallback( | 1167 static void NaClSecureReverseClientCallback( |
| 1170 void *state, | 1168 void *state, |
| 1171 struct NaClThreadInterface *tif, | 1169 struct NaClThreadInterface *tif, |
| 1172 struct NaClDesc *conn) { | 1170 struct NaClDesc *new_conn) { |
| 1173 struct NaClSecureReverseClient *self = | 1171 struct NaClSecureReverseClient *self = |
| 1174 (struct NaClSecureReverseClient *) state; | 1172 (struct NaClSecureReverseClient *) state; |
| 1175 struct NaClApp *nap = self->nap; | 1173 struct NaClApp *nap = self->nap; |
| 1176 | 1174 |
| 1177 UNREFERENCED_PARAMETER(tif); | 1175 UNREFERENCED_PARAMETER(tif); |
| 1178 | 1176 |
| 1179 NaClLog(4, "Entered NaClSecureReverseClientCallback\n"); | 1177 NaClLog(4, "Entered NaClSecureReverseClientCallback\n"); |
| 1180 | 1178 |
| 1181 NaClLog(4, " self=0x%"NACL_PRIxPTR"\n", (uintptr_t) self); | 1179 NaClLog(4, " self=0x%"NACL_PRIxPTR"\n", (uintptr_t) self); |
| 1182 NaClLog(4, " nap=0x%"NACL_PRIxPTR"\n", (uintptr_t) nap); | 1180 NaClLog(4, " nap=0x%"NACL_PRIxPTR"\n", (uintptr_t) nap); |
| 1183 NaClXMutexLock(&nap->mu); | 1181 NaClXMutexLock(&nap->mu); |
| 1184 | 1182 |
| 1185 if (nap->reverse_channel_initialized) { | 1183 if (nap->reverse_channel_initialized) { |
| 1186 NaClLog(LOG_FATAL, "Reverse channel already initialized\n"); | 1184 NaClLog(LOG_FATAL, "Reverse channel already initialized\n"); |
| 1187 } | 1185 } |
| 1188 if (!NaClSrpcClientCtor(&nap->reverse_channel, conn)) { | 1186 if (!NaClSrpcClientCtor(&nap->reverse_channel, new_conn)) { |
| 1189 NaClLog(LOG_FATAL, "Reverse channel SRPC Client Ctor failed\n"); | 1187 NaClLog(LOG_FATAL, "Reverse channel SRPC Client Ctor failed\n"); |
| 1190 } | 1188 } |
| 1191 nap->reverse_channel_initialized = 1; | 1189 nap->reverse_channel_initialized = 1; |
| 1192 | 1190 |
| 1193 NaClXCondVarBroadcast(&nap->cv); | 1191 NaClXCondVarBroadcast(&nap->cv); |
| 1194 NaClXMutexUnlock(&nap->mu); | 1192 NaClXMutexUnlock(&nap->mu); |
| 1195 | 1193 |
| 1196 NaClLog(4, "Leaving NaClSecureReverseClientCallback\n"); | 1194 NaClLog(4, "Leaving NaClSecureReverseClientCallback\n"); |
| 1197 } | 1195 } |
| 1198 | 1196 |
| 1197 /* fwd */ |
| 1198 int NaClSecureReverseClientCtor( |
| 1199 struct NaClSecureReverseClient *self, |
| 1200 void (*client_callback)( |
| 1201 void *, struct NaClThreadInterface *, struct NaClDesc *), |
| 1202 void *state, |
| 1203 struct NaClApp *nap); |
| 1204 |
| 1199 static void NaClSecureReverseClientSetup(struct NaClSrpcRpc *rpc, | 1205 static void NaClSecureReverseClientSetup(struct NaClSrpcRpc *rpc, |
| 1200 struct NaClSrpcArg **in_args, | 1206 struct NaClSrpcArg **in_args, |
| 1201 struct NaClSrpcArg **out_args, | 1207 struct NaClSrpcArg **out_args, |
| 1202 struct NaClSrpcClosure *done) { | 1208 struct NaClSrpcClosure *done) { |
| 1203 struct NaClApp *nap = | 1209 struct NaClApp *nap = |
| 1204 (struct NaClApp *) rpc->channel->server_instance_data; | 1210 (struct NaClApp *) rpc->channel->server_instance_data; |
| 1205 struct NaClSecureReverseClient *rev; | 1211 struct NaClSecureReverseClient *rev; |
| 1206 | 1212 |
| 1207 UNREFERENCED_PARAMETER(in_args); | 1213 UNREFERENCED_PARAMETER(in_args); |
| 1208 NaClLog(4, "Entered NaClSecureReverseClientSetup\n"); | 1214 NaClLog(4, "Entered NaClSecureReverseClientSetup\n"); |
| 1209 if (NULL != nap->reverse_client) { | 1215 if (NULL != nap->reverse_client) { |
| 1210 NaClLog(LOG_FATAL, "Double reverse setup RPC\n"); | 1216 NaClLog(LOG_FATAL, "Double reverse setup RPC\n"); |
| 1211 } | 1217 } |
| 1212 rev = (struct NaClSecureReverseClient *) malloc(sizeof *rev); | 1218 rev = (struct NaClSecureReverseClient *) malloc(sizeof *rev); |
| 1213 if (NULL == rev) { | 1219 if (NULL == rev) { |
| 1214 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 1220 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 1215 goto done; | 1221 goto done; |
| 1216 } | 1222 } |
| 1217 NaClLog(4, | 1223 NaClLog(4, |
| 1218 "NaClSecureReverseClientSetup: invoking" | 1224 "NaClSecureReverseClientSetup: invoking" |
| 1219 " NaClSecureReverseClientCtor\n"); | 1225 " NaClSecureReverseClientCtor\n"); |
| 1220 if (!NaClSecureReverseClientCtor(rev, | 1226 if (!NaClSecureReverseClientCtor(rev, |
| 1221 NaClSecureReverseClientCallback, | 1227 NaClSecureReverseClientCallback, |
| 1222 (void *) rev, | 1228 (void *) rev, |
| 1223 nap)) { | 1229 nap)) { |
| 1224 free(rev); | 1230 free(rev); |
| 1225 rpc->result = NACL_SRPC_RESULT_APP_ERROR; | 1231 rpc->result = NACL_SRPC_RESULT_APP_ERROR; |
| 1226 goto done; | 1232 goto done; |
| 1227 } | 1233 } |
| 1228 nap->reverse_client = rev; | 1234 nap->reverse_client = (struct NaClSecureReverseClient *) NaClRefCountRef( |
| 1235 (struct NaClRefCount *) rev); |
| 1229 out_args[0]->u.hval = NaClDescRef(rev->base.bound_and_cap[1]); | 1236 out_args[0]->u.hval = NaClDescRef(rev->base.bound_and_cap[1]); |
| 1230 rpc->result = NACL_SRPC_RESULT_OK; | 1237 rpc->result = NACL_SRPC_RESULT_OK; |
| 1231 | 1238 |
| 1239 /* |
| 1240 * Service thread takes the reference rev. |
| 1241 */ |
| 1232 if (!NaClSimpleRevClientStartServiceThread(&rev->base)) { | 1242 if (!NaClSimpleRevClientStartServiceThread(&rev->base)) { |
| 1233 NaClLog(LOG_FATAL, "Could not start reverse service thread\n"); | 1243 NaClLog(LOG_FATAL, "Could not start reverse service thread\n"); |
| 1234 } | 1244 } |
| 1235 | 1245 |
| 1236 done: | 1246 done: |
| 1237 (*done->Run)(done); | 1247 (*done->Run)(done); |
| 1238 NaClLog(4, "Leaving NaClSecureReverseClientSetup\n"); | 1248 NaClLog(4, "Leaving NaClSecureReverseClientSetup\n"); |
| 1239 } | 1249 } |
| 1240 | 1250 |
| 1241 /* | 1251 /* |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1276 * doesn't wait for a handler, we don't need a condvar. | 1286 * doesn't wait for a handler, we don't need a condvar. |
| 1277 * | 1287 * |
| 1278 * We do not need to serialize on the handlers, since the | 1288 * We do not need to serialize on the handlers, since the |
| 1279 * RPC-server/IMC-client implementation should not distinguish one | 1289 * RPC-server/IMC-client implementation should not distinguish one |
| 1280 * connection from another: it is okay for two handlers to be | 1290 * connection from another: it is okay for two handlers to be |
| 1281 * inserted, and two connection request RPCs to be preformed | 1291 * inserted, and two connection request RPCs to be preformed |
| 1282 * (sequentially, since they are over a single channel), and have the | 1292 * (sequentially, since they are over a single channel), and have the |
| 1283 * server side spawn threads that asynchronously connect twice, in the | 1293 * server side spawn threads that asynchronously connect twice, in the |
| 1284 * "incorrect" order, etc. | 1294 * "incorrect" order, etc. |
| 1285 */ | 1295 */ |
| 1286 static | |
| 1287 int NaClSecureReverseClientInsertHandler( | 1296 int NaClSecureReverseClientInsertHandler( |
| 1288 struct NaClSecureReverseClient *self, | 1297 struct NaClSecureReverseClient *self, |
| 1289 void (*h)(void *, | 1298 void (*handler)( |
| 1290 struct NaClThreadInterface *, | 1299 void *handlr_state, |
| 1291 struct NaClDesc *), | 1300 struct NaClThreadInterface *thread_if, |
| 1292 void *d) { | 1301 struct NaClDesc *new_conn), |
| 1302 void *handler_state) { |
| 1293 int retval; | 1303 int retval; |
| 1294 | 1304 |
| 1295 NaClXMutexLock(&self->mu); | 1305 NaClXMutexLock(&self->mu); |
| 1296 retval = NaClSecureReverseClientInsertHandler_mu(self, h, d); | 1306 retval = NaClSecureReverseClientInsertHandler_mu(self, |
| 1307 handler, handler_state); |
| 1297 NaClXMutexUnlock(&self->mu); | 1308 NaClXMutexUnlock(&self->mu); |
| 1298 return retval; | 1309 return retval; |
| 1299 } | 1310 } |
| 1300 | 1311 |
| 1301 static | 1312 static |
| 1302 struct NaClConnectionHandler *NaClSecureReverseClientPopHandler( | 1313 struct NaClConnectionHandler *NaClSecureReverseClientPopHandler( |
| 1303 struct NaClSecureReverseClient *self) { | 1314 struct NaClSecureReverseClient *self) { |
| 1304 struct NaClConnectionHandler *head; | 1315 struct NaClConnectionHandler *head; |
| 1305 | 1316 |
| 1306 NaClLog(4, "Entered NaClSecureReverseClientPopHandler, acquiring lock\n"); | 1317 NaClLog(4, "Entered NaClSecureReverseClientPopHandler, acquiring lock\n"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1431 | 1442 |
| 1432 int NaClSecureServiceConnectionFactory( | 1443 int NaClSecureServiceConnectionFactory( |
| 1433 struct NaClSimpleService *vself, | 1444 struct NaClSimpleService *vself, |
| 1434 struct NaClDesc *conn, | 1445 struct NaClDesc *conn, |
| 1435 struct NaClSimpleServiceConnection **out) { | 1446 struct NaClSimpleServiceConnection **out) { |
| 1436 struct NaClSecureService *self = | 1447 struct NaClSecureService *self = |
| 1437 (struct NaClSecureService *) vself; | 1448 (struct NaClSecureService *) vself; |
| 1438 | 1449 |
| 1439 /* our instance_data is not connection specific */ | 1450 /* our instance_data is not connection specific */ |
| 1440 return NaClSimpleServiceConnectionFactoryWithInstanceData( | 1451 return NaClSimpleServiceConnectionFactoryWithInstanceData( |
| 1441 vself, conn, (void*) self->nap, out); | 1452 vself, conn, (void *) self->nap, out); |
| 1442 } | 1453 } |
| 1443 | 1454 |
| 1444 int NaClSecureServiceAcceptAndSpawnHandler(struct NaClSimpleService *vself) { | 1455 int NaClSecureServiceAcceptAndSpawnHandler(struct NaClSimpleService *vself) { |
| 1445 int rv; | 1456 int rv; |
| 1446 | 1457 |
| 1447 NaClLog(4, | 1458 NaClLog(4, |
| 1448 "NaClSecureServiceAcceptAndSpawnHandler: invoking base class vfn\n"); | 1459 "NaClSecureServiceAcceptAndSpawnHandler: invoking base class vfn\n"); |
| 1449 rv = (*kNaClSimpleServiceVtbl.AcceptAndSpawnHandler)(vself); | 1460 rv = (*kNaClSimpleServiceVtbl.AcceptAndSpawnHandler)(vself); |
| 1450 if (0 != rv) { | 1461 if (0 != rv) { |
| 1451 NaClLog(LOG_FATAL, | 1462 NaClLog(LOG_FATAL, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1479 NaClSecureServiceRpcHandler, | 1490 NaClSecureServiceRpcHandler, |
| 1480 }; | 1491 }; |
| 1481 | 1492 |
| 1482 struct NaClSimpleRevClientVtbl const kNaClSecureReverseClientVtbl = { | 1493 struct NaClSimpleRevClientVtbl const kNaClSecureReverseClientVtbl = { |
| 1483 { | 1494 { |
| 1484 NaClSecureReverseClientDtor, | 1495 NaClSecureReverseClientDtor, |
| 1485 }, | 1496 }, |
| 1486 }; | 1497 }; |
| 1487 | 1498 |
| 1488 | 1499 |
| 1489 static void WINAPI ReverseTestThread(void *thread_state) { | 1500 static void WINAPI ReverseSetupThread(void *thread_state) { |
| 1490 struct NaClApp *nap = (struct NaClApp *) thread_state; | 1501 struct NaClApp *nap = (struct NaClApp *) thread_state; |
| 1491 NaClSrpcError rpc_result; | 1502 NaClSrpcError rpc_result; |
| 1492 | 1503 |
| 1493 /* wait for reverse connection */ | 1504 /* wait for reverse connection */ |
| 1494 NaClLog(1, "ReverseTestThread\n"); | 1505 NaClLog(1, "ReverseSetupThread\n"); |
| 1495 NaClXMutexLock(&nap->mu); | 1506 NaClXMutexLock(&nap->mu); |
| 1496 while (!nap->reverse_channel_initialized) { | 1507 while (!nap->reverse_channel_initialized) { |
| 1497 NaClLog(1, "ReverseTestThread waiting\n"); | 1508 NaClLog(1, "ReverseSetupThread waiting\n"); |
| 1498 NaClXCondVarWait(&nap->cv, &nap->mu); | 1509 NaClXCondVarWait(&nap->cv, &nap->mu); |
| 1499 } | 1510 } |
| 1500 NaClLog(1, "ReverseTestThread initialized, making rpc\n"); | 1511 NaClLog(1, "ReverseSetupThread initialized, making rpc\n"); |
| 1501 rpc_result = NaClSrpcInvokeBySignature(&nap->reverse_channel, | 1512 rpc_result = NaClSrpcInvokeBySignature(&nap->reverse_channel, |
| 1502 "test:s:", "Hello world"); | 1513 NACL_REVERSE_CONTROL_TEST, |
| 1514 "Hello world"); |
| 1503 if (NACL_SRPC_RESULT_OK != rpc_result) { | 1515 if (NACL_SRPC_RESULT_OK != rpc_result) { |
| 1504 NaClLog(LOG_ERROR, | 1516 NaClLog(LOG_ERROR, |
| 1505 "ReverseTestThread, test:s: rpc_result %d\n", | 1517 "ReverseSetupThread, test:s: rpc_result %d\n", |
| 1506 rpc_result); | 1518 rpc_result); |
| 1507 } | 1519 } |
| 1508 NaClLog(4, | 1520 NaClLog(4, |
| 1509 "Hello world should be logged browser side, rpc_result %d.\n", | 1521 "Hello world should be logged browser side, rpc_result %d.\n", |
| 1510 rpc_result); | 1522 rpc_result); |
| 1511 rpc_result = NaClSrpcInvokeBySignature(&nap->reverse_channel, | 1523 rpc_result = NaClSrpcInvokeBySignature(&nap->reverse_channel, |
| 1512 "revlog:s:", | 1524 NACL_REVERSE_CONTROL_LOG, |
| 1513 ("Log message that should show up" | 1525 ("Log message that should show up" |
| 1514 " on the JavaScript console")); | 1526 " on the JavaScript console")); |
| 1515 NaClLog(4, "revlog returned %d.\n", rpc_result); | 1527 NaClLog(4, "revlog returned %d.\n", rpc_result); |
| 1516 if (NACL_SRPC_RESULT_OK != rpc_result) { | 1528 if (NACL_SRPC_RESULT_OK != rpc_result) { |
| 1517 NaClLog(LOG_ERROR, | 1529 NaClLog(LOG_ERROR, |
| 1518 "ReverseTestThread, revlog:s: rpc_result %d\n", | 1530 "ReverseSetupThread, revlog:s: rpc_result %d\n", |
| 1519 rpc_result); | 1531 rpc_result); |
| 1520 } | 1532 } |
| 1521 NaClXMutexUnlock(&nap->mu); | 1533 NaClXMutexUnlock(&nap->mu); |
| 1534 |
| 1535 NaClThreadDtor(&nap->reverse_setup_thread); |
| 1522 } | 1536 } |
| 1523 | 1537 |
| 1524 | 1538 |
| 1525 void NaClSecureCommandChannel(struct NaClApp *nap) { | 1539 void NaClSecureCommandChannel(struct NaClApp *nap) { |
| 1526 struct NaClSecureService *secure_command_server; | 1540 struct NaClSecureService *secure_command_server; |
| 1527 | 1541 |
| 1528 static struct NaClSrpcHandlerDesc const secure_handlers[] = { | 1542 static struct NaClSrpcHandlerDesc const secure_handlers[] = { |
| 1529 { "hard_shutdown::", NaClSecureChannelShutdownRpc, }, | 1543 { "hard_shutdown::", NaClSecureChannelShutdownRpc, }, |
| 1530 { "start_module::i", NaClSecureChannelStartModuleRpc, }, | 1544 { "start_module::i", NaClSecureChannelStartModuleRpc, }, |
| 1531 { "log:is:", NaClSecureChannelLog, }, | 1545 { "log:is:", NaClSecureChannelLog, }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1550 } | 1564 } |
| 1551 nap->secure_service = secure_command_server; | 1565 nap->secure_service = secure_command_server; |
| 1552 | 1566 |
| 1553 NaClLog(4, "NaClSecureCommandChannel: starting service thread\n"); | 1567 NaClLog(4, "NaClSecureCommandChannel: starting service thread\n"); |
| 1554 if (!NaClSimpleServiceStartServiceThread((struct NaClSimpleService *) | 1568 if (!NaClSimpleServiceStartServiceThread((struct NaClSimpleService *) |
| 1555 secure_command_server)) { | 1569 secure_command_server)) { |
| 1556 NaClLog(LOG_FATAL, | 1570 NaClLog(LOG_FATAL, |
| 1557 "Could not start secure command channel service thread\n"); | 1571 "Could not start secure command channel service thread\n"); |
| 1558 } | 1572 } |
| 1559 | 1573 |
| 1560 if (1) { | 1574 NaClThreadCtor(&nap->reverse_setup_thread, ReverseSetupThread, nap, |
| 1561 struct NaClThread thr; | 1575 NACL_KERN_STACK_SIZE); |
| 1562 | |
| 1563 NaClThreadCtor(&thr, ReverseTestThread, nap, NACL_KERN_STACK_SIZE); | |
| 1564 } | |
| 1565 | 1576 |
| 1566 NaClLog(4, "Leaving NaClSecureCommandChannel\n"); | 1577 NaClLog(4, "Leaving NaClSecureCommandChannel\n"); |
| 1567 } | 1578 } |
| 1568 | 1579 |
| 1569 | 1580 |
| 1570 void NaClVmHoleWaitToStartThread(struct NaClApp *nap) { | 1581 void NaClVmHoleWaitToStartThread(struct NaClApp *nap) { |
| 1571 NaClXMutexLock(&nap->mu); | 1582 NaClXMutexLock(&nap->mu); |
| 1572 | 1583 |
| 1573 /* ensure no virtual memory hole may appear */ | 1584 /* ensure no virtual memory hole may appear */ |
| 1574 while (nap->vm_hole_may_exist) { | 1585 while (nap->vm_hole_may_exist) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 NaClSandboxMemoryStartForValgrind(mem_start); | 1635 NaClSandboxMemoryStartForValgrind(mem_start); |
| 1625 | 1636 |
| 1626 #ifdef __GNUC__ | 1637 #ifdef __GNUC__ |
| 1627 _ovly_debug_event (); | 1638 _ovly_debug_event (); |
| 1628 #endif | 1639 #endif |
| 1629 } | 1640 } |
| 1630 | 1641 |
| 1631 void NaClGdbHook(struct NaClApp const *nap) { | 1642 void NaClGdbHook(struct NaClApp const *nap) { |
| 1632 StopForDebuggerInit(nap->mem_start); | 1643 StopForDebuggerInit(nap->mem_start); |
| 1633 } | 1644 } |
| OLD | NEW |