oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package webread
2
3import (
4 "unsafe"
5
6 "golang.org/x/sys/unix"
7)
8
9// tryClone makes a new process with a bare clone (no CLONE_THREAD), as
10// fork does; a child that is made exits at once and is reaped.
11func tryClone() error {
12 pid, _, errno := unix.RawSyscall6(unix.SYS_CLONE, uintptr(unix.SIGCHLD), 0, 0, 0, 0, 0)
13 if errno != 0 {
14 return errno
15 }
16 if pid == 0 {
17 unix.RawSyscall(unix.SYS_EXIT_GROUP, 0, 0, 0)
18 }
19 var ws unix.WaitStatus
20 unix.Wait4(int(pid), &ws, 0, nil)
21 return nil
22}
23
24// tryClone3 is the same with clone3, whose struct clone_args starts
25// flags, pidfd, child_tid, parent_tid, exit_signal (version 0, 64 bytes).
26func tryClone3() error {
27 var args [8]uint64
28 args[4] = uint64(unix.SIGCHLD)
29 pid, _, errno := unix.RawSyscall(unix.SYS_CLONE3, uintptr(unsafe.Pointer(&args)), unsafe.Sizeof(args), 0)
30 if errno != 0 {
31 return errno
32 }
33 if pid == 0 {
34 unix.RawSyscall(unix.SYS_EXIT_GROUP, 0, 0, 0)
35 }
36 var ws unix.WaitStatus
37 unix.Wait4(int(pid), &ws, 0, nil)
38 return nil
39}
40