]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/namespace.h
lxc: switch to SPDX
[mirror_lxc.git] / src / lxc / namespace.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #ifndef __LXC_NAMESPACE_H
4 #define __LXC_NAMESPACE_H
5
6 #include <sched.h>
7 #include <unistd.h>
8 #include <sys/syscall.h>
9
10 #ifndef CLONE_PARENT_SETTID
11 #define CLONE_PARENT_SETTID 0x00100000
12 #endif
13
14 #ifndef CLONE_CHILD_CLEARTID
15 #define CLONE_CHILD_CLEARTID 0x00200000
16 #endif
17
18 #ifndef CLONE_CHILD_SETTID
19 #define CLONE_CHILD_SETTID 0x01000000
20 #endif
21
22 #ifndef CLONE_VFORK
23 #define CLONE_VFORK 0x00004000
24 #endif
25
26 #ifndef CLONE_THREAD
27 #define CLONE_THREAD 0x00010000
28 #endif
29
30 #ifndef CLONE_SETTLS
31 #define CLONE_SETTLS 0x00080000
32 #endif
33
34 #ifndef CLONE_VM
35 #define CLONE_VM 0x00000100
36 #endif
37
38 #ifndef CLONE_FILES
39 #define CLONE_FILES 0x00000400
40 #endif
41
42 #ifndef CLONE_FS
43 # define CLONE_FS 0x00000200
44 #endif
45 #ifndef CLONE_NEWNS
46 # define CLONE_NEWNS 0x00020000
47 #endif
48 #ifndef CLONE_NEWCGROUP
49 # define CLONE_NEWCGROUP 0x02000000
50 #endif
51 #ifndef CLONE_NEWUTS
52 # define CLONE_NEWUTS 0x04000000
53 #endif
54 #ifndef CLONE_NEWIPC
55 # define CLONE_NEWIPC 0x08000000
56 #endif
57 #ifndef CLONE_NEWUSER
58 # define CLONE_NEWUSER 0x10000000
59 #endif
60 #ifndef CLONE_NEWPID
61 # define CLONE_NEWPID 0x20000000
62 #endif
63 #ifndef CLONE_NEWNET
64 # define CLONE_NEWNET 0x40000000
65 #endif
66
67 enum {
68 LXC_NS_USER,
69 LXC_NS_MNT,
70 LXC_NS_PID,
71 LXC_NS_UTS,
72 LXC_NS_IPC,
73 LXC_NS_NET,
74 LXC_NS_CGROUP,
75 LXC_NS_MAX
76 };
77
78 extern const struct ns_info {
79 const char *proc_name;
80 int clone_flag;
81 const char *flag_name;
82 const char *env_name;
83 } ns_info[LXC_NS_MAX];
84
85 #if defined(__ia64__)
86 int __clone2(int (*__fn) (void *__arg), void *__child_stack_base,
87 size_t __child_stack_size, int __flags, void *__arg, ...);
88 #else
89 int clone(int (*fn)(void *), void *child_stack,
90 int flags, void *arg, ...
91 /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
92 #endif
93
94 /**
95 * lxc_clone() - create a new process
96 *
97 * - allocate stack:
98 * This function allocates a new stack the size of page and passes it to the
99 * kernel.
100 *
101 * - support all CLONE_*flags:
102 * This function supports all CLONE_* flags. If in doubt or not sufficiently
103 * familiar with process creation in the kernel and interactions with libcs
104 * this function should be used.
105 *
106 * - pthread_atfork() handlers depending on libc:
107 * Whether this function runs pthread_atfork() handlers depends on the
108 * corresponding libc wrapper. glibc currently does not run pthread_atfork()
109 * handlers but does not guarantee that they are not. Other libcs might or
110 * might not run pthread_atfork() handlers. If you require guarantees please
111 * refer to the lxc_raw_clone*() functions in raw_syscalls.{c,h}.
112 *
113 * - should call lxc_raw_getpid():
114 * The child should use lxc_raw_getpid() to retrieve its pid.
115 */
116 extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
117
118 extern int lxc_namespace_2_cloneflag(const char *namespace);
119 extern int lxc_namespace_2_ns_idx(const char *namespace);
120 extern int lxc_namespace_2_std_identifiers(char *namespaces);
121 extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
122
123 #endif