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.3 by root, Thu Nov 2 07:31:16 2017 UTC vs.
Revision 1.7 by root, Sat Sep 3 23:56:10 2022 UTC

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 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
14#ifdef SYS_kcmp 27#ifdef SYS_kcmp
15 #include <linux/kcmp.h> 28 #include "linux/kcmp.h"
16 #define kcmp(pid1,pid2,type,idx1,idx2) \ 29 #define kcmp(pid1,pid2,type,idx1,idx2) \
17 syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \ 30 syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \
18 (int)type, (unsigned long)idx1, (unsigned long)idx2) 31 (int)type, (unsigned long)idx1, (unsigned long)idx2)
19#else 32#else
20 #define kcmp(pid1,pid2,type,idx1,idx2) \ 33 #define kcmp(pid1,pid2,type,idx1,idx2) \
68 81
69 static const struct { 82 static const struct {
70 const char *name; 83 const char *name;
71 IV iv; 84 IV iv;
72 } *civ, const_iv[] = { 85 } *civ, const_iv[] = {
73# define const_iv(name) { # name, (IV)name }, 86# define const_iv(name) { # name, (IV)name },
87# define const_iv_clone(name) { # name, (IV) CLONE_ ## name },
88# ifdef CSIGNAL
89 const_iv (CSIGNAL)
90# endif
74# ifdef CLONE_FILES 91# ifdef CLONE_FILES
75 const_iv (CLONE_FILES) 92 const_iv_clone (FILES)
76# endif 93# endif
77# ifdef CLONE_FS 94# ifdef CLONE_FS
78 const_iv (CLONE_FS) 95 const_iv_clone (FS)
79# endif 96# endif
80# ifdef CLONE_NEWNS 97# ifdef CLONE_NEWNS
81 const_iv (CLONE_NEWNS) 98 const_iv_clone (NEWNS)
82# endif 99# endif
83# ifdef CLONE_VM 100# ifdef CLONE_VM
84 const_iv (CLONE_VM) 101 const_iv_clone (VM)
85# endif 102# endif
86# ifdef CLONE_THREAD 103# ifdef CLONE_THREAD
87 const_iv (CLONE_THREAD) 104 const_iv_clone (THREAD)
88# endif 105# endif
89# ifdef CLONE_SIGHAND 106# ifdef CLONE_SIGHAND
90 const_iv (CLONE_SIGHAND) 107 const_iv_clone (SIGHAND)
91# endif 108# endif
92# ifdef CLONE_SYSVSEM 109# ifdef CLONE_SYSVSEM
93 const_iv (CLONE_SYSVSEM) 110 const_iv_clone (SYSVSEM)
94# endif 111# endif
95# ifdef CLONE_NEWUTS 112# ifdef CLONE_NEWUTS
96 const_iv (CLONE_NEWUTS) 113 const_iv_clone (NEWUTS)
97# endif 114# endif
98# ifdef CLONE_NEWIPC 115# ifdef CLONE_NEWIPC
99 const_iv (CLONE_NEWIPC) 116 const_iv_clone (NEWIPC)
100# endif 117# endif
101# ifdef CLONE_NEWNET 118# ifdef CLONE_NEWNET
102 const_iv (CLONE_NEWNET) 119 const_iv_clone (NEWNET)
103# endif 120# endif
104# ifdef CLONE_PTRACE 121# ifdef CLONE_PTRACE
105 const_iv (CLONE_PTRACE) 122 const_iv_clone (PTRACE)
106# endif 123# endif
107# ifdef CLONE_VFORK 124# ifdef CLONE_VFORK
108 const_iv (CLONE_VFORK) 125 const_iv_clone (VFORK)
109# endif 126# endif
110# ifdef CLONE_SETTLS 127# ifdef CLONE_SETTLS
111 const_iv (CLONE_SETTLS) 128 const_iv_clone (SETTLS)
112# endif 129# endif
113# ifdef CLONE_PARENT_SETTID 130# ifdef CLONE_PARENT_SETTID
114 const_iv (CLONE_PARENT_SETTID) 131 const_iv_clone (PARENT_SETTID)
115# endif 132# endif
116# ifdef CLONE_CHILD_CLEARTID 133# ifdef CLONE_CHILD_CLEARTID
117 const_iv (CLONE_CHILD_CLEARTID) 134 const_iv_clone (CHILD_CLEARTID)
118# endif 135# endif
119# ifdef CLONE_DETACHED 136# ifdef CLONE_DETACHED
120 const_iv (CLONE_DETACHED) 137 const_iv_clone (DETACHED)
121# endif 138# endif
122# ifdef CLONE_UNTRACED 139# ifdef CLONE_UNTRACED
123 const_iv (CLONE_UNTRACED) 140 const_iv_clone (UNTRACED)
124# endif 141# endif
125# ifdef CLONE_CHILD_SETTID 142# ifdef CLONE_CHILD_SETTID
126 const_iv (CLONE_CHILD_SETTID) 143 const_iv_clone (CHILD_SETTID)
127# endif 144# endif
128# ifdef CLONE_NEWUSER 145# ifdef CLONE_NEWUSER
129 const_iv (CLONE_NEWUSER) 146 const_iv_clone (NEWUSER)
130# endif 147# endif
131# ifdef CLONE_NEWPID 148# ifdef CLONE_NEWPID
132 const_iv (CLONE_NEWPID) 149 const_iv_clone (NEWPID)
133# endif 150# endif
134# ifdef CLONE_IO 151# ifdef CLONE_IO
135 const_iv (CLONE_IO) 152 const_iv_clone (IO)
136# endif 153# endif
137# ifdef CLONE_NEWCGROUP 154# ifdef CLONE_NEWCGROUP
138 const_iv (CLONE_NEWCGROUP) 155 const_iv_clone (NEWCGROUP)
156# endif
157# ifdef CLONE_PIDFD
158 const_iv_clone (PIDFD)
139# endif 159# endif
140# ifdef SYS_kcmp 160# ifdef SYS_kcmp
141 const_iv (KCMP_FILE) 161 const_iv (KCMP_FILE)
142 const_iv (KCMP_VM) 162 const_iv (KCMP_VM)
143 const_iv (KCMP_FILES) 163 const_iv (KCMP_FILES)
145 const_iv (KCMP_SIGHAND) 165 const_iv (KCMP_SIGHAND)
146 const_iv (KCMP_IO) 166 const_iv (KCMP_IO)
147 const_iv (KCMP_SYSVSEM) 167 const_iv (KCMP_SYSVSEM)
148 const_iv (KCMP_FILE) 168 const_iv (KCMP_FILE)
149# endif 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
181# endif
150 }; 182 };
151 183
152 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--)
153 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 185 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
154 186
181 munmap (stack_ptr, stacksize); 213 munmap (stack_ptr, stacksize);
182 errno = old_errno; 214 errno = old_errno;
183 } 215 }
184 } 216 }
185} 217}
186 OUTPUT: 218 OUTPUT: RETVAL
187 RETVAL
188 219
189int 220int
190unshare (int flags) 221unshare (int flags)
191 222
192int 223int
197pivot_root (SV *new_root, SV *old_root) 228pivot_root (SV *new_root, SV *old_root)
198 CODE: 229 CODE:
199 RETVAL = syscall (SYS_pivot_root, 230 RETVAL = syscall (SYS_pivot_root,
200 (const char *)SvPVbyte_nolen (new_root), 231 (const char *)SvPVbyte_nolen (new_root),
201 (const char *)SvPVbyte_nolen (old_root)); 232 (const char *)SvPVbyte_nolen (old_root));
202 OUTPUT: 233 OUTPUT: RETVAL
203 RETVAL
204 234
205int 235int
206kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) 236kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0)
207 237
238int
239siocsifflags (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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines