Index: src/trusted/reverse_service/reverse_service.cc |
=================================================================== |
--- src/trusted/reverse_service/reverse_service.cc (revision 5652) |
+++ src/trusted/reverse_service/reverse_service.cc (working copy) |
@@ -4,17 +4,21 @@ |
* found in the LICENSE file. |
*/ |
+#include <string.h> |
+ |
#include "native_client/src/trusted/reverse_service/reverse_service.h" |
#include "native_client/src/include/nacl_compiler_annotations.h" |
#include "native_client/src/include/nacl_scoped_ptr.h" |
- |
+#include "native_client/src/include/portability_io.h" |
#include "native_client/src/shared/platform/nacl_log.h" |
#include "native_client/src/shared/platform/nacl_sync.h" |
#include "native_client/src/shared/platform/nacl_sync_checked.h" |
#include "native_client/src/shared/platform/nacl_threads.h" |
#include "native_client/src/shared/srpc/nacl_srpc.h" |
+#include "native_client/src/trusted/desc/nacl_desc_invalid.h" |
+ |
namespace { |
void Test(NaClSrpcRpc* rpc, |
@@ -37,8 +41,9 @@ |
NaClSrpcClosure* done) { |
nacl::ReverseService* service = reinterpret_cast<nacl::ReverseService*>( |
rpc->channel->server_instance_data); |
+ |
UNREFERENCED_PARAMETER(in_args); |
- UNREFERENCED_PARAMETER(out_args); |
+ |
NaClLog(4, "Entered AddChannel\n"); |
out_args[0]->u.bval = service->Start(); |
NaClLog(4, "Leaving AddChannel\n"); |
@@ -63,6 +68,83 @@ |
done->Run(done); |
} |
+// Manifest name service, internal APIs. |
+// |
+// Manifest file lookups result in read-only file descriptors with a |
+// handle. When the descriptor is closed, the service runtime must |
+// inform the plugin of this using the handle, so that the File object |
+// reference can be closed (thereby allowing the browser to delete or |
+// otherwise garbage collect the file). Files, being from the |
+// manifest, cannot be deleted. The manifest is also a read-only |
+// object, so no new entries can be made to it. |
+// |
+// Read-only proxies do not require quota support per se, since we do |
+// not limit read bandwidth. Quota support is needed for storage |
+// limits, though could also be used to limit write bandwidth (prevent |
+// disk output saturation, limit malicious code's ability to cause |
+// disk failures, especially with flash disks with limited write |
+// cycles). |
+ |
+// NACL_MANIFEST_LIST list::C -- enumerate all names in the manifest |
+void ManifestListRpc(NaClSrpcRpc* rpc, |
+ NaClSrpcArg** in_args, |
+ NaClSrpcArg** out_args, |
+ NaClSrpcClosure* done) { |
+ UNREFERENCED_PARAMETER(in_args); |
+ // Placeholder. This RPC handler will be replaced with code that |
+ // actually do manifest listing. |
+ // |
+ // TODO(bsy) hook up to real manifest info |
+ out_args[0]->u.count = SNPRINTF(out_args[0]->arrays.carr, |
+ out_args[0]->u.count, |
+ "This is a reply from the manifest reverse" |
+ " service in the plugin."); |
+ rpc->result = NACL_SRPC_RESULT_OK; |
+ done->Run(done); |
+} |
+ |
+// NACL_MANIFEST_LOOKUP lookup:si:ihC -- look up by string name, |
+// resulting in a handle (if name is in the preimage), a object proxy |
+// handle, and an error code. |
+void ManifestLookupRpc(NaClSrpcRpc* rpc, |
+ NaClSrpcArg** in_args, |
+ NaClSrpcArg** out_args, |
+ NaClSrpcClosure* done) { |
+ char* fname = in_args[0]->arrays.str; |
+ int flags = in_args[0]->u.ival; |
+ |
+ NaClLog(0, "ManifestLookupRpc: %s, %d\n", fname, flags); |
+ out_args[0]->u.ival = 0; // ok |
+ out_args[1]->u.hval = (struct NaClDesc*) NaClDescInvalidMake(); |
+ // Placeholder. This RPC handler will be replaced with code that |
+ // actually do lookups/URL fetches. |
+ // |
+ // TODO(bsy): hook up to real name resolution and return a real |
+ // descriptor. |
+ out_args[2]->u.count = 10; |
+ strncpy(out_args[2]->arrays.carr, "123456789", 10); |
+ rpc->result = NACL_SRPC_RESULT_OK; |
+ done->Run(done); |
+} |
+ |
+// NACL_MANIFEST_UNREF unref:C:i -- dereferences the file by object |
+// proxy handle. The file descriptor should have been closed. |
+void ManifestUnrefRpc(NaClSrpcRpc* rpc, |
+ NaClSrpcArg** in_args, |
+ NaClSrpcArg** out_args, |
+ NaClSrpcClosure* done) { |
+ char* proxy_handle = in_args[0]->arrays.carr; |
+ |
+ NaClLog(0, "ManifestUnrefRpc: %s\n", proxy_handle); |
+ // Placeholder. This RPC will be replaced by real code that |
+ // looks up the object proxy handle to close the Pepper file object. |
+ // |
+ // TODO(bsy): replace with real code. |
+ out_args[0]->u.ival = 0; // ok |
+ rpc->result = NACL_SRPC_RESULT_OK; |
+ done->Run(done); |
+} |
+ |
} // namespace |
namespace nacl { |
@@ -184,9 +266,12 @@ |
}; |
NaClSrpcHandlerDesc const ReverseService::handlers[] = { |
- { "test:s:", Test, }, |
- { "revlog:s:", RevLog, }, |
- { "add_channel::b", AddChannel, }, |
+ { NACL_REVERSE_CONTROL_TEST, Test, }, |
+ { NACL_REVERSE_CONTROL_LOG, RevLog, }, |
+ { NACL_REVERSE_CONTROL_ADD_CHANNEL, AddChannel, }, |
+ { NACL_MANIFEST_LIST, ManifestListRpc, }, |
+ { NACL_MANIFEST_LOOKUP, ManifestLookupRpc, }, |
+ { NACL_MANIFEST_UNREF, ManifestUnrefRpc, }, |
{ NULL, NULL, }, |
}; |
@@ -220,6 +305,7 @@ |
bool ReverseService::Start() { |
+ NaClLog(4, "Entered ReverseService::Start\n"); |
return service_socket_->StartService(reinterpret_cast<void*>(this)); |
} |