1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <cstdio>
18 #include <string>
19 
20 #include "berberis/program_runner/program_runner.h"
21 
22 // Basic program runner meant to be used by binfmt_misc utility.
23 
main(int argc,const char * argv[],char * envp[])24 int main(int argc, const char* argv[], char* envp[]) {
25   if (argc < 3) {
26     printf("Usage: %s /full/path/to/program program [args...]", argv[0]);
27     return 0;
28   }
29 
30   std::string error_msg;
31   if (!berberis::Run(
32           /* vdso_path */ nullptr,
33           /* loader_path */ nullptr,
34           argc - 2,
35           &argv[2],
36           envp,
37           &error_msg)) {
38     fprintf(stderr, "Error running %s: %s", argv[1], error_msg.c_str());
39     return -1;
40   }
41 }