1 : /*
2 : * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 : * Use of this source code is governed by a BSD-style license that can be
4 : * found in the LICENSE file.
5 : */
6 :
7 : #include <string.h>
8 :
9 : #include "native_client/src/trusted/service_runtime/sel_ldr.h"
10 :
11 : /*
12 : * This function handles the nacl_helper_bootstrap arguments r_debug
13 : * and reserved_at_zero and updates argc and argv to act as though
14 : * these arguments were not passed. For example, the command
15 : *
16 : * nacl_helper_bootstrap program --r_debug=0xXXXXXXXXXXXXXXXX \
17 : * --reserved_at_zero=0xXXXXXXXXXXXXXXXX program_arg
18 : *
19 : * will result in the following argc and argv structure for program after
20 : * running throughg the bootstrapper:
21 : *
22 : * argc: 4
23 : * argv[0]: program
24 : * argv[1]: --r_debug=0xXXXXXXXXXXXXXXXX
25 : * argv[2]: --reserved_at_zero=0xXXXXXXXXXXXXXXXX
26 : * argv[3]: program_arg
27 : *
28 : * After program calls NaClHandleBootstrapArgs, the argc and argv structure
29 : * will be:
30 : *
31 : * argc: 2
32 : * argv[0]: program
33 : * argv[1]: program_arg
34 : *
35 : * argc_p is the pointer to the argc variable passed to main.
36 : * argv_p is the pointer to the argv variable passed to main.
37 : */
38 11 : void NaClHandleBootstrapArgs(int *argc_p, char ***argv_p) {
39 : static const char kRDebugSwitch[] = "--r_debug=";
40 : static const char kAtZeroSwitch[] = "--reserved_at_zero=";
41 11 : int argc = *argc_p;
42 11 : char **argv = *argv_p;
43 : char *argv0;
44 :
45 11 : if (argc == 0)
46 11 : return;
47 11 : argv0 = argv[0];
48 :
49 22 : if (argc > 1 &&
50 11 : 0 == strncmp(argv[1], kRDebugSwitch, sizeof(kRDebugSwitch) - 1)) {
51 11 : NaClHandleRDebug(&argv[1][sizeof(kRDebugSwitch) - 1], argv[0]);
52 11 : --argc;
53 11 : ++argv;
54 : }
55 :
56 22 : if (argc > 1 &&
57 11 : 0 == strncmp(argv[1], kAtZeroSwitch, sizeof(kAtZeroSwitch) - 1)) {
58 11 : NaClHandleReservedAtZero(&argv[1][sizeof(kAtZeroSwitch) - 1]);
59 11 : --argc;
60 11 : ++argv;
61 : }
62 :
63 11 : *argc_p = argc;
64 11 : *argv_p = argv;
65 11 : (*argv_p)[0] = argv0;
66 : }
|