]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/namespace.h
Merge pull request #3059 from brauner/2019-06-21/seccomp_notify
[mirror_lxc.git] / src / lxc / namespace.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2009
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef __LXC_NAMESPACE_H
24 #define __LXC_NAMESPACE_H
25
26 #include <sched.h>
27 #include <unistd.h>
28 #include <sys/syscall.h>
29
30 #ifndef CLONE_PARENT_SETTID
31 #define CLONE_PARENT_SETTID 0x00100000
32 #endif
33
34 #ifndef CLONE_CHILD_CLEARTID
35 #define CLONE_CHILD_CLEARTID 0x00200000
36 #endif
37
38 #ifndef CLONE_CHILD_SETTID
39 #define CLONE_CHILD_SETTID 0x01000000
40 #endif
41
42 #ifndef CLONE_VFORK
43 #define CLONE_VFORK 0x00004000
44 #endif
45
46 #ifndef CLONE_THREAD
47 #define CLONE_THREAD 0x00010000
48 #endif
49
50 #ifndef CLONE_SETTLS
51 #define CLONE_SETTLS 0x00080000
52 #endif
53
54 #ifndef CLONE_VM
55 #define CLONE_VM 0x00000100
56 #endif
57
58 #ifndef CLONE_FILES
59 #define CLONE_FILES 0x00000400
60 #endif
61
62 #ifndef CLONE_FS
63 # define CLONE_FS 0x00000200
64 #endif
65 #ifndef CLONE_NEWNS
66 # define CLONE_NEWNS 0x00020000
67 #endif
68 #ifndef CLONE_NEWCGROUP
69 # define CLONE_NEWCGROUP 0x02000000
70 #endif
71 #ifndef CLONE_NEWUTS
72 # define CLONE_NEWUTS 0x04000000
73 #endif
74 #ifndef CLONE_NEWIPC
75 # define CLONE_NEWIPC 0x08000000
76 #endif
77 #ifndef CLONE_NEWUSER
78 # define CLONE_NEWUSER 0x10000000
79 #endif
80 #ifndef CLONE_NEWPID
81 # define CLONE_NEWPID 0x20000000
82 #endif
83 #ifndef CLONE_NEWNET
84 # define CLONE_NEWNET 0x40000000
85 #endif
86
87 enum {
88 LXC_NS_USER,
89 LXC_NS_MNT,
90 LXC_NS_PID,
91 LXC_NS_UTS,
92 LXC_NS_IPC,
93 LXC_NS_NET,
94 LXC_NS_CGROUP,
95 LXC_NS_MAX
96 };
97
98 extern const struct ns_info {
99 const char *proc_name;
100 int clone_flag;
101 const char *flag_name;
102 const char *env_name;
103 } ns_info[LXC_NS_MAX];
104
105 #if defined(__ia64__)
106 int __clone2(int (*__fn) (void *__arg), void *__child_stack_base,
107 size_t __child_stack_size, int __flags, void *__arg, ...);
108 #else
109 int clone(int (*fn)(void *), void *child_stack,
110 int flags, void *arg, ...
111 /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
112 #endif
113
114 /**
115 * lxc_clone() - create a new process
116 *
117 * - allocate stack:
118 * This function allocates a new stack the size of page and passes it to the
119 * kernel.
120 *
121 * - support all CLONE_*flags:
122 * This function supports all CLONE_* flags. If in doubt or not sufficiently
123 * familiar with process creation in the kernel and interactions with libcs
124 * this function should be used.
125 *
126 * - pthread_atfork() handlers depending on libc:
127 * Whether this function runs pthread_atfork() handlers depends on the
128 * corresponding libc wrapper. glibc currently does not run pthread_atfork()
129 * handlers but does not guarantee that they are not. Other libcs might or
130 * might not run pthread_atfork() handlers. If you require guarantees please
131 * refer to the lxc_raw_clone*() functions in raw_syscalls.{c,h}.
132 *
133 * - should call lxc_raw_getpid():
134 * The child should use lxc_raw_getpid() to retrieve its pid.
135 */
136 extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
137
138 extern int lxc_namespace_2_cloneflag(const char *namespace);
139 extern int lxc_namespace_2_ns_idx(const char *namespace);
140 extern int lxc_namespace_2_std_identifiers(char *namespaces);
141 extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
142
143 #endif