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_s(channel_buf_
, sizeof(channel_buf_
), sizeof(channel_buf_
),
52 "%d:%u", imc_fd
, imc_channel_handle
);
53 _snprintf_s(channel_number_
, sizeof(channel_number_
), sizeof(channel_number_
),
56 snprintf(channel_buf_
,
61 snprintf(channel_number_
, sizeof(channel_number_
), "%d", imc_fd
);
64 // .../sel_ldr -f <application_name> -i <NaCl fd>:<imcchannel#>
65 const char* kFixedArgs
[] = {
66 const_cast<char*>(sel_ldr_pathname
),
68 const_cast<char*>(application_name
),
72 const int kFixedArgc
= sizeof(kFixedArgs
) / sizeof(kFixedArgs
[0]);
74 argv_
= new char const*[kFixedArgc
+ sel_ldr_argc
75 + (application_argc
+ 1) + 1];
76 // We use pre-increment everywhere, so we need to initialize to -1.
79 // Copy the fixed arguments to argv_.
80 for (int i
= 0; i
< kFixedArgc
; ++i
) {
81 argv_
[++argc_
] = kFixedArgs
[i
];
83 // Copy the specified additional arguments (e.g., "-d" or "-P") to sel_ldr
84 for (int i
= 0; i
< sel_ldr_argc
; ++i
) {
85 argv_
[++argc_
] = sel_ldr_argv
[i
];
87 // Copy the specified arguments to the application
88 if (application_argc
> 0) {
89 argv_
[++argc_
] = "--";
90 for (int i
= 0; i
< application_argc
; ++i
) {
91 if (strncmp("$CHAN", application_argv
[i
], 6) == 0) {
92 argv_
[++argc_
] = channel_number_
;
94 argv_
[++argc_
] = application_argv
[i
];
98 // NULL terminate the argument list.
99 argv_
[++argc_
] = NULL
;