… | |
… | |
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> |
11 | #include <unistd.h> |
12 | #include <sys/syscall.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 | #include <linux/kcmp.h> |
|
|
21 | |
|
|
22 | /* kcmp.h does not define symbols, so there is no way to detect preesence of enum */ |
|
|
23 | /* members, so we just hardcode new symbols here. */ |
|
|
24 | #ifndef KCMP_EPOLL_TFD |
|
|
25 | #define KCMP_EPOLL_TFD 7 |
|
|
26 | #endif |
13 | |
27 | |
14 | #ifdef __has_include |
28 | #ifdef __has_include |
15 | #if !__has_include("linux/kcmp.h") // use "" as GCC wrongly expands macros |
29 | #if !__has_include("linux/kcmp.h") // use "" as GCC wrongly expands macros |
16 | #undef SYS_kcmp |
30 | #undef SYS_kcmp |
17 | #endif |
31 | #endif |
… | |
… | |
76 | const char *name; |
90 | const char *name; |
77 | IV iv; |
91 | IV iv; |
78 | } *civ, const_iv[] = { |
92 | } *civ, const_iv[] = { |
79 | # define const_iv(name) { # name, (IV)name }, |
93 | # define const_iv(name) { # name, (IV)name }, |
80 | # define const_iv_clone(name) { # name, (IV) CLONE_ ## name }, |
94 | # define const_iv_clone(name) { # name, (IV) CLONE_ ## name }, |
|
|
95 | # ifdef CSIGNAL |
|
|
96 | const_iv (CSIGNAL) |
|
|
97 | # endif |
81 | # ifdef CLONE_FILES |
98 | # ifdef CLONE_FILES |
82 | const_iv_clone (FILES) |
99 | const_iv_clone (FILES) |
83 | # endif |
100 | # endif |
84 | # ifdef CLONE_FS |
101 | # ifdef CLONE_FS |
85 | const_iv_clone (FS) |
102 | const_iv_clone (FS) |
… | |
… | |
106 | const_iv_clone (NEWIPC) |
123 | const_iv_clone (NEWIPC) |
107 | # endif |
124 | # endif |
108 | # ifdef CLONE_NEWNET |
125 | # ifdef CLONE_NEWNET |
109 | const_iv_clone (NEWNET) |
126 | const_iv_clone (NEWNET) |
110 | # endif |
127 | # endif |
|
|
128 | # ifdef CLONE_NEWTIME |
|
|
129 | x |
|
|
130 | const_iv_clone (NEWTIME) |
|
|
131 | # endif |
111 | # ifdef CLONE_PTRACE |
132 | # ifdef CLONE_PTRACE |
112 | const_iv_clone (PTRACE) |
133 | const_iv_clone (PTRACE) |
113 | # endif |
134 | # endif |
114 | # ifdef CLONE_VFORK |
135 | # ifdef CLONE_VFORK |
115 | const_iv_clone (VFORK) |
136 | const_iv_clone (VFORK) |
… | |
… | |
141 | # ifdef CLONE_IO |
162 | # ifdef CLONE_IO |
142 | const_iv_clone (IO) |
163 | const_iv_clone (IO) |
143 | # endif |
164 | # endif |
144 | # ifdef CLONE_NEWCGROUP |
165 | # ifdef CLONE_NEWCGROUP |
145 | const_iv_clone (NEWCGROUP) |
166 | const_iv_clone (NEWCGROUP) |
|
|
167 | # endif |
|
|
168 | # ifdef CLONE_PIDFD |
|
|
169 | const_iv_clone (PIDFD) |
146 | # endif |
170 | # endif |
147 | # ifdef SYS_kcmp |
171 | # ifdef SYS_kcmp |
148 | const_iv (KCMP_FILE) |
172 | const_iv (KCMP_FILE) |
149 | const_iv (KCMP_VM) |
173 | const_iv (KCMP_VM) |
150 | const_iv (KCMP_FILES) |
174 | const_iv (KCMP_FILES) |
151 | const_iv (KCMP_FS) |
175 | const_iv (KCMP_FS) |
152 | const_iv (KCMP_SIGHAND) |
176 | const_iv (KCMP_SIGHAND) |
153 | const_iv (KCMP_IO) |
177 | const_iv (KCMP_IO) |
154 | const_iv (KCMP_SYSVSEM) |
178 | const_iv (KCMP_SYSVSEM) |
155 | const_iv (KCMP_FILE) |
179 | const_iv (KCMP_EPOLL_TFD) |
|
|
180 | # endif |
|
|
181 | # ifdef NS_GET_USERNS |
|
|
182 | const_iv (NS_GET_USERNS) |
|
|
183 | # endif |
|
|
184 | # ifdef NS_GET_PARENT |
|
|
185 | const_iv (NS_GET_PARENT) |
|
|
186 | # endif |
|
|
187 | # ifdef NS_GET_NSTYPE |
|
|
188 | const_iv (NS_GET_NSTYPE) |
|
|
189 | # endif |
|
|
190 | # ifdef NS_OWNER_UID |
|
|
191 | const_iv (NS_OWNER_UID |
156 | # endif |
192 | # endif |
157 | }; |
193 | }; |
158 | |
194 | |
159 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
195 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
160 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
196 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
… | |
… | |
188 | munmap (stack_ptr, stacksize); |
224 | munmap (stack_ptr, stacksize); |
189 | errno = old_errno; |
225 | errno = old_errno; |
190 | } |
226 | } |
191 | } |
227 | } |
192 | } |
228 | } |
193 | OUTPUT: |
229 | OUTPUT: RETVAL |
194 | RETVAL |
|
|
195 | |
230 | |
196 | int |
231 | int |
197 | unshare (int flags) |
232 | unshare (int flags) |
198 | |
233 | |
199 | int |
234 | int |
… | |
… | |
204 | pivot_root (SV *new_root, SV *old_root) |
239 | pivot_root (SV *new_root, SV *old_root) |
205 | CODE: |
240 | CODE: |
206 | RETVAL = syscall (SYS_pivot_root, |
241 | RETVAL = syscall (SYS_pivot_root, |
207 | (const char *)SvPVbyte_nolen (new_root), |
242 | (const char *)SvPVbyte_nolen (new_root), |
208 | (const char *)SvPVbyte_nolen (old_root)); |
243 | (const char *)SvPVbyte_nolen (old_root)); |
209 | OUTPUT: |
244 | OUTPUT: RETVAL |
210 | RETVAL |
|
|
211 | |
245 | |
212 | int |
246 | int |
213 | kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) |
247 | kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) |
214 | |
248 | |
|
|
249 | int |
|
|
250 | siocsifflags (char *ifname, U32 flags = IFF_UP) |
|
|
251 | CODE: |
|
|
252 | { |
|
|
253 | int saved_errno; |
|
|
254 | struct ifreq ifr; |
|
|
255 | int fd = socket (AF_INET, SOCK_DGRAM, 0); |
|
|
256 | strncpy (ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); |
|
|
257 | RETVAL = ioctl (fd, SIOCSIFFLAGS, &ifr); |
|
|
258 | saved_errno = errno; |
|
|
259 | close (fd); |
|
|
260 | errno = saved_errno; |
|
|
261 | } |
|
|
262 | OUTPUT: RETVAL |
|
|
263 | |