static void NaClManifestProxyConnectionDtor(struct NaClRefCount *vself) { struct NaClManifestProxyConnection *self = (struct NaClManifestProxyConnection *) vself; NaClLog(4, "Entered NaClManifestProxyConnectionDtor: self 0x%"NACL_PRIxPTR"\n", (uintptr_t) self); NaClXMutexLock(&self->mu); while (!self->channel_initialized) { NaClLog(4, "NaClManifestProxyConnectionDtor:" " waiting for connection initialization\n"); NaClXCondVarWait(&self->cv, &self->mu); } NaClXMutexUnlock(&self->mu); NaClLog(4, "NaClManifestProxyConnectionDtor: dtoring\n"); NaClCondVarDtor(&self->cv); NaClMutexDtor(&self->mu); NaClSrpcDtor(&self->client_channel); NACL_VTBL(NaClSimpleServiceConnection, self) = &kNaClSimpleServiceConnectionVtbl; (*NACL_VTBL(NaClRefCount, self)->Dtor)(vself); }
unsigned long get_good_seed(void) { int ns; int connected_socket; NaClSrpcChannel ns_channel; NaClSrpcError rpc_result; int status; int rng; unsigned long seed; ns = -1; if (-1 == nacl_nameservice(&ns)) { fprintf(stderr, "nacl_nameservice failed\n"); abort(); } connected_socket = imc_connect(ns); assert(-1 != connected_socket); if (!NaClSrpcClientCtor(&ns_channel, connected_socket)) { fprintf(stderr, "SRPC client channel ctor failed\n"); abort(); } (void) close(ns); rpc_result = NaClSrpcInvokeBySignature(&ns_channel, NACL_NAME_SERVICE_LOOKUP, "SecureRandom", O_RDONLY, &status, &rng); assert(NACL_SRPC_RESULT_OK == rpc_result); assert(NACL_NAME_SERVICE_SUCCESS == status); assert(sizeof seed == read(rng, &seed, sizeof seed)); close(rng); NaClSrpcDtor(&ns_channel); return seed; }
/* * ServerLoop processes the RPCs that this descriptor listens to. */ static int ServerLoop(NaClSrpcService* service, NaClSrpcImcDescType socket_desc, void* instance_data) { NaClSrpcChannel* channel = NULL; int retval = 0; NaClSrpcLog(2, "ServerLoop(service=%p, socket_desc=%p, instance_data=%p)\n", (void*) service, (void*) socket_desc, (void*) instance_data); /* * SrpcChannel objects can be large due to the buffers they contain. * Hence they should not be allocated on a thread stack. */ channel = (NaClSrpcChannel*) malloc(sizeof(*channel)); if (NULL == channel) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "ServerLoop: channel malloc failed\n"); goto cleanup; } /* Create an SRPC server listening on the new file descriptor. */ if (!NaClSrpcServerCtor(channel, socket_desc, service, instance_data)) { NaClSrpcLog(NACL_SRPC_LOG_ERROR, "ServerLoop: NaClSrpcServerCtor failed\n"); goto cleanup; } /* * Loop receiving RPCs and processing them. * The loop stops when a method requests a break out of the loop * or the IMC layer is unable to satisfy a request. */ NaClSrpcRpcWait(channel, NULL); retval = 1; NaClSrpcLog(2, "ServerLoop(service=%p, socket_desc=%p, instance_data=%p) done\n", (void*) service, (void*) socket_desc, (void*) instance_data); cleanup: NaClSrpcDtor(channel); free(channel); return retval; }
int main(int argc, char* argv[]) { int result; NaClHandle pair[2]; #ifdef __native_client__ int imc_desc[2]; #else struct NaClDescImcDesc* imc_desc[2]; #endif struct NaClThread thr; NaClSrpcChannel channel; NaClSrpcError error; struct ServiceThreadArgs* threadArg; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); NaClSrpcModuleInit(); if (0 != NaClSocketPair(pair)) { failWithErrno("SocketPair"); } #ifdef __native_client__ imc_desc[0] = pair[0]; imc_desc[1] = pair[1]; #else NaClNrdAllModulesInit(); imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0])); if (0 == imc_desc[0]) { failWithErrno("calloc"); } imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1])); if (0 == imc_desc[1]) { failWithErrno("calloc"); } if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) { failWithErrno("NaClDescImcDescCtor"); } if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) { failWithErrno("NaClDescImcDescCtor"); } #endif threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg)); if (NULL == threadArg) { failWithErrno("calloc for threadArg"); } threadArg->desc = (NaClSrpcImcDescType)imc_desc[0]; if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) { failWithErrno("NaClThreadCtor"); } if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) { failWithErrno("NaClSrpcClientCtor"); } error = NaClSrpcInvokeBySignature(&channel, "getNum::i", &result); if (NACL_SRPC_RESULT_OK != error) { fprintf(stderr, "SRPC call to getNum::i failed: %s\n", NaClSrpcErrorString(error)); exit(EXIT_FAILURE); } if (TEST_NUM != result) { fprintf(stderr, "expected: %d, got: %d\n", TEST_NUM, result); exit(EXIT_FAILURE); } NaClSrpcDtor(&channel); #ifdef __native_client__ close(imc_desc[1]); #else NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]); #endif NaClThreadJoin(&thr); NaClSrpcModuleFini(); return 0; }
int main(int argc, char* argv[]) { nacl_abi_size_t char_array_count; char* char_array_carr; NaClHandle pair[2]; #ifdef __native_client__ int imc_desc[2]; #else struct NaClDescImcDesc* imc_desc[2]; #endif struct NaClThread thr; NaClSrpcChannel channel; NaClSrpcError error; struct ServiceThreadArgs* threadArg; UNREFERENCED_PARAMETER(argc); UNREFERENCED_PARAMETER(argv); NaClSrpcModuleInit(); if (0 != NaClSocketPair(pair)) { failWithErrno("SocketPair"); } #ifdef __native_client__ imc_desc[0] = pair[0]; imc_desc[1] = pair[1]; #else NaClNrdAllModulesInit(); imc_desc[0] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[0])); if (0 == imc_desc[0]) { failWithErrno("calloc"); } imc_desc[1] = (struct NaClDescImcDesc*) calloc(1, sizeof(*imc_desc[1])); if (0 == imc_desc[1]) { failWithErrno("calloc"); } if (!NaClDescImcDescCtor(imc_desc[0], pair[0])) { failWithErrno("NaClDescImcDescCtor"); } if (!NaClDescImcDescCtor(imc_desc[1], pair[1])) { failWithErrno("NaClDescImcDescCtor"); } #endif threadArg = (struct ServiceThreadArgs*) calloc(1, sizeof(*threadArg)); if (NULL == threadArg) { failWithErrno("calloc for threadArg"); } threadArg->desc = (NaClSrpcImcDescType)imc_desc[0]; if (!NaClThreadCreateJoinable(&thr, serviceThread, threadArg, 128*1024)) { failWithErrno("NaClThreadCtor"); } if (!NaClSrpcClientCtor(&channel, (NaClSrpcImcDescType) imc_desc[1])) { failWithErrno("NaClSrpcClientCtor"); } char_array_count = TEST_ARRAY_LENGTH; char_array_carr = (char*) calloc(TEST_ARRAY_LENGTH, sizeof(char)); if (!char_array_carr) { failWithErrno("calloc for char_array"); } memset(char_array_carr, TEST_NUM, TEST_ARRAY_LENGTH); error = NaClSrpcInvokeBySignature(&channel, "putArr:C:", char_array_count, char_array_carr); if (NACL_SRPC_RESULT_OK != error) { fprintf(stderr, "SRPC call to putArr:C: failed: %s\n", NaClSrpcErrorString(error)); exit(EXIT_FAILURE); } free(char_array_carr); NaClSrpcDtor(&channel); #ifdef __native_client__ close(imc_desc[1]); #else NaClDescUnref((NaClSrpcImcDescType)imc_desc[1]); #endif NaClThreadJoin(&thr); NaClSrpcModuleFini(); return 0; }
void NaClPluginLowLevelInitializationCompleteInternal(void) { int nameservice_conn_desc; int kernel_service_conn_cap_desc = -1; int kernel_service_desc; struct NaClSrpcChannel srpc_channel; int status; NaClLog(4, "Entered NaClPluginLowLevelInitializationComplete\n"); if (-1 != gNaClNameServiceConnCapDesc) { NaClLog(LOG_ERROR, "Double call to NaClPluginLowLevelInitializationComplete?\n"); return; } /* * The existence of the bootstrap nameservice is independent of * whether NaCl is running as a standalone application or running as * a untrusted Pepper plugin, browser extension environment. */ if (-1 == nacl_nameservice(&gNaClNameServiceConnCapDesc)) { NaClLog(LOG_FATAL, "NaClPluginLowLevelInitializationComplete: no name service?!?\n"); } nameservice_conn_desc = imc_connect(gNaClNameServiceConnCapDesc); if (-1 == nameservice_conn_desc) { NaClLog(LOG_FATAL, "Could not connect to bootstrap name service\n"); } if (!NaClSrpcClientCtor(&srpc_channel, nameservice_conn_desc)) { (void) close(nameservice_conn_desc); NaClLog(LOG_FATAL, "SRPC channel ctor to name service failed\n"); } if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( &srpc_channel, NACL_NAME_SERVICE_LOOKUP, "KernelService", O_RDWR, &status, &kernel_service_conn_cap_desc)) { NaClSrpcDtor(&srpc_channel); NaClLog(LOG_FATAL, "Name service lookup RPC for KernelService failed\n"); } NaClSrpcDtor(&srpc_channel); if (-1 == kernel_service_conn_cap_desc) { NaClLog(LOG_FATAL, "Name service lookup for KernelService failed, %d\n", status); } if (-1 == (kernel_service_desc = imc_connect(kernel_service_conn_cap_desc))) { (void) close(kernel_service_conn_cap_desc); NaClLog(LOG_FATAL, "Connect to KernelService failed\n"); } (void) close(kernel_service_conn_cap_desc); if (!NaClSrpcClientCtor(&srpc_channel, kernel_service_desc)) { (void) close(kernel_service_desc); NaClLog(LOG_FATAL, "SRPC channel ctor to KernelService failed\n"); } if (NACL_SRPC_RESULT_OK != NaClSrpcInvokeBySignature( &srpc_channel, NACL_KERNEL_SERVICE_INITIALIZATION_COMPLETE)) { NaClLog(LOG_FATAL, "KernelService init_done RPC failed!\n"); } NaClSrpcDtor(&srpc_channel); }