1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
|
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package syscall
#include "runtime.h"
#include "defs_GOOS_GOARCH.h"
#include "os_GOOS.h"
#include "cgocall.h"
#include "../../cmd/ld/textflag.h"
#pragma dynimport libc·chdir chdir "libc.so"
#pragma dynimport libc·chroot chroot "libc.so"
#pragma dynimport libc·close close "libc.so"
#pragma dynimport libc·dlclose dlclose "libc.so"
#pragma dynimport libc·dlopen dlopen "libc.so"
#pragma dynimport libc·dlsym dlsym "libc.so"
#pragma dynimport libc·execve execve "libc.so"
#pragma dynimport libc·fcntl fcntl "libc.so"
#pragma dynimport libc·gethostname gethostname "libc.so"
#pragma dynimport libc·ioctl ioctl "libc.so"
#pragma dynimport libc·pipe pipe "libc.so"
#pragma dynimport libc·setgid setgid "libc.so"
#pragma dynimport libc·setgroups setgroups "libc.so"
#pragma dynimport libc·setsid setsid "libc.so"
#pragma dynimport libc·setuid setuid "libc.so"
#pragma dynimport libc·setpgid setsid "libc.so"
#pragma dynimport libc·syscall syscall "libc.so"
#pragma dynimport libc·forkx forkx "libc.so"
#pragma dynimport libc·wait4 wait4 "libc.so"
extern uintptr libc·chdir;
extern uintptr libc·chroot;
extern uintptr libc·close;
extern uintptr libc·dlclose;
extern uintptr libc·dlopen;
extern uintptr libc·dlsym;
extern uintptr libc·execve;
extern uintptr libc·exit;
extern uintptr libc·fcntl;
extern uintptr libc·gethostname;
extern uintptr libc·ioctl;
extern uintptr libc·pipe;
extern uintptr libc·setgid;
extern uintptr libc·setgroups;
extern uintptr libc·setsid;
extern uintptr libc·setuid;
extern uintptr libc·setpgid;
extern uintptr libc·syscall;
extern uintptr libc·forkx;
extern uintptr libc·wait4;
extern uintptr libc·write;
func sysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
{
LibCall c;
USED(a2);
USED(a3);
USED(a4);
USED(a5);
USED(a6);
c.fn = (void*)func;
c.n = nargs;
c.args = (void*)&a1;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.err;
r1 = c.r1;
r2 = c.r2;
}
#pragma textflag NOSPLIT
func rawSysvicall6(func uintptr, nargs uintptr, a1 uintptr, a2 uintptr, a3 uintptr, a4 uintptr, a5 uintptr, a6 uintptr) (r1 uintptr, r2 uintptr, err uintptr)
{
LibCall c;
USED(a2);
USED(a3);
USED(a4);
USED(a5);
USED(a6);
c.fn = (void*)func;
c.n = nargs;
c.args = (void*)&a1;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
r1 = c.r1;
r2 = c.r2;
}
#pragma textflag NOSPLIT
func chdir(path uintptr) (err uintptr) {
LibCall c;
c.fn = (void*)libc·chdir;
c.n = 1;
c.args = (void*)&path;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func chroot1(path uintptr) (err uintptr) {
LibCall c;
c.fn = (void*)libc·chroot;
c.n = 1;
c.args = (void*)&path;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func close(fd uintptr) (err uintptr) {
LibCall c;
c.fn = (void*)libc·close;
c.n = 1;
c.args = (void*)&fd;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
func dlclose(handle uintptr) (err uintptr) {
LibCall c;
USED(handle);
c.fn = (void*)libc·dlclose;
c.n = 1;
c.args = (void*)&handle;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.r1;
}
func dlopen(name *uint8, mode uintptr) (handle uintptr, err uintptr) {
LibCall c;
USED(mode);
c.fn = (void*)libc·dlopen;
c.n = 2;
c.args = (void*)&name;
runtime·cgocall(runtime·asmsysvicall6, &c);
handle = c.r1;
if(handle == 0)
err = c.err;
else
err = 0;
}
func dlsym(handle uintptr, name *uint8) (proc uintptr, err uintptr) {
LibCall c;
USED(name);
c.fn = (void*)libc·dlsym;
c.n = 2;
c.args = &handle;
runtime·cgocall(runtime·asmsysvicall6, &c);
proc = c.r1;
if(proc == 0)
err = c.err;
else
err = 0;
}
#pragma textflag NOSPLIT
func execve(path uintptr, argv uintptr, envp uintptr) (err uintptr) {
LibCall c;
USED(argv);
USED(envp);
c.fn = (void*)libc·execve;
c.n = 3;
c.args = (void*)&path;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func exit(code uintptr) {
LibCall c;
c.fn = (void*)libc·exit;
c.n = 1;
c.args = (void*)&code;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
}
#pragma textflag NOSPLIT
func fcntl1(fd uintptr, cmd uintptr, arg uintptr) (val uintptr, err uintptr) {
LibCall c;
USED(cmd);
USED(arg);
c.fn = (void*)libc·fcntl;
c.n = 3;
c.args = (void*)&fd;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
val = c.r1;
}
func gethostname() (name String, err uintptr) {
struct { uintptr v[2]; } args;
uint8 cname[MAXHOSTNAMELEN];
LibCall c;
c.fn = (void*)libc·gethostname;
c.n = 2;
args.v[0] = (uintptr)&cname[0];
args.v[1] = MAXHOSTNAMELEN;
c.args = (void*)&args;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.err;
if(c.r1) {
name = runtime·emptystring;
return;
}
cname[MAXHOSTNAMELEN - 1] = 0;
name = runtime·gostring(cname);
}
#pragma textflag NOSPLIT
func ioctl(fd uintptr, req uintptr, arg uintptr) (err uintptr) {
LibCall c;
USED(req);
USED(arg);
c.fn = (void*)libc·ioctl;
c.n = 3;
c.args = (void*)&fd;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
func wait4(pid uintptr, wstatus *uint32, options uintptr, rusage *void) (wpid int, err uintptr) {
LibCall c;
USED(wstatus);
USED(options);
USED(rusage);
c.fn = (void*)libc·wait4;
c.n = 4;
c.args = (void*)&pid;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.err;
wpid = c.r1;
}
#pragma textflag NOSPLIT
func setgid(gid uintptr) (err uintptr) {
LibCall c;
c.fn = (void*)libc·setgid;
c.n = 1;
c.args = (void*)&gid;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func setgroups1(ngid uintptr, gid uintptr) (err uintptr) {
LibCall c;
USED(gid);
c.fn = (void*)libc·setgroups;
c.n = 2;
c.args = (void*)&ngid;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func setsid() (pid uintptr, err uintptr) {
LibCall c;
c.fn = (void*)libc·setsid;
c.n = 0;
c.args = (void*)0;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
pid = c.r1;
}
#pragma textflag NOSPLIT
func setuid(uid uintptr) (err uintptr) {
LibCall c;
c.fn = (void*)libc·setuid;
c.n = 1;
c.args = (void*)&uid;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func setpgid(pid uintptr, pgid uintptr) (err uintptr) {
LibCall c;
USED(pgid);
c.fn = (void*)libc·setpgid;
c.n = 2;
c.args = (void*)&pid;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
}
#pragma textflag NOSPLIT
func forkx(flags uintptr) (pid uintptr, err uintptr) {
LibCall c;
c.fn = (void*)libc·forkx;
c.n = 1;
c.args = (void*)&flags;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
pid = c.r1;
}
void runtime·pipe1(void);
func pipe() (r uintptr, w uintptr, err uintptr) {
LibCall c;
c.fn = (void*)runtime·pipe1;
c.n = 0;
c.args = (void*)0;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.err;
r = c.r1;
w = c.r2;
}
#pragma textflag NOSPLIT
func write1(fd uintptr, buf uintptr, nbyte uintptr) (n uintptr, err uintptr) {
LibCall c;
USED(buf);
USED(nbyte);
c.fn = (void*)libc·write;
c.n = 3;
c.args = (void*)fd;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
n = c.r1;
}
func Syscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr) (r1 uintptr, r2 uintptr, err uintptr) {
LibCall c;
USED(a1);
USED(a2);
USED(a3);
c.fn = (void*)libc·syscall;
c.n = 4;
c.args = &trap;
runtime·cgocall(runtime·asmsysvicall6, &c);
err = c.err;
r1 = c.r1;
r2 = c.r2;
}
func RawSyscall(trap uintptr, a1 uintptr, a2 uintptr, a3 uintptr) (r1 uintptr, r2 uintptr, err uintptr) {
LibCall c;
USED(a1);
USED(a2);
USED(a3);
c.fn = (void*)libc·syscall;
c.n = 4;
c.args = &trap;
runtime·asmcgocall(runtime·asmsysvicall6, &c);
err = c.err;
r1 = c.r1;
r2 = c.r2;
}
|