Chromium Code Reviews| 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 "native_client/src/include/portability_io.h" | |
| 8 | |
|
noelallen_use_chromium
2011/06/14 02:25:45
Why is portability_io.h included before string.h?
bsy
2011/06/14 20:30:03
several of our portability* files had to be includ
noelallen_use_chromium
2011/06/14 22:08:14
I mentioned portability vs portability_io, because
| |
| 9 #include <string.h> | |
| 10 | |
| 7 #include "native_client/src/trusted/reverse_service/reverse_service.h" | 11 #include "native_client/src/trusted/reverse_service/reverse_service.h" |
| 8 | 12 |
| 9 #include "native_client/src/include/nacl_compiler_annotations.h" | 13 #include "native_client/src/include/nacl_compiler_annotations.h" |
| 10 #include "native_client/src/include/nacl_scoped_ptr.h" | 14 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 11 | 15 |
| 12 #include "native_client/src/shared/platform/nacl_log.h" | 16 #include "native_client/src/shared/platform/nacl_log.h" |
| 13 #include "native_client/src/shared/platform/nacl_sync.h" | 17 #include "native_client/src/shared/platform/nacl_sync.h" |
| 14 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 18 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 15 #include "native_client/src/shared/platform/nacl_threads.h" | 19 #include "native_client/src/shared/platform/nacl_threads.h" |
| 16 #include "native_client/src/shared/srpc/nacl_srpc.h" | 20 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 17 | 21 |
| 22 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" | |
| 23 | |
| 18 namespace { | 24 namespace { |
| 19 | 25 |
| 20 void Test(NaClSrpcRpc* rpc, | 26 void Test(NaClSrpcRpc* rpc, |
| 21 NaClSrpcArg** in_args, | 27 NaClSrpcArg** in_args, |
| 22 NaClSrpcArg** out_args, | 28 NaClSrpcArg** out_args, |
| 23 NaClSrpcClosure* done) { | 29 NaClSrpcClosure* done) { |
| 24 char *msg = in_args[0]->arrays.str; | 30 char *msg = in_args[0]->arrays.str; |
| 25 UNREFERENCED_PARAMETER(out_args); | 31 UNREFERENCED_PARAMETER(out_args); |
| 26 // use rpc->channel rather than rpc->channel->server_instance_data | 32 // use rpc->channel rather than rpc->channel->server_instance_data |
| 27 // to show that Test RPCs arrive in different channels. | 33 // to show that Test RPCs arrive in different channels. |
| 28 NaClLog(1, "Test: [%"NACL_PRIxPTR"] %s\n", | 34 NaClLog(1, "Test: [%"NACL_PRIxPTR"] %s\n", |
| 29 reinterpret_cast<uintptr_t>(rpc->channel), msg); | 35 reinterpret_cast<uintptr_t>(rpc->channel), msg); |
| 30 rpc->result = NACL_SRPC_RESULT_OK; | 36 rpc->result = NACL_SRPC_RESULT_OK; |
| 31 done->Run(done); | 37 done->Run(done); |
| 32 } | 38 } |
| 33 | 39 |
| 34 void AddChannel(NaClSrpcRpc* rpc, | 40 void AddChannel(NaClSrpcRpc* rpc, |
| 35 NaClSrpcArg** in_args, | 41 NaClSrpcArg** in_args, |
| 36 NaClSrpcArg** out_args, | 42 NaClSrpcArg** out_args, |
| 37 NaClSrpcClosure* done) { | 43 NaClSrpcClosure* done) { |
| 38 nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( | 44 nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( |
| 39 rpc->channel->server_instance_data); | 45 rpc->channel->server_instance_data); |
| 46 | |
| 40 UNREFERENCED_PARAMETER(in_args); | 47 UNREFERENCED_PARAMETER(in_args); |
| 41 UNREFERENCED_PARAMETER(out_args); | 48 |
| 42 NaClLog(4, "Entered AddChannel\n"); | 49 NaClLog(4, "Entered AddChannel\n"); |
| 43 out_args[0]->u.bval = service->Start(); | 50 service->Start(); |
| 51 out_args[0]->u.bval = 1; | |
| 44 NaClLog(4, "Leaving AddChannel\n"); | 52 NaClLog(4, "Leaving AddChannel\n"); |
| 45 rpc->result = NACL_SRPC_RESULT_OK; | 53 rpc->result = NACL_SRPC_RESULT_OK; |
| 46 done->Run(done); | 54 done->Run(done); |
| 47 } | 55 } |
| 48 | 56 |
| 49 void RevLog(NaClSrpcRpc* rpc, | 57 void RevLog(NaClSrpcRpc* rpc, |
| 50 NaClSrpcArg** in_args, | 58 NaClSrpcArg** in_args, |
| 51 NaClSrpcArg** out_args, | 59 NaClSrpcArg** out_args, |
| 52 NaClSrpcClosure* done) { | 60 NaClSrpcClosure* done) { |
| 53 nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( | 61 nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( |
| 54 rpc->channel->server_instance_data); | 62 rpc->channel->server_instance_data); |
| 55 UNREFERENCED_PARAMETER(out_args); | 63 UNREFERENCED_PARAMETER(out_args); |
| 56 char* message = in_args[0]->arrays.str; | 64 char* message = in_args[0]->arrays.str; |
| 57 | 65 |
| 58 if (NULL == service->reverse_interface()) { | 66 if (NULL == service->reverse_interface()) { |
| 59 NaClLog(1, "Log RPC, no reverse_interface. Message: %s\n", message); | 67 NaClLog(1, "Log RPC, no reverse_interface. Message: %s\n", message); |
| 60 } else { | 68 } else { |
| 61 service->reverse_interface()->Log(message); | 69 service->reverse_interface()->Log(message); |
| 62 } | 70 } |
| 63 done->Run(done); | 71 done->Run(done); |
| 64 } | 72 } |
| 65 | 73 |
| 74 // Manifest name service, internal APIs. | |
| 75 // | |
| 76 // Manifest file lookups result in read-only file descriptors with a | |
| 77 // handle. When the descriptor is closed, the service runtime must | |
| 78 // inform the plugin of this using the handle, so that the File object | |
| 79 // reference can be closed (thereby allowing the browser to delete or | |
| 80 // otherwise garbage collect the file). Files, being from the | |
| 81 // manifest, cannot be deleted. The manifest is also a read-only | |
| 82 // object, so no new entries can be made to it. | |
| 83 // | |
| 84 // Read-only proxies do not require quota support per se, since we do | |
| 85 // not limit read bandwidth. Quota support is needed for storage | |
| 86 // limits, though could also be used to limit write bandwidth (prevent | |
| 87 // disk output saturation, limit malicious code's ability to cause | |
| 88 // disk failures, especially with flash disks with limited write | |
| 89 // cycles). | |
| 90 | |
| 91 // NACL_NAME_SERVICE_LIST list::C -- enumerate all names in the manifest | |
| 92 void ManifestListRpc(NaClSrpcRpc* rpc, | |
| 93 NaClSrpcArg** in_args, | |
| 94 NaClSrpcArg** out_args, | |
| 95 NaClSrpcClosure* done) { | |
| 96 size_t nbytes = out_args[0]->u.count; | |
| 97 char* dest = out_args[0]->arrays.carr; | |
| 98 | |
|
noelallen_use_chromium
2011/06/14 02:25:45
No NaClLog?
| |
| 99 UNREFERENCED_PARAMETER(in_args); | |
| 100 // temporary test return value. TODO(bsy) hook up to real manifest info | |
| 101 out_args[0]->u.count = SNPRINTF(dest, nbytes, | |
| 102 "This is a reply from the manifest reverse" | |
| 103 " service in the plugin."); | |
| 104 rpc->result = NACL_SRPC_RESULT_OK; | |
| 105 done->Run(done); | |
| 106 } | |
| 107 | |
| 108 // NACL_NAME_SERVICE_LOOKUP lookup:si:ihC -- look up by string name, | |
| 109 // resulting in a handle (if name is in the preimage), a object proxy | |
| 110 // handle, and an error code. | |
| 111 void ManifestLookupRpc(NaClSrpcRpc* rpc, | |
| 112 NaClSrpcArg** in_args, | |
| 113 NaClSrpcArg** out_args, | |
| 114 NaClSrpcClosure* done) { | |
| 115 char* fname = in_args[0]->arrays.str; | |
| 116 int flags = in_args[0]->u.ival; | |
| 117 | |
| 118 NaClLog(0, "ManifestLookupRpc: %s, %d\n", fname, flags); | |
| 119 out_args[0]->u.ival = 0; // ok | |
| 120 out_args[1]->u.hval = (struct NaClDesc*) NaClDescInvalidMake(); | |
| 121 out_args[2]->u.count = 10; | |
|
noelallen_use_chromium
2011/06/14 02:25:45
Either u.count above should be set as sizeof('stri
bsy
2011/06/14 20:30:03
this is stub code that will be removed once the ma
| |
| 122 strncpy(out_args[2]->arrays.carr, "123456789", 10); | |
| 123 rpc->result = NACL_SRPC_RESULT_OK; | |
| 124 done->Run(done); | |
| 125 } | |
| 126 | |
| 127 // unref:C:i -- dereferences the file by object proxy handle. The | |
| 128 // file descriptor should have been closed. | |
| 129 void ManifestUnrefRpc(NaClSrpcRpc* rpc, | |
| 130 NaClSrpcArg** in_args, | |
| 131 NaClSrpcArg** out_args, | |
| 132 NaClSrpcClosure* done) { | |
| 133 char* proxy_handle = in_args[0]->arrays.carr; | |
| 134 | |
| 135 NaClLog(0, "ManifestUnrefRpc: %s\n", proxy_handle); | |
| 136 out_args[0]->u.ival = 0; // ok | |
| 137 rpc->result = NACL_SRPC_RESULT_OK; | |
| 138 done->Run(done); | |
| 139 } | |
| 140 | |
| 66 } // namespace | 141 } // namespace |
| 67 | 142 |
| 68 namespace nacl { | 143 namespace nacl { |
| 69 | 144 |
| 70 // need NaClThreadIfFactoryFunction that keeps "this" to do counting | 145 // need NaClThreadIfFactoryFunction that keeps "this" to do counting |
| 71 | 146 |
| 72 struct ReverseCountingThreadInterface { | 147 struct ReverseCountingThreadInterface { |
| 73 struct NaClThreadInterface base NACL_IS_REFCOUNT_SUBCLASS; | 148 struct NaClThreadInterface base NACL_IS_REFCOUNT_SUBCLASS; |
| 74 nacl::ReverseService* rev; | 149 nacl::ReverseService* rev; |
| 75 }; | 150 }; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 180 }, | 255 }, |
| 181 NaClThreadInterfaceStartThread, | 256 NaClThreadInterfaceStartThread, |
| 182 ReverseThreadIfLaunchCallback, | 257 ReverseThreadIfLaunchCallback, |
| 183 ReverseThreadIfExit, | 258 ReverseThreadIfExit, |
| 184 }; | 259 }; |
| 185 | 260 |
| 186 NaClSrpcHandlerDesc const ReverseService::handlers[] = { | 261 NaClSrpcHandlerDesc const ReverseService::handlers[] = { |
| 187 { "test:s:", Test, }, | 262 { "test:s:", Test, }, |
| 188 { "revlog:s:", RevLog, }, | 263 { "revlog:s:", RevLog, }, |
| 189 { "add_channel::b", AddChannel, }, | 264 { "add_channel::b", AddChannel, }, |
| 265 { NACL_MANIFEST_LIST, ManifestListRpc, }, | |
| 266 { NACL_MANIFEST_LOOKUP, ManifestLookupRpc, }, | |
| 267 { NACL_MANIFEST_UNREF, ManifestUnrefRpc, }, | |
| 190 { NULL, NULL, }, | 268 { NULL, NULL, }, |
| 191 }; | 269 }; |
| 192 | 270 |
| 193 ReverseService::ReverseService(nacl::DescWrapper* conn_cap, | 271 ReverseService::ReverseService(nacl::DescWrapper* conn_cap, |
| 194 ReverseInterface* rif) | 272 ReverseInterface* rif) |
| 195 : service_socket_(NULL), | 273 : service_socket_(NULL), |
| 196 reverse_interface_(rif), | 274 reverse_interface_(rif), |
| 197 thread_count_(0) { | 275 thread_count_(0) { |
| 198 /* | 276 /* |
| 199 * We wait for service threads to exit before dtor'ing, so the | 277 * We wait for service threads to exit before dtor'ing, so the |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 213 ReverseService::~ReverseService() { | 291 ReverseService::~ReverseService() { |
| 214 if (thread_count_ != 0) { | 292 if (thread_count_ != 0) { |
| 215 NaClLog(LOG_FATAL, "ReverseService dtor when thread count is nonzero\n"); | 293 NaClLog(LOG_FATAL, "ReverseService dtor when thread count is nonzero\n"); |
| 216 } | 294 } |
| 217 NaClCondVarDtor(&cv_); | 295 NaClCondVarDtor(&cv_); |
| 218 NaClMutexDtor(&mu_); | 296 NaClMutexDtor(&mu_); |
| 219 } | 297 } |
| 220 | 298 |
| 221 | 299 |
| 222 bool ReverseService::Start() { | 300 bool ReverseService::Start() { |
| 301 NaClLog(4, "Entered ReverseService::Start\n"); | |
| 223 return service_socket_->StartService(reinterpret_cast<void*>(this)); | 302 return service_socket_->StartService(reinterpret_cast<void*>(this)); |
| 224 } | 303 } |
| 225 | 304 |
| 226 void ReverseService::WaitForServiceThreadsToExit() { | 305 void ReverseService::WaitForServiceThreadsToExit() { |
| 227 NaClLog(4, "ReverseService::WaitForServiceThreadsToExit\n"); | 306 NaClLog(4, "ReverseService::WaitForServiceThreadsToExit\n"); |
| 228 NaClXMutexLock(&mu_); | 307 NaClXMutexLock(&mu_); |
| 229 while (0 != thread_count_) { | 308 while (0 != thread_count_) { |
| 230 NaClXCondVarWait(&cv_, &mu_); | 309 NaClXCondVarWait(&cv_, &mu_); |
| 231 NaClLog(5, "ReverseService::WaitForServiceThreadsToExit: woke up\n"); | 310 NaClLog(5, "ReverseService::WaitForServiceThreadsToExit: woke up\n"); |
| 232 } | 311 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 252 ("ReverseService::DecrThreadCount:" | 331 ("ReverseService::DecrThreadCount:" |
| 253 " Decrementing thread count when count is zero\n")); | 332 " Decrementing thread count when count is zero\n")); |
| 254 } | 333 } |
| 255 if (0 == --thread_count_) { | 334 if (0 == --thread_count_) { |
| 256 NaClXCondVarBroadcast(&cv_); | 335 NaClXCondVarBroadcast(&cv_); |
| 257 } | 336 } |
| 258 NaClXMutexUnlock(&mu_); | 337 NaClXMutexUnlock(&mu_); |
| 259 } | 338 } |
| 260 | 339 |
| 261 } // namespace nacl | 340 } // namespace nacl |
| OLD | NEW |