blob: 6351f8ea2fe17fdfe5751766a39c9c60237aac6c [file] [log] [blame]
Elly Jonescd7a9042011-07-22 13:56:51 -04001/* libminijail-private.h
Mike Frysinger4c331892022-09-13 05:17:08 -04002 * Copyright 2011 The ChromiumOS Authors
Elly Jonescd7a9042011-07-22 13:56:51 -04003 * 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
Jorge Lucangeli Obesa67bd6a2016-08-19 15:33:48 -040013#ifdef __cplusplus
14extern "C" {
15#endif
16
Will Drewry6ac91122011-10-21 16:38:58 -050017/* Explicitly declare exported functions so that -fvisibility tricks
18 * can be used for testing and minimal symbol leakage occurs.
19 */
Mike Frysingerd9ef07c2018-05-30 16:51:36 -040020#define API __attribute__((__visibility__("default")))
Will Drewry6ac91122011-10-21 16:38:58 -050021
Zi Lin96db6fc2022-02-17 21:44:52 +000022static const char kFdEnvVar[] = "__MINIJAIL_FD";
23static const char kLdPreloadEnvVar[] = "LD_PRELOAD";
24static const char kSeccompPolicyPathEnvVar[] = "SECCOMP_POLICY_PATH";
Elly Jonescd7a9042011-07-22 13:56:51 -040025
Will Drewryf89aef52011-09-16 16:48:57 -050026struct minijail;
Elly Jonese1749eb2011-10-07 13:54:59 -040027
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.
Will Drewry2ddaad02011-09-16 11:36:08 -050032 */
33extern size_t minijail_size(const struct minijail *j);
Elly Jonese1749eb2011-10-07 13:54:59 -040034
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 *
Will Drewry2ddaad02011-09-16 11:36:08 -050042 * 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).
Will Drewry2ddaad02011-09-16 11:36:08 -050049 */
Allen Webb7ae41c22021-09-16 10:23:37 -050050extern int minijail_marshal(const struct minijail *j, char *buf, size_t size);
Elly Jonese1749eb2011-10-07 13:54:59 -040051
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 */
Allen Webb7ae41c22021-09-16 10:23:37 -050059extern int minijail_unmarshal(struct minijail *j, char *serialized,
60 size_t length);
Elly Jonese1749eb2011-10-07 13:54:59 -040061
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 */
Will Drewryfe4a3722011-09-16 14:50:50 -050068extern int minijail_from_fd(int fd, struct minijail *j);
Elly Jonese1749eb2011-10-07 13:54:59 -040069
70/* minijail_to_fd: sends @j over @fd
71 * @j minijail to send
72 * @fd fd to send over
73 *
François Degros664eba72019-11-05 13:18:24 +110074 * Returns 0 on success, or a negative error code on error.
Elly Jonese1749eb2011-10-07 13:54:59 -040075 */
Will Drewryfe4a3722011-09-16 14:50:50 -050076extern int minijail_to_fd(struct minijail *j, int fd);
Elly Jonese1749eb2011-10-07 13:54:59 -040077
78/* minijail_preexec: strips @j of all options handled by minijail_enter()
79 * @j jail to strip
80 */
Will Drewryfe4a3722011-09-16 14:50:50 -050081extern void minijail_preexec(struct minijail *j);
Elly Jonese1749eb2011-10-07 13:54:59 -040082
83/* minijail_preenter: strips @j of all options handled by minijail_run()
84 * @j jail to strip
85 */
Will Drewry2ddaad02011-09-16 11:36:08 -050086extern void minijail_preenter(struct minijail *j);
87
Jorge Lucangeli Obesa67bd6a2016-08-19 15:33:48 -040088#ifdef __cplusplus
89}; /* extern "C" */
90#endif
91
Elly Jonescd7a9042011-07-22 13:56:51 -040092#endif /* !LIBMINIJAIL_PRIVATE_H */