xref: /aosp_15_r20/external/minijail/libminijail-private.h (revision 4b9c6d91573e8b3a96609339b46361b5476dd0f9)
1 /* libminijail-private.h
2  * Copyright 2011 The ChromiumOS Authors
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  *
6  * Values shared between libminijailpreload and libminijail, but not visible to
7  * the outside world.
8  */
9 
10 #ifndef LIBMINIJAIL_PRIVATE_H
11 #define LIBMINIJAIL_PRIVATE_H
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
17 /* Explicitly declare exported functions so that -fvisibility tricks
18  * can be used for testing and minimal symbol leakage occurs.
19  */
20 #define API __attribute__((__visibility__("default")))
21 
22 static const char kFdEnvVar[] = "__MINIJAIL_FD";
23 static const char kLdPreloadEnvVar[] = "LD_PRELOAD";
24 static const char kSeccompPolicyPathEnvVar[] = "SECCOMP_POLICY_PATH";
25 
26 struct minijail;
27 
28 /* minijail_size: returns the size (in bytes) of @j if marshalled
29  * @j jail to compute size of
30  *
31  * Returns 0 on error.
32  */
33 extern size_t minijail_size(const struct minijail *j);
34 
35 /* minijail_marshal: serializes @j to @buf
36  * @j    minijail to serialize
37  * @buf  buffer to serialize to
38  * @size size of @buf
39  *
40  * Returns 0 on success.
41  *
42  * Writes |j| to |buf| such that it can be reparsed by the same
43  * library on the same architecture.  This is meant to be used
44  * by minijail0.c and libminijailpreload.c.  minijail flags that
45  * require minijail_run() will be excluded.
46  *
47  * The marshalled data is not robust to differences between the child
48  * and parent process (personality, etc).
49  */
50 extern int minijail_marshal(const struct minijail *j, char *buf, size_t size);
51 
52 /* minijail_unmarshal: initializes @j from @serialized
53  * @j          minijail to initialize
54  * @serialized serialized jail buffer
55  * @length     length of buffer
56  *
57  * Returns 0 on success.
58  */
59 extern int minijail_unmarshal(struct minijail *j, char *serialized,
60 			      size_t length);
61 
62 /* minijail_from_fd: builds @j from @fd
63  * @j  minijail to initialize
64  * @fd fd to initialize from
65  *
66  * Returns 0 on success.
67  */
68 extern int minijail_from_fd(int fd, struct minijail *j);
69 
70 /* minijail_to_fd: sends @j over @fd
71  * @j  minijail to send
72  * @fd fd to send over
73  *
74  * Returns 0 on success, or a negative error code on error.
75  */
76 extern int minijail_to_fd(struct minijail *j, int fd);
77 
78 /* minijail_preexec: strips @j of all options handled by minijail_enter()
79  * @j jail to strip
80  */
81 extern void minijail_preexec(struct minijail *j);
82 
83 /* minijail_preenter: strips @j of all options handled by minijail_run()
84  * @j jail to strip
85  */
86 extern void minijail_preenter(struct minijail *j);
87 
88 #ifdef __cplusplus
89 }; /* extern "C" */
90 #endif
91 
92 #endif /* !LIBMINIJAIL_PRIVATE_H */
93