… | |
… | |
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 __has_include |
|
|
15 | #if !__has_include("linux/kcmp.h") // use "" as GCC wrongly expands macros |
|
|
16 | #undef SYS_kcmp |
|
|
17 | #endif |
|
|
18 | #endif |
|
|
19 | |
|
|
20 | #ifdef SYS_kcmp |
|
|
21 | #include "linux/kcmp.h" |
|
|
22 | #define kcmp(pid1,pid2,type,idx1,idx2) \ |
|
|
23 | syscall (SYS_kcmp, (pid_t)pid1, (pid_t)pid2, \ |
|
|
24 | (int)type, (unsigned long)idx1, (unsigned long)idx2) |
|
|
25 | #else |
|
|
26 | #define kcmp(pid1,pid2,type,idx1,idx2) \ |
|
|
27 | (errno = ENOSYS, -1) |
|
|
28 | #endif |
11 | |
29 | |
12 | /* from schmorp.h */ |
30 | /* from schmorp.h */ |
13 | static int |
31 | static int |
14 | s_fileno (SV *fh, int wr) |
32 | s_fileno (SV *fh, int wr) |
15 | { |
33 | { |
… | |
… | |
56 | |
74 | |
57 | static const struct { |
75 | static const struct { |
58 | const char *name; |
76 | const char *name; |
59 | IV iv; |
77 | IV iv; |
60 | } *civ, const_iv[] = { |
78 | } *civ, const_iv[] = { |
|
|
79 | # define const_iv(name) { # name, (IV)name }, |
61 | # define const_iv(name) { # name, (IV) CLONE_ ## name }, |
80 | # define const_iv_clone(name) { # name, (IV) CLONE_ ## name }, |
62 | # ifdef CLONE_FILES |
81 | # ifdef CLONE_FILES |
63 | const_iv (FILES) |
82 | const_iv_clone (FILES) |
64 | # endif |
83 | # endif |
65 | # ifdef CLONE_FS |
84 | # ifdef CLONE_FS |
66 | const_iv (FS) |
85 | const_iv_clone (FS) |
67 | # endif |
86 | # endif |
68 | # ifdef CLONE_NEWNS |
87 | # ifdef CLONE_NEWNS |
69 | const_iv (NEWNS) |
88 | const_iv_clone (NEWNS) |
70 | # endif |
89 | # endif |
71 | # ifdef CLONE_VM |
90 | # ifdef CLONE_VM |
72 | const_iv (VM) |
91 | const_iv_clone (VM) |
73 | # endif |
92 | # endif |
74 | # ifdef CLONE_THREAD |
93 | # ifdef CLONE_THREAD |
75 | const_iv (THREAD) |
94 | const_iv_clone (THREAD) |
76 | # endif |
95 | # endif |
77 | # ifdef CLONE_SIGHAND |
96 | # ifdef CLONE_SIGHAND |
78 | const_iv (SIGHAND) |
97 | const_iv_clone (SIGHAND) |
79 | # endif |
98 | # endif |
80 | # ifdef CLONE_SYSVSEM |
99 | # ifdef CLONE_SYSVSEM |
81 | const_iv (SYSVSEM) |
100 | const_iv_clone (SYSVSEM) |
82 | # endif |
101 | # endif |
83 | # ifdef CLONE_NEWUTS |
102 | # ifdef CLONE_NEWUTS |
84 | const_iv (NEWUTS) |
103 | const_iv_clone (NEWUTS) |
85 | # endif |
104 | # endif |
86 | # ifdef CLONE_NEWIPC |
105 | # ifdef CLONE_NEWIPC |
87 | const_iv (NEWIPC) |
106 | const_iv_clone (NEWIPC) |
88 | # endif |
107 | # endif |
89 | # ifdef CLONE_NEWNET |
108 | # ifdef CLONE_NEWNET |
90 | const_iv (NEWNET) |
109 | const_iv_clone (NEWNET) |
91 | # endif |
110 | # endif |
92 | # ifdef CLONE_PTRACE |
111 | # ifdef CLONE_PTRACE |
93 | const_iv (PTRACE) |
112 | const_iv_clone (PTRACE) |
94 | # endif |
113 | # endif |
95 | # ifdef CLONE_VFORK |
114 | # ifdef CLONE_VFORK |
96 | const_iv (VFORK) |
115 | const_iv_clone (VFORK) |
97 | # endif |
116 | # endif |
98 | # ifdef CLONE_SETTLS |
117 | # ifdef CLONE_SETTLS |
99 | const_iv (SETTLS) |
118 | const_iv_clone (SETTLS) |
100 | # endif |
119 | # endif |
101 | # ifdef CLONE_PARENT_SETTID |
120 | # ifdef CLONE_PARENT_SETTID |
102 | const_iv (PARENT_SETTID) |
121 | const_iv_clone (PARENT_SETTID) |
103 | # endif |
122 | # endif |
104 | # ifdef CLONE_CHILD_CLEARTID |
123 | # ifdef CLONE_CHILD_CLEARTID |
105 | const_iv (CHILD_CLEARTID) |
124 | const_iv_clone (CHILD_CLEARTID) |
106 | # endif |
125 | # endif |
107 | # ifdef CLONE_DETACHED |
126 | # ifdef CLONE_DETACHED |
108 | const_iv (DETACHED) |
127 | const_iv_clone (DETACHED) |
109 | # endif |
128 | # endif |
110 | # ifdef CLONE_UNTRACED |
129 | # ifdef CLONE_UNTRACED |
111 | const_iv (UNTRACED) |
130 | const_iv_clone (UNTRACED) |
112 | # endif |
131 | # endif |
113 | # ifdef CLONE_CHILD_SETTID |
132 | # ifdef CLONE_CHILD_SETTID |
114 | const_iv (CHILD_SETTID) |
133 | const_iv_clone (CHILD_SETTID) |
115 | # endif |
134 | # endif |
116 | # ifdef CLONE_NEWUSER |
135 | # ifdef CLONE_NEWUSER |
117 | const_iv (NEWUSER) |
136 | const_iv_clone (NEWUSER) |
118 | # endif |
137 | # endif |
119 | # ifdef CLONE_NEWPID |
138 | # ifdef CLONE_NEWPID |
120 | const_iv (NEWPID) |
139 | const_iv_clone (NEWPID) |
121 | # endif |
140 | # endif |
122 | # ifdef CLONE_IO |
141 | # ifdef CLONE_IO |
123 | const_iv (IO) |
142 | const_iv_clone (IO) |
124 | # endif |
143 | # endif |
125 | # ifdef CLONE_NEWCGROUP |
144 | # ifdef CLONE_NEWCGROUP |
126 | const_iv (NEWCGROUP) |
145 | const_iv_clone (NEWCGROUP) |
|
|
146 | # endif |
|
|
147 | # ifdef CLONE_PIDFD |
|
|
148 | const_iv_clone (PIDFD) |
|
|
149 | # endif |
|
|
150 | # ifdef SYS_kcmp |
|
|
151 | const_iv (KCMP_FILE) |
|
|
152 | const_iv (KCMP_VM) |
|
|
153 | const_iv (KCMP_FILES) |
|
|
154 | const_iv (KCMP_FS) |
|
|
155 | const_iv (KCMP_SIGHAND) |
|
|
156 | const_iv (KCMP_IO) |
|
|
157 | const_iv (KCMP_SYSVSEM) |
|
|
158 | const_iv (KCMP_FILE) |
127 | # endif |
159 | # endif |
128 | }; |
160 | }; |
129 | |
161 | |
130 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
162 | for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
131 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
163 | newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
… | |
… | |
168 | unshare (int flags) |
200 | unshare (int flags) |
169 | |
201 | |
170 | int |
202 | int |
171 | setns (SV *fh_or_fd, int nstype = 0) |
203 | setns (SV *fh_or_fd, int nstype = 0) |
172 | C_ARGS: s_fileno (fh_or_fd, 0), nstype |
204 | C_ARGS: s_fileno (fh_or_fd, 0), nstype |
|
|
205 | |
|
|
206 | int |
|
|
207 | pivot_root (SV *new_root, SV *old_root) |
|
|
208 | CODE: |
|
|
209 | RETVAL = syscall (SYS_pivot_root, |
|
|
210 | (const char *)SvPVbyte_nolen (new_root), |
|
|
211 | (const char *)SvPVbyte_nolen (old_root)); |
|
|
212 | OUTPUT: |
|
|
213 | RETVAL |
|
|
214 | |
|
|
215 | int |
|
|
216 | kcmp (IV pid1, IV pid2, IV type, UV idx1 = 0, UV idx2 = 0) |
|
|
217 | |