2 * Copyright 2008, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/types.h>
41 #include <sys/param.h>
44 #include "native_client/nonnacl_util/sel_ldr_launcher.h"
48 SelLdrLauncher::~SelLdrLauncher() {
49 if (child_
!= kInvalidHandle
) {
51 // When used with the browser's invalidate functionality this
52 // causes occasional deadlocks in nacl modules that have threads that have
53 // not terminated when the main thread is being terminated.
54 // TODO: Implement a whole-module shutdown RPC.
55 // waitpid(child_, &status, 0);
59 SelLdrLauncher::SelLdrLauncher(const char* application_name
,
62 const char* sel_ldr_argv
[],
64 const char* application_argv
[])
66 application_name_(application_name
) {
68 const char* const kSelLdrBasename
= "sel_ldr";
69 const char* const kNaclPtraceBasename
= "sel_ldr.trace";
70 const char* plugin_dirname
= GetPluginDirname();
71 char sel_ldr_path
[MAXPATHLEN
+ 1];
73 child_
= kInvalidHandle
;
74 channel_
= kInvalidHandle
;
76 if (NULL
== plugin_dirname
) {
77 // TODO: better reporting that we couldn't find sel_ldr.
78 printf("GetPluginDirname returned NULL -- load failed\n");
82 if (getenv("NACL_TRACE_SEL_LDR")) {
83 snprintf(sel_ldr_path
,
89 snprintf(sel_ldr_path
,
95 printf("starting: %s %s\n", sel_ldr_path
, application_name
);
97 if (SocketPair(pair
) == -1) {
98 // TODO: better reporting that we couldn't create the socket pair.
102 // Set environment variable to keep the Mac sel_ldr from stealing the focus.
103 // TODO: change this to use a command line parameter rather than env.
104 setenv("NACL_LAUNCHED_FROM_BROWSER", "1", 0);
105 // Fork the sel_ldr process.
108 // TODO: better reporting that we couldn't fork.
109 printf("fork failed\n");
117 BuildArgv(sel_ldr_path
,
125 execv(sel_ldr_path
, const_cast<char **>(argv_
));
127 printf("exec failed\n");
133 int flags
= fcntl(channel_
, F_GETFD
);
136 fcntl(channel_
, F_SETFD
, flags
);