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 "native_client/nonnacl_util/sel_ldr_launcher.h"
36 #include <sys/types.h>
38 #include "native_client/include/nacl_elf.h"
42 void SelLdrLauncher::BuildArgv(const char* sel_ldr_pathname
,
43 const char* application_name
,
45 Handle imc_channel_handle
,
47 const char* sel_ldr_argv
[],
49 const char* application_argv
[]) {
51 _snprintf(channel_buf_
, sizeof(channel_buf_
), "%d:%u",
52 imc_fd
, imc_channel_handle
);
53 _snprintf(channel_number_
, sizeof(channel_number_
), "%d", imc_fd
);
55 snprintf(channel_buf_
,
60 snprintf(channel_number_
, sizeof(channel_number_
), "%d", imc_fd
);
63 // .../sel_ldr -f <application_name> -i <NaCl fd>:<imcchannel#>
64 const char* kFixedArgs
[] = {
65 const_cast<char*>(sel_ldr_pathname
),
67 const_cast<char*>(application_name
),
71 const int kFixedArgc
= sizeof(kFixedArgs
) / sizeof(kFixedArgs
[0]);
73 argv_
= new char const*[kFixedArgc
+ sel_ldr_argc
74 + (application_argc
+ 1) + 1];
75 // We use pre-increment everywhere, so we need to initialize to -1.
78 // Copy the fixed arguments to argv_.
79 for (int i
= 0; i
< kFixedArgc
; ++i
) {
80 argv_
[++argc_
] = kFixedArgs
[i
];
82 // Copy the specified additional arguments (e.g., "-d" or "-P") to sel_ldr
83 for (int i
= 0; i
< sel_ldr_argc
; ++i
) {
84 argv_
[++argc_
] = sel_ldr_argv
[i
];
86 // Copy the specified arguments to the application
87 if (application_argc
> 0) {
88 argv_
[++argc_
] = "--";
89 for (int i
= 0; i
< application_argc
; ++i
) {
90 if (strncmp("$CHAN", application_argv
[i
], 6) == 0) {
91 argv_
[++argc_
] = channel_number_
;
93 argv_
[++argc_
] = application_argv
[i
];
97 // NULL terminate the argument list.
98 argv_
[++argc_
] = NULL
;