… | |
… | |
6 | #include <sys/mman.h> |
6 | #include <sys/mman.h> |
7 | |
7 | |
8 | #undef _GNU_SOURCE |
8 | #undef _GNU_SOURCE |
9 | #define _GNU_SOURCE |
9 | #define _GNU_SOURCE |
10 | #include <sched.h> |
10 | #include <sched.h> |
|
|
11 | #include <unistd.h> |
|
|
12 | #include <sys/syscall.h> |
|
|
13 | |
|
|
14 | #include <sched.h> |
|
|
15 | |
|
|
16 | #include <sys/ioctl.h> |
|
|
17 | #include <net/if.h> |
|
|
18 | |
|
|
19 | #include <linux/nsfs.h> |
|
|
20 | |
|
|
21 | #ifdef __has_include |
|
|
22 | #if !__has_include("linux/kcmp.h") // use "" as GCC wrongly expands macros |
|
|
23 | #undef SYS_kcmp |
|
|
24 | #endif |
|
|
25 | #endif |
|
|
26 | |
|
|
27 | #ifdef SYS_kcmp |
|
|
28 | #include "linux/kcmp.h" |
|
|
29 | #define kcmp(pid1,pid2,type,idx1,idx2) \ |
|
|
30 | syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \ |
|
|
31 | (int)type, (unsigned long)idx1, (unsigned long)idx2) |
|
|
32 | #else |
|
|
33 | #define kcmp(pid1,pid2,type,idx1,idx2) \ |
|
|
34 | (errno = ENOSYS, -1) |
|
|
35 | #endif |
11 | |
36 | |
12 | /* from schmorp.h */ |
37 | /* from schmorp.h */ |
13 | static int |
38 | static int |
14 | s_fileno (SV *fh, int wr) |
39 | s_fileno (SV *fh, int wr) |
15 | { |
40 | { |
… | |
… | |
56 | |
81 | |
57 | static const struct { |
82 | static const struct { |
58 | const char *name; |
83 | const char *name; |
59 | IV iv; |
84 | IV iv; |
60 | } *civ, const_iv[] = { |
85 | } *civ, const_iv[] = { |
|
|
86 | # define const_iv(name) { # name, (IV)name }, |
61 | # define const_iv(name) { # name, (IV) CLONE_ ## name }, |
87 | # define const_iv_clone(name) { # name, (IV) CLONE_ ## name }, |
|
|
88 | # ifdef CSIGNAL |
|
|
89 | const_iv (CSIGNAL) |
|
|
90 | # endif |
62 | # ifdef CLONE_FILES |
91 | # ifdef CLONE_FILES |
63 | const_iv (FILES) |
92 | const_iv_clone (FILES) |
64 | # endif |
93 | # endif |
65 | # ifdef CLONE_FS |
94 | # ifdef CLONE_FS |
66 | const_iv (FS) |
95 | const_iv_clone (FS) |
67 | # endif |
96 | # endif |
68 | # ifdef CLONE_NEWNS |
97 | # ifdef CLONE_NEWNS |
69 | const_iv (NEWNS) |
98 | const_iv_clone (NEWNS) |
70 | # endif |
99 | # endif |
71 | # ifdef CLONE_VM |
100 | # ifdef CLONE_VM |
72 | const_iv (VM) |
101 | const_iv_clone (VM) |
73 | # endif |
102 | # endif |
74 | # ifdef CLONE_THREAD |
103 | # ifdef CLONE_THREAD |
75 | const_iv (THREAD) |
104 | const_iv_clone (THREAD) |
76 | # endif |
105 | # endif |
77 | # ifdef CLONE_SIGHAND |
106 | # ifdef CLONE_SIGHAND |
78 | const_iv (SIGHAND) |
107 | const_iv_clone (SIGHAND) |
79 | # endif |
108 | # endif |
80 | # ifdef CLONE_SYSVSEM |
109 | # ifdef CLONE_SYSVSEM |
81 | const_iv (SYSVSEM) |
110 | const_iv_clone (SYSVSEM) |
82 | # endif |
111 | # endif |
83 | # ifdef CLONE_NEWUTS |
112 | # ifdef CLONE_NEWUTS |
84 | const_iv (NEWUTS) |
113 | const_iv_clone (NEWUTS) |
85 | # endif |
114 | # endif |
86 | # ifdef CLONE_NEWIPC |
115 | # ifdef CLONE_NEWIPC |
87 | const_iv (NEWIPC) |
116 | const_iv_clone (NEWIPC) |
88 | # endif |
117 | # endif |
89 | # ifdef CLONE_NEWNET |
118 | # ifdef CLONE_NEWNET |
90 | const_iv (NEWNET) |
119 | const_iv_clone (NEWNET) |
91 | # endif |
120 | # endif |
92 | # ifdef CLONE_PTRACE |
121 | # ifdef CLONE_PTRACE |
93 | const_iv (PTRACE) |
122 | const_iv_clone (PTRACE) |
94 | # endif |
123 | # endif |
95 | # ifdef CLONE_VFORK |
124 | # ifdef CLONE_VFORK |
96 | const_iv (VFORK) |
125 | const_iv_clone (VFORK) |
97 | # endif |
126 | # endif |
98 | # ifdef CLONE_SETTLS |
127 | # ifdef CLONE_SETTLS |
99 | const_iv (SETTLS) |
128 | const_iv_clone (SETTLS) |
100 | # endif |
129 | # endif |
101 | # ifdef CLONE_PARENT_SETTID |
130 | # ifdef CLONE_PARENT_SETTID |
102 | const_iv (PARENT_SETTID) |
131 | const_iv_clone (PARENT_SETTID) |
103 | # endif |
132 | # endif |
104 | # ifdef CLONE_CHILD_CLEARTID |
133 | # ifdef CLONE_CHILD_CLEARTID |
105 | const_iv (CHILD_CLEARTID) |
134 | const_iv_clone (CHILD_CLEARTID) |
106 | # endif |
135 | # endif |
107 | # ifdef CLONE_DETACHED |
136 | # ifdef CLONE_DETACHED |
108 | const_iv (DETACHED) |
137 | const_iv_clone (DETACHED) |
109 | # endif |
138 | # endif |
110 | # ifdef CLONE_UNTRACED |
139 | # ifdef CLONE_UNTRACED |
111 | const_iv (UNTRACED) |
140 | const_iv_clone (UNTRACED) |
112 | # endif |
141 | # endif |
113 | # ifdef CLONE_CHILD_SETTID |
142 | # ifdef CLONE_CHILD_SETTID |
114 | const_iv (CHILD_SETTID) |
143 | const_iv_clone (CHILD_SETTID) |
115 | # endif |
144 | # endif |
116 | # ifdef CLONE_NEWUSER |
145 | # ifdef CLONE_NEWUSER |
117 | const_iv (NEWUSER) |
146 | const_iv_clone (NEWUSER) |
118 | # endif |
147 | # endif |
119 | # ifdef CLONE_NEWPID |
148 | # ifdef CLONE_NEWPID |
120 | const_iv (NEWPID) |
149 | const_iv_clone (NEWPID) |
121 | # endif |
150 | # endif |
122 | # ifdef CLONE_IO |
151 | # ifdef CLONE_IO |
123 | const_iv (IO) |
152 | const_iv_clone (IO) |
124 | # endif |
153 | # endif |
125 | # ifdef CLONE_NEWCGROUP |
154 | # ifdef CLONE_NEWCGROUP |
126 | const_iv (NEWCGROUP) |
155 | const_iv_clone (NEWCGROUP) |
|
|
156 | # endif |
|
|
157 | # ifdef CLONE_PIDFD |
|
|
158 | const_iv_clone (PIDFD) |
|
|
159 | # endif |
|
|
160 | # ifdef SYS_kcmp |
|
|
161 | const_iv (KCMP_FILE) |
|
|
162 | const_iv (KCMP_VM) |
|
|
163 | const_iv (KCMP_FILES) |
|
|
164 | const_iv (KCMP_FS) |
|
|
165 | const_iv (KCMP_SIGHAND) |
|
|
166 | const_iv (KCMP_IO) |
|
|
167 | const_iv (KCMP_SYSVSEM) |
|
|
168 | const_iv (KCMP_FILE) |
|
|
169 | # endif |
|
|
170 | # ifdef NS_GET_USERNS |
|
|
171 | const_iv (NS_GET_USERNS) |
|
|
172 | # endif |
|
|
173 | # ifdef NS_GET_PARENT |
|
|
174 | const_iv (NS_GET_PARENT) |
|
|
175 | # endif |
|
|
176 | # ifdef NS_GET_NSTYPE |
|
|
177 | const_iv (NS_GET_NSTYPE) |
|
|
178 | # endif |
|
|
179 | # ifdef NS_OWNER_UID |
|
|
180 | const_iv (NS_OWNER_UID |
127 | # endif |
181 | # endif |
128 | }; |
182 | }; |
129 | |
183 | |
130 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
184 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
131 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
185 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
… | |
… | |
159 | munmap (stack_ptr, stacksize); |
213 | munmap (stack_ptr, stacksize); |
160 | errno = old_errno; |
214 | errno = old_errno; |
161 | } |
215 | } |
162 | } |
216 | } |
163 | } |
217 | } |
164 | OUTPUT: |
218 | OUTPUT: RETVAL |
165 | RETVAL |
|
|
166 | |
219 | |
167 | int |
220 | int |
168 | unshare (int flags) |
221 | unshare (int flags) |
169 | |
222 | |
170 | int |
223 | int |
171 | setns (SV *fh_or_fd, int nstype = 0) |
224 | setns (SV *fh_or_fd, int nstype = 0) |
172 | C_ARGS: s_fileno (fh_or_fd, 0), nstype |
225 | C_ARGS: s_fileno (fh_or_fd, 0), nstype |
|
|
226 | |
|
|
227 | int |
|
|
228 | pivot_root (SV *new_root, SV *old_root) |
|
|
229 | CODE: |
|
|
230 | RETVAL = syscall (SYS_pivot_root, |
|
|
231 | (const char *)SvPVbyte_nolen (new_root), |
|
|
232 | (const char *)SvPVbyte_nolen (old_root)); |
|
|
233 | OUTPUT: RETVAL |
|
|
234 | |
|
|
235 | int |
|
|
236 | kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) |
|
|
237 | |
|
|
238 | int |
|
|
239 | siocsifflags (char *ifname, U32 flags = IFF_UP) |
|
|
240 | CODE: |
|
|
241 | { |
|
|
242 | int saved_errno; |
|
|
243 | struct ifreq ifr; |
|
|
244 | int fd = socket (AF_INET, SOCK_DGRAM, 0); |
|
|
245 | strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); |
|
|
246 | RETVAL = ioctl (fd, SIOCSIFFLAGS, &ifr); |
|
|
247 | saved_errno = errno; |
|
|
248 | close (fd); |
|
|
249 | errno = saved_errno; |
|
|
250 | } |
|
|
251 | OUTPUT: RETVAL |
|
|
252 | |