• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #ifndef LOADER_H
13 #define LOADER_H
14 
15 #include "liblaunch.h"
16 
17 /**
18  * This struct represents an abstract program loader.
19  * A program loader can be used to launch a dynamically linked
20  * program. When doing so, the loader itself would be launched
21  * as a process first, then it would load and dynamically link
22  * the really program to be run in its address space.
23  */
24 struct loader;
25 
26 /**
27  * @brief Get a loader object by its path. Thread-Safe.
28  *
29  * By default, this function would cache loader objects used before.
30  * And returning the same loader object if it used to be invoked.
31  * As a loader file would be specified by many dynamically linked programs, it's
32  * would be useful to reuse memory consumed by this loader(including the loader
33  * object, file content loaded into memory for this loader, and maybe other
34  * memory depending on loader object implementation), instead of creating
35  * multiple loader objects for the same loader file.
36  *
37  * @param loader_path [In]
38  * @param loader [Out] WARNING: the returning pointer is owned by this function,
39  * and caller just borrow it. Caller is not allowed to free this pointer,
40  * otherwise the behavior is undefined.
41  * @return 0 if success, otherwise -errno is returned. All memory resources
42  * consumed by this function are guaranteed to be freed if not success.
43  */
44 int find_loader(const char* loader_path, struct loader** loader);
45 
46 /**
47  * @brief Launch a dynamically linked program using given loader. Thread-Safe.
48  *
49  * @param this [In] loader object to be used
50  * @param lp_args [In] WARNING: This function just borrow the pointer. Caller
51  * owns this pointer, So it's the caller's responsibility to free it if it's a
52  * heap pointer.
53  * @return 0 if success, otherwise -errno is returned. All memory resources
54  * consumed by this function are guaranteed to be freed if not success.
55  */
56 int launch_process_using_loader(struct loader* this,
57                                 struct launch_process_args* lp_args);
58 
59 #endif /* LOADER_H */