ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Linux-Clone/Clone.xs
(Generate patch)

Comparing Linux-Clone/Clone.xs (file contents):
Revision 1.5 by root, Mon Jul 25 10:59:29 2022 UTC vs.
Revision 1.10 by root, Fri Jul 7 07:47:03 2023 UTC

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)
105# ifdef CLONE_NEWIPC 122# ifdef CLONE_NEWIPC
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)
127# endif
128# ifdef CLONE_NEWTIME
129 const_iv_clone (NEWTIME)
110# endif 130# endif
111# ifdef CLONE_PTRACE 131# ifdef CLONE_PTRACE
112 const_iv_clone (PTRACE) 132 const_iv_clone (PTRACE)
113# endif 133# endif
114# ifdef CLONE_VFORK 134# ifdef CLONE_VFORK
153 const_iv (KCMP_FILES) 173 const_iv (KCMP_FILES)
154 const_iv (KCMP_FS) 174 const_iv (KCMP_FS)
155 const_iv (KCMP_SIGHAND) 175 const_iv (KCMP_SIGHAND)
156 const_iv (KCMP_IO) 176 const_iv (KCMP_IO)
157 const_iv (KCMP_SYSVSEM) 177 const_iv (KCMP_SYSVSEM)
158 const_iv (KCMP_FILE) 178 const_iv (KCMP_EPOLL_TFD)
179# endif
180# ifdef NS_GET_USERNS
181 const_iv (NS_GET_USERNS)
182# endif
183# ifdef NS_GET_PARENT
184 const_iv (NS_GET_PARENT)
185# endif
186# ifdef NS_GET_NSTYPE
187 const_iv (NS_GET_NSTYPE)
188# endif
189# ifdef NS_OWNER_UID
190 const_iv (NS_OWNER_UID
159# endif 191# endif
160 }; 192 };
161 193
162 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 194 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
163 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 195 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
191 munmap (stack_ptr, stacksize); 223 munmap (stack_ptr, stacksize);
192 errno = old_errno; 224 errno = old_errno;
193 } 225 }
194 } 226 }
195} 227}
196 OUTPUT: 228 OUTPUT: RETVAL
197 RETVAL
198 229
199int 230int
200unshare (int flags) 231unshare (int flags)
232 PROTOTYPE: @
201 233
202int 234int
203setns (SV *fh_or_fd, int nstype = 0) 235setns (SV *fh_or_fd, int nstype = 0)
204 C_ARGS: s_fileno (fh_or_fd, 0), nstype 236 C_ARGS: s_fileno (fh_or_fd, 0), nstype
205 237
207pivot_root (SV *new_root, SV *old_root) 239pivot_root (SV *new_root, SV *old_root)
208 CODE: 240 CODE:
209 RETVAL = syscall (SYS_pivot_root, 241 RETVAL = syscall (SYS_pivot_root,
210 (const char *)SvPVbyte_nolen (new_root), 242 (const char *)SvPVbyte_nolen (new_root),
211 (const char *)SvPVbyte_nolen (old_root)); 243 (const char *)SvPVbyte_nolen (old_root));
212 OUTPUT: 244 OUTPUT: RETVAL
213 RETVAL
214 245
215int 246int
216kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) 247kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0)
217 248
249int
250siocsifflags (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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines