Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/trusted/service_runtime/sel_ldr_standard.c

Issue 7108031: this patch adds the manifest proxy server to sel_ldr and the manifest (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 /* 7 /*
8 * NaCl Simple/secure ELF loader (NaCl SEL). 8 * NaCl Simple/secure ELF loader (NaCl SEL).
9 */ 9 */
10 10
11 #include "native_client/src/include/portability.h" 11 #include "native_client/src/include/portability.h"
12 12
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <string.h> 15 #include <string.h>
16 16
17 #include "native_client/src/include/elf_constants.h" 17 #include "native_client/src/include/elf_constants.h"
18 #include "native_client/src/include/nacl_elf.h" 18 #include "native_client/src/include/nacl_elf.h"
19 #include "native_client/src/include/nacl_macros.h" 19 #include "native_client/src/include/nacl_macros.h"
20 #include "native_client/src/include/win/mman.h" 20 #include "native_client/src/include/win/mman.h"
21 #include "native_client/src/shared/platform/nacl_check.h" 21 #include "native_client/src/shared/platform/nacl_check.h"
22 #include "native_client/src/shared/platform/nacl_log.h" 22 #include "native_client/src/shared/platform/nacl_log.h"
23 #include "native_client/src/shared/platform/nacl_sync_checked.h" 23 #include "native_client/src/shared/platform/nacl_sync_checked.h"
24 #include "native_client/src/shared/platform/nacl_time.h" 24 #include "native_client/src/shared/platform/nacl_time.h"
25
26 #include "native_client/src/trusted/manifest_name_service_proxy/manifest_proxy.h "
25 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h" 27 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h"
26 28
27 #include "native_client/src/trusted/service_runtime/include/sys/errno.h" 29 #include "native_client/src/trusted/service_runtime/include/sys/errno.h"
30 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
28 31
29 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" 32 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h"
30 #include "native_client/src/trusted/service_runtime/elf_util.h" 33 #include "native_client/src/trusted/service_runtime/elf_util.h"
31 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" 34 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
32 #include "native_client/src/trusted/service_runtime/nacl_closure.h" 35 #include "native_client/src/trusted/service_runtime/nacl_closure.h"
33 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h" 36 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h"
34 #include "native_client/src/trusted/service_runtime/nacl_sync_queue.h" 37 #include "native_client/src/trusted/service_runtime/nacl_sync_queue.h"
35 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" 38 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h"
36 #include "native_client/src/trusted/service_runtime/nacl_text.h" 39 #include "native_client/src/trusted/service_runtime/nacl_text.h"
37 #include "native_client/src/trusted/service_runtime/outer_sandbox.h" 40 #include "native_client/src/trusted/service_runtime/outer_sandbox.h"
38 #include "native_client/src/trusted/service_runtime/sel_memory.h" 41 #include "native_client/src/trusted/service_runtime/sel_memory.h"
39 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 42 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
43 #include "native_client/src/trusted/service_runtime/sel_ldr_thread_interface.h"
40 #include "native_client/src/trusted/service_runtime/sel_util.h" 44 #include "native_client/src/trusted/service_runtime/sel_util.h"
41 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" 45 #include "native_client/src/trusted/service_runtime/sel_addrspace.h"
42 46
43 #if !defined(SIZE_T_MAX) 47 #if !defined(SIZE_T_MAX)
44 # define SIZE_T_MAX (~(size_t) 0) 48 # define SIZE_T_MAX (~(size_t) 0)
45 #endif 49 #endif
46 50
47 51
48 /* 52 /*
49 * Fill from static_text_end to end of that page with halt 53 * Fill from static_text_end to end of that page with halt
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 int NaClAddrIsValidEntryPt(struct NaClApp *nap, 519 int NaClAddrIsValidEntryPt(struct NaClApp *nap,
516 uintptr_t addr) { 520 uintptr_t addr) {
517 if (0 != (addr & (nap->bundle_size - 1))) { 521 if (0 != (addr & (nap->bundle_size - 1))) {
518 return 0; 522 return 0;
519 } 523 }
520 524
521 return addr < nap->static_text_end; 525 return addr < nap->static_text_end;
522 } 526 }
523 527
524 int NaClAppLaunchServiceThreads(struct NaClApp *nap) { 528 int NaClAppLaunchServiceThreads(struct NaClApp *nap) {
529 struct NaClManifestProxy *manifest_proxy = NULL;
530 int rv;
531
525 NaClNameServiceLaunch(nap->name_service); 532 NaClNameServiceLaunch(nap->name_service);
526 return 1; 533
534 /*
535 * The locking here isn't really needed. Here is why:
536 * reverse_channel_initialized is written in reverse_setup RPC
537 * handler of the secure command channel RPC handler thread. and
538 * the RPC order requires that the plugin invoke reverse_setup prior
539 * to invoking start_module, so there will have been plenty of other
540 * synchronization operations to force cache coherency
541 * (module_may_start, for example, is set in the cache of the secure
542 * channel RPC handler (in start_module) and read by the main
543 * thread, and the synchronization operations needed to propagate
544 * its value properly suffices to propagate
545 * reverse_channel_initialized as well). However, reading it while
546 * holding a lock is more obviously correct for tools like tsan.
547 * Due to the RPC order, it is impossible for
548 * reverse_channel_initialized to get set after the unlock and
549 * before the if test.
550 */
551 NaClXMutexLock(&nap->mu);
552 rv = !nap->reverse_channel_initialized;
553 NaClXMutexUnlock(&nap->mu);
554 if (rv) {
555 NaClLog(3,
556 ("NaClAppLaunchServiceThreads: no reverse channel;"
557 " NOT launching manifest proxy\n"));
558 goto done;
559 }
560
561 rv = 0;
562 /*
563 * Allocate/construct the manifest proxy without grabbing global
564 * locks.
565 */
566 NaClLog(3, "NaClAppLaunchServiceThreads: launching manifest proxy\n");
567
568 /*
569 * ReverseClientSetup RPC should be done via the command channel
570 * prior to the load_module / start_module RPCs, and
571 * occurs after that, so checking
572 * nap->reverse_client suffices for determining whether the proxy is
573 * exporting reverse services.
574 */
575 manifest_proxy = (struct NaClManifestProxy *) malloc(sizeof *manifest_proxy);
576 if (NULL == manifest_proxy) {
577 NaClLog(LOG_ERROR, "No memory for manifest proxy\n");
578 goto manifest_proxy_alloc_failure;
579 }
580 if (!NaClManifestProxyCtor(manifest_proxy,
581 NaClAddrSpSquattingThreadIfFactoryFunction,
582 (void *) nap,
583 nap)) {
584 NaClLog(LOG_ERROR, "ManifestProxyCtor failed\n");
585 goto manifest_proxy_ctor_failure;
586 }
587
588 /*
589 * NaClSimpleServiceStartServiceThread requires the nap->mu lock.
590 */
591 if (!NaClSimpleServiceStartServiceThread((struct NaClSimpleService *)
592 manifest_proxy)) {
593 NaClLog(LOG_ERROR, "ManifestProxy start service failed\n");
594 NaClRefCountUnref((struct NaClRefCount *) manifest_proxy);
595 manifest_proxy = NULL;
596 goto manifest_proxy_start_failed;
597 }
598
599 NaClXMutexLock(&nap->mu);
600 CHECK(NULL == nap->manifest_proxy);
601
602 nap->manifest_proxy = manifest_proxy;
603 manifest_proxy = NULL;
604
605 NaClLog(3,
606 ("NaClAppLaunchServiceThreads: adding manifest proxy to"
607 " name service\n"));
608 (*NACL_VTBL(NaClNameService, nap->name_service)->
609 CreateDescEntry)(nap->name_service,
610 "manifest_proxy", NACL_ABI_O_RDWR,
611 NaClDescRef(nap->manifest_proxy->base.bound_and_cap[1]));
612
613 rv = 1;
614 NaClXMutexUnlock(&nap->mu);
615
616 manifest_proxy_start_failed:
617 manifest_proxy_ctor_failure:
618 free(manifest_proxy);
619 manifest_proxy_alloc_failure:
620 done:
621 return rv;
527 } 622 }
528 623
529 /* 624 /*
530 * preconditions: 625 * preconditions:
531 * argc > 0, argc and argv table is consistent 626 * argc > 0, argc and argv table is consistent
532 * envv may be NULL (this happens on MacOS/Cocoa 627 * envv may be NULL (this happens on MacOS/Cocoa
533 * if envv is non-NULL it is 'consistent', null terminated etc. 628 * if envv is non-NULL it is 'consistent', null terminated etc.
534 */ 629 */
535 int NaClCreateMainThread(struct NaClApp *nap, 630 int NaClCreateMainThread(struct NaClApp *nap,
536 int argc, 631 int argc,
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 sys_tdb, 900 sys_tdb,
806 tdb_size)) { 901 tdb_size)) {
807 NaClLog(LOG_WARNING, 902 NaClLog(LOG_WARNING,
808 ("NaClCreateAdditionalThread: could not allocate thread index." 903 ("NaClCreateAdditionalThread: could not allocate thread index."
809 " Returning EAGAIN per POSIX specs.\n")); 904 " Returning EAGAIN per POSIX specs.\n"));
810 free(natp); 905 free(natp);
811 return -NACL_ABI_EAGAIN; 906 return -NACL_ABI_EAGAIN;
812 } 907 }
813 return 0; 908 return 0;
814 } 909 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698