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.10 by root, Fri Jul 7 07:47:03 2023 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#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
27
28#ifdef __has_include
29 #if !__has_include("linux/kcmp.h") // use "" as GCC wrongly expands macros
30 #undef SYS_kcmp
31 #endif
32#endif
33
14#ifdef SYS_kcmp 34#ifdef SYS_kcmp
15 #include <linux/kcmp.h> 35 #include "linux/kcmp.h"
16 #define kcmp(pid1,pid2,type,idx1,idx2) \ 36 #define kcmp(pid1,pid2,type,idx1,idx2) \
17 syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \ 37 syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \
18 (int)type, (unsigned long)idx1, (unsigned long)idx2) 38 (int)type, (unsigned long)idx1, (unsigned long)idx2)
19#else 39#else
20 #define kcmp(pid1,pid2,type,idx1,idx2) \ 40 #define kcmp(pid1,pid2,type,idx1,idx2) \
68 88
69 static const struct { 89 static const struct {
70 const char *name; 90 const char *name;
71 IV iv; 91 IV iv;
72 } *civ, const_iv[] = { 92 } *civ, const_iv[] = {
73# define const_iv(name) { # name, (IV)name }, 93# define const_iv(name) { # name, (IV)name },
94# define const_iv_clone(name) { # name, (IV) CLONE_ ## name },
95# ifdef CSIGNAL
96 const_iv (CSIGNAL)
97# endif
74# ifdef CLONE_FILES 98# ifdef CLONE_FILES
75 const_iv (CLONE_FILES) 99 const_iv_clone (FILES)
76# endif 100# endif
77# ifdef CLONE_FS 101# ifdef CLONE_FS
78 const_iv (CLONE_FS) 102 const_iv_clone (FS)
79# endif 103# endif
80# ifdef CLONE_NEWNS 104# ifdef CLONE_NEWNS
81 const_iv (CLONE_NEWNS) 105 const_iv_clone (NEWNS)
82# endif 106# endif
83# ifdef CLONE_VM 107# ifdef CLONE_VM
84 const_iv (CLONE_VM) 108 const_iv_clone (VM)
85# endif 109# endif
86# ifdef CLONE_THREAD 110# ifdef CLONE_THREAD
87 const_iv (CLONE_THREAD) 111 const_iv_clone (THREAD)
88# endif 112# endif
89# ifdef CLONE_SIGHAND 113# ifdef CLONE_SIGHAND
90 const_iv (CLONE_SIGHAND) 114 const_iv_clone (SIGHAND)
91# endif 115# endif
92# ifdef CLONE_SYSVSEM 116# ifdef CLONE_SYSVSEM
93 const_iv (CLONE_SYSVSEM) 117 const_iv_clone (SYSVSEM)
94# endif 118# endif
95# ifdef CLONE_NEWUTS 119# ifdef CLONE_NEWUTS
96 const_iv (CLONE_NEWUTS) 120 const_iv_clone (NEWUTS)
97# endif 121# endif
98# ifdef CLONE_NEWIPC 122# ifdef CLONE_NEWIPC
99 const_iv (CLONE_NEWIPC) 123 const_iv_clone (NEWIPC)
100# endif 124# endif
101# ifdef CLONE_NEWNET 125# ifdef CLONE_NEWNET
102 const_iv (CLONE_NEWNET) 126 const_iv_clone (NEWNET)
127# endif
128# ifdef CLONE_NEWTIME
129 const_iv_clone (NEWTIME)
103# endif 130# endif
104# ifdef CLONE_PTRACE 131# ifdef CLONE_PTRACE
105 const_iv (CLONE_PTRACE) 132 const_iv_clone (PTRACE)
106# endif 133# endif
107# ifdef CLONE_VFORK 134# ifdef CLONE_VFORK
108 const_iv (CLONE_VFORK) 135 const_iv_clone (VFORK)
109# endif 136# endif
110# ifdef CLONE_SETTLS 137# ifdef CLONE_SETTLS
111 const_iv (CLONE_SETTLS) 138 const_iv_clone (SETTLS)
112# endif 139# endif
113# ifdef CLONE_PARENT_SETTID 140# ifdef CLONE_PARENT_SETTID
114 const_iv (CLONE_PARENT_SETTID) 141 const_iv_clone (PARENT_SETTID)
115# endif 142# endif
116# ifdef CLONE_CHILD_CLEARTID 143# ifdef CLONE_CHILD_CLEARTID
117 const_iv (CLONE_CHILD_CLEARTID) 144 const_iv_clone (CHILD_CLEARTID)
118# endif 145# endif
119# ifdef CLONE_DETACHED 146# ifdef CLONE_DETACHED
120 const_iv (CLONE_DETACHED) 147 const_iv_clone (DETACHED)
121# endif 148# endif
122# ifdef CLONE_UNTRACED 149# ifdef CLONE_UNTRACED
123 const_iv (CLONE_UNTRACED) 150 const_iv_clone (UNTRACED)
124# endif 151# endif
125# ifdef CLONE_CHILD_SETTID 152# ifdef CLONE_CHILD_SETTID
126 const_iv (CLONE_CHILD_SETTID) 153 const_iv_clone (CHILD_SETTID)
127# endif 154# endif
128# ifdef CLONE_NEWUSER 155# ifdef CLONE_NEWUSER
129 const_iv (CLONE_NEWUSER) 156 const_iv_clone (NEWUSER)
130# endif 157# endif
131# ifdef CLONE_NEWPID 158# ifdef CLONE_NEWPID
132 const_iv (CLONE_NEWPID) 159 const_iv_clone (NEWPID)
133# endif 160# endif
134# ifdef CLONE_IO 161# ifdef CLONE_IO
135 const_iv (CLONE_IO) 162 const_iv_clone (IO)
136# endif 163# endif
137# ifdef CLONE_NEWCGROUP 164# ifdef CLONE_NEWCGROUP
138 const_iv (CLONE_NEWCGROUP) 165 const_iv_clone (NEWCGROUP)
166# endif
167# ifdef CLONE_PIDFD
168 const_iv_clone (PIDFD)
139# endif 169# endif
140# ifdef SYS_kcmp 170# ifdef SYS_kcmp
141 const_iv (KCMP_FILE) 171 const_iv (KCMP_FILE)
142 const_iv (KCMP_VM) 172 const_iv (KCMP_VM)
143 const_iv (KCMP_FILES) 173 const_iv (KCMP_FILES)
144 const_iv (KCMP_FS) 174 const_iv (KCMP_FS)
145 const_iv (KCMP_SIGHAND) 175 const_iv (KCMP_SIGHAND)
146 const_iv (KCMP_IO) 176 const_iv (KCMP_IO)
147 const_iv (KCMP_SYSVSEM) 177 const_iv (KCMP_SYSVSEM)
148 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
149# endif 191# endif
150 }; 192 };
151 193
152 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--)
153 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 195 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
181 munmap (stack_ptr, stacksize); 223 munmap (stack_ptr, stacksize);
182 errno = old_errno; 224 errno = old_errno;
183 } 225 }
184 } 226 }
185} 227}
186 OUTPUT: 228 OUTPUT: RETVAL
187 RETVAL
188 229
189int 230int
190unshare (int flags) 231unshare (int flags)
232 PROTOTYPE: @
191 233
192int 234int
193setns (SV *fh_or_fd, int nstype = 0) 235setns (SV *fh_or_fd, int nstype = 0)
194 C_ARGS: s_fileno (fh_or_fd, 0), nstype 236 C_ARGS: s_fileno (fh_or_fd, 0), nstype
195 237
197pivot_root (SV *new_root, SV *old_root) 239pivot_root (SV *new_root, SV *old_root)
198 CODE: 240 CODE:
199 RETVAL = syscall (SYS_pivot_root, 241 RETVAL = syscall (SYS_pivot_root,
200 (const char *)SvPVbyte_nolen (new_root), 242 (const char *)SvPVbyte_nolen (new_root),
201 (const char *)SvPVbyte_nolen (old_root)); 243 (const char *)SvPVbyte_nolen (old_root));
202 OUTPUT: 244 OUTPUT: RETVAL
203 RETVAL
204 245
205int 246int
206kcmp (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)
207 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