| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2012 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/trusted/reverse_service/reverse_service_c.h" | 7 #include "native_client/src/trusted/reverse_service/reverse_service_c.h" |
| 8 | 8 |
| 9 #include <limits.h> | 9 #include <limits.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| 11 | 11 |
| 12 #include "native_client/src/include/nacl_compiler_annotations.h" | 12 #include "native_client/src/include/nacl_compiler_annotations.h" |
| 13 #include "native_client/src/include/portability_io.h" | 13 #include "native_client/src/include/portability_io.h" |
| 14 | 14 |
| 15 #include "native_client/src/shared/platform/nacl_check.h" | 15 #include "native_client/src/shared/platform/nacl_check.h" |
| 16 #include "native_client/src/shared/platform/nacl_host_desc.h" | 16 #include "native_client/src/shared/platform/nacl_host_desc.h" |
| 17 #include "native_client/src/shared/platform/nacl_log.h" | 17 #include "native_client/src/shared/platform/nacl_log.h" |
| 18 #include "native_client/src/shared/platform/nacl_sync.h" | 18 #include "native_client/src/shared/platform/nacl_sync.h" |
| 19 #include "native_client/src/shared/platform/nacl_sync_checked.h" | 19 #include "native_client/src/shared/platform/nacl_sync_checked.h" |
| 20 #include "native_client/src/shared/platform/nacl_threads.h" | 20 #include "native_client/src/shared/platform/nacl_threads.h" |
| 21 | 21 |
| 22 #include "native_client/src/shared/srpc/nacl_srpc.h" | 22 #include "native_client/src/shared/srpc/nacl_srpc.h" |
| 23 | 23 |
| 24 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" | 24 #include "native_client/src/trusted/desc/nacl_desc_invalid.h" |
| 25 #include "native_client/src/trusted/desc/nacl_desc_io.h" | 25 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
| 26 | 26 |
| 27 #include "native_client/src/trusted/reverse_service/manifest_rpc.h" | 27 #include "native_client/src/trusted/reverse_service/manifest_rpc.h" |
| 28 #include "native_client/src/trusted/reverse_service/nacl_file_info.h" |
| 28 #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h" | 29 #include "native_client/src/trusted/reverse_service/reverse_control_rpc.h" |
| 29 | 30 |
| 30 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" | 31 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" |
| 31 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | 32 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 32 | 33 |
| 33 struct NaClSrpcHandlerDesc const kNaClReverseServiceHandlers[]; /* fwd */ | 34 struct NaClSrpcHandlerDesc const kNaClReverseServiceHandlers[]; /* fwd */ |
| 34 | 35 |
| 35 int NaClReverseThreadIfFactoryFn( | 36 int NaClReverseThreadIfFactoryFn( |
| 36 void *factory_data, | 37 void *factory_data, |
| 37 NaClThreadIfStartFunction fn_ptr, | 38 NaClThreadIfStartFunction fn_ptr, |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 */ | 349 */ |
| 349 static void NaClReverseServiceManifestLookupRpc( | 350 static void NaClReverseServiceManifestLookupRpc( |
| 350 struct NaClSrpcRpc *rpc, | 351 struct NaClSrpcRpc *rpc, |
| 351 struct NaClSrpcArg **in_args, | 352 struct NaClSrpcArg **in_args, |
| 352 struct NaClSrpcArg **out_args, | 353 struct NaClSrpcArg **out_args, |
| 353 struct NaClSrpcClosure *done_cls) { | 354 struct NaClSrpcClosure *done_cls) { |
| 354 struct NaClReverseService *nrsp = | 355 struct NaClReverseService *nrsp = |
| 355 (struct NaClReverseService *) rpc->channel->server_instance_data; | 356 (struct NaClReverseService *) rpc->channel->server_instance_data; |
| 356 char *url_key = in_args[0]->arrays.str; | 357 char *url_key = in_args[0]->arrays.str; |
| 357 int flags = in_args[0]->u.ival; | 358 int flags = in_args[0]->u.ival; |
| 358 int32_t desc = -1; | 359 struct NaClFileInfo info; |
| 359 struct NaClHostDesc *host_desc; | 360 struct NaClHostDesc *host_desc; |
| 360 struct NaClDescIoDesc *io_desc = NULL; | 361 struct NaClDescIoDesc *io_desc = NULL; |
| 362 struct NaClDesc *nacl_desc = NULL; |
| 363 |
| 364 memset(&info, 0, sizeof(info)); |
| 361 | 365 |
| 362 NaClLog(4, "Entered ManifestLookupRpc: 0x%08"NACL_PRIxPTR", %s, %d\n", | 366 NaClLog(4, "Entered ManifestLookupRpc: 0x%08"NACL_PRIxPTR", %s, %d\n", |
| 363 (uintptr_t) nrsp, url_key, flags); | 367 (uintptr_t) nrsp, url_key, flags); |
| 364 | 368 |
| 365 NaClLog(4, "ManifestLookupRpc: invoking OpenManifestEntry\n"); | 369 NaClLog(4, "ManifestLookupRpc: invoking OpenManifestEntry\n"); |
| 366 if (!(*NACL_VTBL(NaClReverseInterface, nrsp->iface)-> | 370 if (!(*NACL_VTBL(NaClReverseInterface, nrsp->iface)-> |
| 367 OpenManifestEntry)(nrsp->iface, url_key, &desc) | 371 OpenManifestEntry)(nrsp->iface, url_key, &info) |
| 368 || -1 == desc) { | 372 || -1 == info.desc) { |
| 369 NaClLog(1, "ManifestLookupRpc: OpenManifestEntry failed.\n"); | 373 NaClLog(1, "ManifestLookupRpc: OpenManifestEntry failed.\n"); |
| 370 out_args[0]->u.ival = NACL_ABI_ENOENT; /* failed */ | 374 out_args[0]->u.ival = NACL_ABI_ENOENT; /* failed */ |
| 371 out_args[1]->u.hval = (struct NaClDesc *) NaClDescInvalidMake(); | 375 out_args[1]->u.hval = (struct NaClDesc *) NaClDescInvalidMake(); |
| 372 out_args[2]->u.count = 0; | 376 out_args[2]->u.lval = 0; |
| 377 out_args[3]->u.count = 0; |
| 373 goto done; | 378 goto done; |
| 374 } | 379 } |
| 375 NaClLog(4, "ManifestLookupRpc: OpenManifestEntry returned desc %d.\n", | 380 NaClLog(4, "ManifestLookupRpc: OpenManifestEntry returned desc %d.\n", |
| 376 desc); | 381 info.desc); |
| 377 host_desc = (struct NaClHostDesc *) malloc(sizeof *host_desc); | 382 host_desc = (struct NaClHostDesc *) malloc(sizeof *host_desc); |
| 378 CHECK(host_desc != NULL); | 383 CHECK(host_desc != NULL); |
| 379 CHECK(NaClHostDescPosixTake(host_desc, desc, NACL_ABI_O_RDONLY) == 0); | 384 CHECK(NaClHostDescPosixTake(host_desc, info.desc, NACL_ABI_O_RDONLY) == 0); |
| 380 io_desc = NaClDescIoDescMake(host_desc); | 385 io_desc = NaClDescIoDescMake(host_desc); |
| 381 CHECK(io_desc != NULL); | 386 CHECK(io_desc != NULL); |
| 387 nacl_desc = (struct NaClDesc *) io_desc; |
| 388 |
| 382 out_args[0]->u.ival = 0; /* OK */ | 389 out_args[0]->u.ival = 0; /* OK */ |
| 383 out_args[1]->u.hval = (struct NaClDesc *) io_desc; | 390 out_args[1]->u.hval = nacl_desc; |
| 384 out_args[2]->u.count = 10; | 391 out_args[2]->u.lval = (int64_t) info.nonce; |
| 385 strncpy(out_args[2]->arrays.carr, "123456789", 10); | 392 out_args[3]->u.count = 10; |
| 393 strncpy(out_args[3]->arrays.carr, "123456789", 10); |
| 386 /* | 394 /* |
| 387 * TODO(phosek): the array should be an object reference (issue 3035). | 395 * TODO(phosek): the array should be an object reference (issue 3035). |
| 388 */ | 396 */ |
| 389 | 397 |
| 390 done: | 398 done: |
| 391 rpc->result = NACL_SRPC_RESULT_OK; | 399 rpc->result = NACL_SRPC_RESULT_OK; |
| 392 (*done_cls->Run)(done_cls); | 400 (*done_cls->Run)(done_cls); |
| 393 NaClDescSafeUnref((struct NaClDesc *) io_desc); | 401 NaClDescSafeUnref((struct NaClDesc *) io_desc); |
| 394 } | 402 } |
| 395 | 403 |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 NaClLog(3, | 734 NaClLog(3, |
| 727 ("NaClReverseInterfaceEnumerateManifestKeys(0x%08"NACL_PRIxPTR | 735 ("NaClReverseInterfaceEnumerateManifestKeys(0x%08"NACL_PRIxPTR |
| 728 ", 0x%08"NACL_PRIxPTR", %08"NACL_PRIdS")\n"), | 736 ", 0x%08"NACL_PRIxPTR", %08"NACL_PRIdS")\n"), |
| 729 (uintptr_t) self, (uintptr_t) buffer, buffer_bytes); | 737 (uintptr_t) self, (uintptr_t) buffer, buffer_bytes); |
| 730 return 0; | 738 return 0; |
| 731 } | 739 } |
| 732 | 740 |
| 733 int NaClReverseInterfaceOpenManifestEntry( | 741 int NaClReverseInterfaceOpenManifestEntry( |
| 734 struct NaClReverseInterface *self, | 742 struct NaClReverseInterface *self, |
| 735 char const *url_key, | 743 char const *url_key, |
| 736 int32_t *out_desc) { | 744 struct NaClFileInfo *info) { |
| 737 NaClLog(3, | 745 NaClLog(3, |
| 738 ("NaClReverseInterfaceOpenManifestEntry(0x%08"NACL_PRIxPTR", %s" | 746 ("NaClReverseInterfaceOpenManifestEntry(0x%08"NACL_PRIxPTR", %s" |
| 739 ", 0x%08"NACL_PRIxPTR")\n"), | 747 ", 0x%08"NACL_PRIxPTR")\n"), |
| 740 (uintptr_t) self, url_key, (uintptr_t) out_desc); | 748 (uintptr_t) self, url_key, (uintptr_t) info); |
| 741 return 0; | 749 return 0; |
| 742 } | 750 } |
| 743 | 751 |
| 744 int NaClReverseInterfaceCloseManifestEntry( | 752 int NaClReverseInterfaceCloseManifestEntry( |
| 745 struct NaClReverseInterface *self, | 753 struct NaClReverseInterface *self, |
| 746 int32_t desc) { | 754 int32_t desc) { |
| 747 NaClLog(3, | 755 NaClLog(3, |
| 748 "NaClReverseInterfaceCloseManifestEntry(0x%08"NACL_PRIxPTR", %d)\n", | 756 "NaClReverseInterfaceCloseManifestEntry(0x%08"NACL_PRIxPTR", %d)\n", |
| 749 (uintptr_t) self, desc); | 757 (uintptr_t) self, desc); |
| 750 return 0; | 758 return 0; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 NaClReverseInterfaceOpenManifestEntry, | 840 NaClReverseInterfaceOpenManifestEntry, |
| 833 NaClReverseInterfaceCloseManifestEntry, | 841 NaClReverseInterfaceCloseManifestEntry, |
| 834 NaClReverseInterfaceReportCrash, | 842 NaClReverseInterfaceReportCrash, |
| 835 NaClReverseInterfaceReportExitStatus, | 843 NaClReverseInterfaceReportExitStatus, |
| 836 NaClReverseInterfaceDoPostMessage, | 844 NaClReverseInterfaceDoPostMessage, |
| 837 NaClReverseInterfaceCreateProcess, | 845 NaClReverseInterfaceCreateProcess, |
| 838 NaClReverseInterfaceCreateProcessFunctorResult, | 846 NaClReverseInterfaceCreateProcessFunctorResult, |
| 839 NaClReverseInterfaceFinalizeProcess, | 847 NaClReverseInterfaceFinalizeProcess, |
| 840 NaClReverseInterfaceRequestQuotaForWrite, | 848 NaClReverseInterfaceRequestQuotaForWrite, |
| 841 }; | 849 }; |
| OLD | NEW |