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

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

Issue 8825007: Native Client side changes for debugging support: stdout/err -> postmessage. (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client/
Patch Set: Created 9 years 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
« no previous file with comments | « src/trusted/service_runtime/sel_ldr.h ('k') | src/trusted/service_runtime/sel_main.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <string.h> 7 #include <string.h>
8 8
9 /* 9 /*
10 * NaCl Simple/secure ELF loader (NaCl SEL). 10 * NaCl Simple/secure ELF loader (NaCl SEL).
(...skipping 26 matching lines...) Expand all
37 #include "native_client/src/trusted/gio/gio_shm.h" 37 #include "native_client/src/trusted/gio/gio_shm.h"
38 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h" 38 #include "native_client/src/trusted/service_runtime/arch/sel_ldr_arch.h"
39 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h " 39 #include "native_client/src/trusted/service_runtime/include/bits/nacl_syscalls.h "
40 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 40 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
41 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" 41 #include "native_client/src/trusted/service_runtime/include/sys/stat.h"
42 #include "native_client/src/trusted/service_runtime/include/sys/time.h" 42 #include "native_client/src/trusted/service_runtime/include/sys/time.h"
43 #include "native_client/src/trusted/service_runtime/nacl_app.h" 43 #include "native_client/src/trusted/service_runtime/nacl_app.h"
44 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h" 44 #include "native_client/src/trusted/service_runtime/nacl_app_thread.h"
45 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h" 45 #include "native_client/src/trusted/service_runtime/nacl_desc_effector_ldr.h"
46 #include "native_client/src/trusted/service_runtime/nacl_globals.h" 46 #include "native_client/src/trusted/service_runtime/nacl_globals.h"
47 #include "native_client/src/trusted/service_runtime/nacl_resource.h"
47 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" 48 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h"
48 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h" 49 #include "native_client/src/trusted/service_runtime/nacl_syscall_handlers.h"
49 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" 50 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h"
50 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" 51 #include "native_client/src/trusted/service_runtime/sel_addrspace.h"
51 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 52 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
52 #include "native_client/src/trusted/service_runtime/sel_memory.h" 53 #include "native_client/src/trusted/service_runtime/sel_memory.h"
53 54
54 #include "native_client/src/trusted/service_runtime/name_service/default_name_se rvice.h" 55 #include "native_client/src/trusted/service_runtime/name_service/default_name_se rvice.h"
55 #include "native_client/src/trusted/service_runtime/name_service/name_service.h" 56 #include "native_client/src/trusted/service_runtime/name_service/name_service.h"
56 57
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 nap->dynamic_mapcache_offset = 0; 137 nap->dynamic_mapcache_offset = 0;
137 nap->dynamic_mapcache_size = 0; 138 nap->dynamic_mapcache_size = 0;
138 nap->dynamic_mapcache_ret = 0; 139 nap->dynamic_mapcache_ret = 0;
139 140
140 nap->service_port = NULL; 141 nap->service_port = NULL;
141 nap->service_address = NULL; 142 nap->service_address = NULL;
142 nap->secure_service = NULL; 143 nap->secure_service = NULL;
143 nap->manifest_proxy = NULL; 144 nap->manifest_proxy = NULL;
144 nap->kern_service = NULL; 145 nap->kern_service = NULL;
146 nap->resource_phase = NACL_RESOURCE_PHASE_START;
147 if (!NaClResourceNaClAppInit(&nap->resources, nap)) {
148 goto cleanup_dynamic_load_mutex;
149 }
145 nap->reverse_client = NULL; 150 nap->reverse_client = NULL;
146 nap->reverse_channel_initialization_state = 151 nap->reverse_channel_initialization_state =
147 NACL_REVERSE_CHANNEL_UNINITIALIZED; 152 NACL_REVERSE_CHANNEL_UNINITIALIZED;
148 153
149 if (!NaClMutexCtor(&nap->mu)) { 154 if (!NaClMutexCtor(&nap->mu)) {
150 goto cleanup_dynamic_load_mutex; 155 goto cleanup_dynamic_load_mutex;
151 } 156 }
152 if (!NaClCondVarCtor(&nap->cv)) { 157 if (!NaClCondVarCtor(&nap->cv)) {
153 goto cleanup_mu; 158 goto cleanup_mu;
154 } 159 }
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 if (NULL == dp) { 657 if (NULL == dp) {
653 NaClLog(LOG_FATAL, "NaClAddImcHandle: no memory\n"); 658 NaClLog(LOG_FATAL, "NaClAddImcHandle: no memory\n");
654 } 659 }
655 if (!NaClDescImcDescCtor(dp, h)) { 660 if (!NaClDescImcDescCtor(dp, h)) {
656 NaClLog(LOG_FATAL, ("NaClAddImcHandle: cannot construct" 661 NaClLog(LOG_FATAL, ("NaClAddImcHandle: cannot construct"
657 " IMC descriptor object\n")); 662 " IMC descriptor object\n"));
658 } 663 }
659 NaClSetDesc(nap, nacl_desc, (struct NaClDesc *) dp); 664 NaClSetDesc(nap, nacl_desc, (struct NaClDesc *) dp);
660 } 665 }
661 666
667
668 static void NaClProcessRedirControl(struct NaClApp *nap) {
669 static struct {
670 int d;
671 char const *env_name;
672 int nacl_flags;
673 int mode;
674 } redir_control[] = {
675 { 0, "NACL_EXE_STDIN",
676 NACL_ABI_O_RDONLY, 0, },
677 { 1, "NACL_EXE_STDOUT",
678 NACL_ABI_O_WRONLY | NACL_ABI_O_APPEND, 0777, },
679 { 2, "NACL_EXE_STDERR",
680 NACL_ABI_O_WRONLY | NACL_ABI_O_APPEND, 0777, },
681 };
682
683 size_t ix;
684 char const *env;
685 struct NaClDesc *ndp;
686
687 for (ix = 0; ix < NACL_ARRAY_SIZE(redir_control); ++ix) {
688 if (NULL != (env = getenv(redir_control[ix].env_name))) {
689 NaClLog(4, "getenv(%s) -> %s\n", redir_control[ix].env_name, env);
690 ndp = NaClResourceOpen((struct NaClResource *) &nap->resources,
691 env,
692 redir_control[ix].nacl_flags,
693 redir_control[ix].mode);
694 NaClLog(4, " NaClResourceOpen returned %"NACL_PRIxPTR"\n",
695 (uintptr_t) ndp);
696 if (NULL != ndp) {
697 NaClLog(4, "Setting descriptor %d\n", (int) ix);
698 NaClSetDesc(nap, (int) ix, ndp);
699 ndp = NULL;
700 }
701 } else if (NACL_RESOURCE_PHASE_START == nap->resource_phase) {
702 /*
703 * Environment not set -- handle default inheritance.
704 */
705 NaClAddHostDescriptor(nap, DUP(redir_control[ix].d),
706 redir_control[ix].nacl_flags, (int) ix);
707 }
708 }
709 }
710
662 /* 711 /*
663 * Process default descriptor inheritance. This means dup'ing 712 * Process default descriptor inheritance. This means dup'ing
664 * descriptors 0-2 and making them available to the NaCl App. 713 * descriptors 0-2 and making them available to the NaCl App.
665 * 714 *
666 * When standard input is inherited, this could result in a NaCl 715 * When standard input is inherited, this could result in a NaCl
667 * module competing for input from the terminal; for graphical / 716 * module competing for input from the terminal; for graphical /
668 * browser plugin environments, this never is allowed to happen, and 717 * browser plugin environments, this never is allowed to happen, and
669 * having this is useful for debugging, and for potential standalone 718 * having this is useful for debugging, and for potential standalone
670 * text-mode applications of NaCl. 719 * text-mode applications of NaCl.
671 * 720 *
672 * TODO(bsy): consider whether default inheritance should occur only 721 * TODO(bsy): consider whether default inheritance should occur only
673 * in debug mode. 722 * in debug mode.
674 */ 723 */
675 void NaClAppInitialDescriptorHookup(struct NaClApp *nap) { 724 void NaClAppInitialDescriptorHookup(struct NaClApp *nap) {
676 static struct {
677 int d;
678 char const *env_name;
679 int flags;
680 int mode;
681 int nacl_flags;
682 } redir_control[] = {
683 { 0, "NACL_EXE_STDIN", O_RDONLY, 0,
684 NACL_ABI_O_RDONLY, },
685 { 1, "NACL_EXE_STDOUT", O_WRONLY | O_APPEND | O_CREAT, 0777,
686 NACL_ABI_O_WRONLY | NACL_ABI_O_APPEND, },
687 { 2, "NACL_EXE_STDERR", O_WRONLY | O_APPEND | O_CREAT, 0777,
688 NACL_ABI_O_WRONLY | NACL_ABI_O_APPEND, },
689 };
690 725
691 size_t ix; 726 NaClLog(4, "Processing I/O redirection/inheritance from environment\n");
692 char *env; 727 nap->resource_phase = NACL_RESOURCE_PHASE_START;
693 int d; 728 NaClProcessRedirControl(nap);
694 729 NaClLog(4, "... done.\n");
695 for (ix = 0; ix < NACL_ARRAY_SIZE(redir_control); ++ix) {
696 d = -1;
697 if (NULL != (env = getenv(redir_control[ix].env_name))) {
698 d = open(env, redir_control[ix].flags, redir_control[ix].mode);
699 /* may return -1, esp sandbox */
700 }
701 if (-1 == d) {
702 d = DUP(redir_control[ix].d);
703 }
704 NaClAddHostDescriptor(nap, d, redir_control[ix].nacl_flags, (int) ix);
705 }
706 } 730 }
707 731
708 void NaClAppVmmapUpdate(struct NaClApp *nap, 732 void NaClAppVmmapUpdate(struct NaClApp *nap,
709 uintptr_t page_num, 733 uintptr_t page_num,
710 size_t npages, 734 size_t npages,
711 int prot, 735 int prot,
712 struct NaClMemObj *nmop, 736 struct NaClMemObj *nmop,
713 int remove) { 737 int remove) {
714 NaClXMutexLock(&nap->mu); 738 NaClXMutexLock(&nap->mu);
715 NaClVmmapUpdate(&nap->mem_map, 739 NaClVmmapUpdate(&nap->mem_map,
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 case NACL_DESC_CONNECTED_SOCKET: 931 case NACL_DESC_CONNECTED_SOCKET:
908 case NACL_DESC_SYSV_SHM: 932 case NACL_DESC_SYSV_SHM:
909 case NACL_DESC_MUTEX: 933 case NACL_DESC_MUTEX:
910 case NACL_DESC_CONDVAR: 934 case NACL_DESC_CONDVAR:
911 case NACL_DESC_SEMAPHORE: 935 case NACL_DESC_SEMAPHORE:
912 case NACL_DESC_SYNC_SOCKET: 936 case NACL_DESC_SYNC_SOCKET:
913 case NACL_DESC_TRANSFERABLE_DATA_SOCKET: 937 case NACL_DESC_TRANSFERABLE_DATA_SOCKET:
914 case NACL_DESC_IMC_SOCKET: 938 case NACL_DESC_IMC_SOCKET:
915 case NACL_DESC_QUOTA: 939 case NACL_DESC_QUOTA:
916 case NACL_DESC_DEVICE_RNG: 940 case NACL_DESC_DEVICE_RNG:
941 case NACL_DESC_DEVICE_POSTMESSAGE:
917 /* Unsupported stuff */ 942 /* Unsupported stuff */
918 rpc->result = NACL_SRPC_RESULT_APP_ERROR; 943 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
919 goto cleanup; 944 goto cleanup;
920 } 945 }
921 946
922 /* 947 /*
923 * do not use default case label, to make sure that the compiler 948 * do not use default case label, to make sure that the compiler
924 * will generate a warning with -Wswitch-enum for new entries in 949 * will generate a warning with -Wswitch-enum for new entries in
925 * NaClDescTypeTag introduced in nacl_desc_base.h for which there is no 950 * NaClDescTypeTag introduced in nacl_desc_base.h for which there is no
926 * corresponding entry here. instead, we pretend that fall-through 951 * corresponding entry here. instead, we pretend that fall-through
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
1295 free(rev); 1320 free(rev);
1296 rpc->result = NACL_SRPC_RESULT_APP_ERROR; 1321 rpc->result = NACL_SRPC_RESULT_APP_ERROR;
1297 goto done; 1322 goto done;
1298 } 1323 }
1299 nap->reverse_client = (struct NaClSecureReverseClient *) NaClRefCountRef( 1324 nap->reverse_client = (struct NaClSecureReverseClient *) NaClRefCountRef(
1300 (struct NaClRefCount *) rev); 1325 (struct NaClRefCount *) rev);
1301 out_args[0]->u.hval = NaClDescRef(rev->base.bound_and_cap[1]); 1326 out_args[0]->u.hval = NaClDescRef(rev->base.bound_and_cap[1]);
1302 rpc->result = NACL_SRPC_RESULT_OK; 1327 rpc->result = NACL_SRPC_RESULT_OK;
1303 1328
1304 /* 1329 /*
1330 * Hook up reverse-channel enabled resources, e.g.,
1331 * DEBUG_ONLY:dev://postmessage. NB: Resources specified by
1332 * file:path should have been taken care of earlier, in
1333 * NaClAppInitialDescriptorHookup.
1334 */
1335 nap->resource_phase = NACL_RESOURCE_PHASE_REV_CHAN;
1336 NaClLog(4, "Processing dev I/O redirection/inheritance from environment\n");
1337 NaClProcessRedirControl(nap);
1338 NaClLog(4, "... done.\n");
1339
1340 /*
1305 * Service thread takes the reference rev. 1341 * Service thread takes the reference rev.
1306 */ 1342 */
1307 if (!NaClSimpleRevClientStartServiceThread(&rev->base)) { 1343 if (!NaClSimpleRevClientStartServiceThread(&rev->base)) {
1308 NaClLog(LOG_FATAL, "Could not start reverse service thread\n"); 1344 NaClLog(LOG_FATAL, "Could not start reverse service thread\n");
1309 } 1345 }
1310 1346
1311 done: 1347 done:
1312 NaClXMutexUnlock(&nap->mu); 1348 NaClXMutexUnlock(&nap->mu);
1313 (*done->Run)(done); 1349 (*done->Run)(done);
1314 NaClLog(4, "Leaving NaClSecureReverseClientSetup\n"); 1350 NaClLog(4, "Leaving NaClSecureReverseClientSetup\n");
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
1659 NaClSandboxMemoryStartForValgrind(mem_start); 1695 NaClSandboxMemoryStartForValgrind(mem_start);
1660 1696
1661 #ifdef __GNUC__ 1697 #ifdef __GNUC__
1662 _ovly_debug_event (); 1698 _ovly_debug_event ();
1663 #endif 1699 #endif
1664 } 1700 }
1665 1701
1666 void NaClGdbHook(struct NaClApp const *nap) { 1702 void NaClGdbHook(struct NaClApp const *nap) {
1667 StopForDebuggerInit(nap->mem_start); 1703 StopForDebuggerInit(nap->mem_start);
1668 } 1704 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/sel_ldr.h ('k') | src/trusted/service_runtime/sel_main.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698