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.1 by root, Mon Nov 28 05:43:03 2011 UTC vs.
Revision 1.3 by root, Thu Nov 2 07:31:16 2017 UTC

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#ifdef SYS_kcmp
15 #include <linux/kcmp.h>
16 #define kcmp(pid1,pid2,type,idx1,idx2) \
17 syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \
18 (int)type, (unsigned long)idx1, (unsigned long)idx2)
19#else
20 #define kcmp(pid1,pid2,type,idx1,idx2) \
21 (errno = ENOSYS, -1)
22#endif
23
24/* from schmorp.h */
25static int
26s_fileno (SV *fh, int wr)
27{
28 dTHX;
29 SvGETMAGIC (fh);
30
31 if (SvROK (fh))
32 {
33 fh = SvRV (fh);
34 SvGETMAGIC (fh);
35 }
36
37 if (SvTYPE (fh) == SVt_PVGV)
38 return PerlIO_fileno (wr ? IoOFP (sv_2io (fh)) : IoIFP (sv_2io (fh)));
39
40 if (SvOK (fh) && (SvIV (fh) >= 0) && (SvIV (fh) < 0x7fffffffL))
41 return SvIV (fh);
42
43 return -1;
44}
11 45
12static int 46static int
13clone_cb (void *arg) 47clone_cb (void *arg)
14{ 48{
15 dSP; 49 dSP;
34 68
35 static const struct { 69 static const struct {
36 const char *name; 70 const char *name;
37 IV iv; 71 IV iv;
38 } *civ, const_iv[] = { 72 } *civ, const_iv[] = {
39# define const_iv(name) { # name, (IV) CLONE_ ## name }, 73# define const_iv(name) { # name, (IV)name },
40# ifdef CLONE_FILES 74# ifdef CLONE_FILES
41 const_iv (FILES) 75 const_iv (CLONE_FILES)
42# endif 76# endif
43# ifdef CLONE_FS 77# ifdef CLONE_FS
44 const_iv (FS) 78 const_iv (CLONE_FS)
45# endif 79# endif
46# ifdef CLONE_NEWNS 80# ifdef CLONE_NEWNS
47 const_iv (NEWNS) 81 const_iv (CLONE_NEWNS)
48# endif 82# endif
49# ifdef CLONE_VM 83# ifdef CLONE_VM
50 const_iv (VM) 84 const_iv (CLONE_VM)
51# endif 85# endif
52# ifdef CLONE_THREAD 86# ifdef CLONE_THREAD
53 const_iv (THREAD) 87 const_iv (CLONE_THREAD)
54# endif 88# endif
55# ifdef CLONE_SIGHAND 89# ifdef CLONE_SIGHAND
56 const_iv (SIGHAND) 90 const_iv (CLONE_SIGHAND)
57# endif 91# endif
58# ifdef CLONE_SYSVSEM 92# ifdef CLONE_SYSVSEM
59 const_iv (SYSVSEM) 93 const_iv (CLONE_SYSVSEM)
60# endif 94# endif
61# ifdef CLONE_NEWUTS 95# ifdef CLONE_NEWUTS
62 const_iv (NEWUTS) 96 const_iv (CLONE_NEWUTS)
63# endif 97# endif
64# ifdef CLONE_NEWIPC 98# ifdef CLONE_NEWIPC
65 const_iv (NEWIPC) 99 const_iv (CLONE_NEWIPC)
66# endif 100# endif
67# ifdef CLONE_NEWNET 101# ifdef CLONE_NEWNET
68 const_iv (NEWNET) 102 const_iv (CLONE_NEWNET)
69# endif 103# endif
70# ifdef CLONE_PTRACE 104# ifdef CLONE_PTRACE
71 const_iv (PTRACE) 105 const_iv (CLONE_PTRACE)
72# endif 106# endif
73# ifdef CLONE_VFORK 107# ifdef CLONE_VFORK
74 const_iv (VFORK) 108 const_iv (CLONE_VFORK)
75# endif 109# endif
76# ifdef CLONE_SETTLS 110# ifdef CLONE_SETTLS
77 const_iv (SETTLS) 111 const_iv (CLONE_SETTLS)
78# endif 112# endif
79# ifdef CLONE_PARENT_SETTID 113# ifdef CLONE_PARENT_SETTID
80 const_iv (PARENT_SETTID) 114 const_iv (CLONE_PARENT_SETTID)
81# endif 115# endif
82# ifdef CLONE_CHILD_CLEARTID 116# ifdef CLONE_CHILD_CLEARTID
83 const_iv (CHILD_CLEARTID) 117 const_iv (CLONE_CHILD_CLEARTID)
84# endif 118# endif
85# ifdef CLONE_DETACHED 119# ifdef CLONE_DETACHED
86 const_iv (DETACHED) 120 const_iv (CLONE_DETACHED)
87# endif 121# endif
88# ifdef CLONE_UNTRACED 122# ifdef CLONE_UNTRACED
89 const_iv (UNTRACED) 123 const_iv (CLONE_UNTRACED)
90# endif 124# endif
91# ifdef CLONE_CHILD_SETTID 125# ifdef CLONE_CHILD_SETTID
92 const_iv (CHILD_SETTID) 126 const_iv (CLONE_CHILD_SETTID)
93# endif 127# endif
94# ifdef CLONE_NEWUSER 128# ifdef CLONE_NEWUSER
95 const_iv (NEWUSER) 129 const_iv (CLONE_NEWUSER)
96# endif 130# endif
97# ifdef CLONE_NEWPID 131# ifdef CLONE_NEWPID
98 const_iv (NEWPID) 132 const_iv (CLONE_NEWPID)
99# endif 133# endif
100# ifdef CLONE_IO 134# ifdef CLONE_IO
135 const_iv (CLONE_IO)
136# endif
137# ifdef CLONE_NEWCGROUP
138 const_iv (CLONE_NEWCGROUP)
139# endif
140# ifdef SYS_kcmp
141 const_iv (KCMP_FILE)
142 const_iv (KCMP_VM)
143 const_iv (KCMP_FILES)
144 const_iv (KCMP_FS)
145 const_iv (KCMP_SIGHAND)
101 const_iv (IO) 146 const_iv (KCMP_IO)
147 const_iv (KCMP_SYSVSEM)
148 const_iv (KCMP_FILE)
102# endif 149# endif
103 }; 150 };
104 151
105 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) 152 for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--)
106 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); 153 newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv));
107
108int
109unshare (int flags)
110 CODE:
111 RETVAL = unshare (flags);
112 OUTPUT:
113 RETVAL
114 154
115int 155int
116clone (SV *sub, IV stacksize, int flags, SV *ptid = 0, SV *tls = &PL_sv_undef) 156clone (SV *sub, IV stacksize, int flags, SV *ptid = 0, SV *tls = &PL_sv_undef)
117 CODE: 157 CODE:
118{ 158{
119 if (!stacksize) 159 if (!stacksize)
120 stacksize = 4 << 20; 160 stacksize = 4 << 20;
121 161
122 pid_t ptid_; 162 pid_t ptid_;
123 char *stack_ptr = mmap (0, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK, -1, 0); 163 char *stack_ptr = mmap (0, stacksize, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_GROWSDOWN | MAP_STACK, -1, 0);
124 164
144 } 184 }
145} 185}
146 OUTPUT: 186 OUTPUT:
147 RETVAL 187 RETVAL
148 188
189int
190unshare (int flags)
191
192int
193setns (SV *fh_or_fd, int nstype = 0)
194 C_ARGS: s_fileno (fh_or_fd, 0), nstype
195
196int
197pivot_root (SV *new_root, SV *old_root)
198 CODE:
199 RETVAL = syscall (SYS_pivot_root,
200 (const char *)SvPVbyte_nolen (new_root),
201 (const char *)SvPVbyte_nolen (old_root));
202 OUTPUT:
203 RETVAL
204
205int
206kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0)
207

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines