package webread import ( "unsafe" "golang.org/x/sys/unix" ) // tryClone makes a new process with a bare clone (no CLONE_THREAD), as // fork does; a child that is made exits at once and is reaped. func tryClone() error { pid, _, errno := unix.RawSyscall6(unix.SYS_CLONE, uintptr(unix.SIGCHLD), 0, 0, 0, 0, 0) if errno != 0 { return errno } if pid == 0 { unix.RawSyscall(unix.SYS_EXIT_GROUP, 0, 0, 0) } var ws unix.WaitStatus unix.Wait4(int(pid), &ws, 0, nil) return nil } // tryClone3 is the same with clone3, whose struct clone_args starts // flags, pidfd, child_tid, parent_tid, exit_signal (version 0, 64 bytes). func tryClone3() error { var args [8]uint64 args[4] = uint64(unix.SIGCHLD) pid, _, errno := unix.RawSyscall(unix.SYS_CLONE3, uintptr(unsafe.Pointer(&args)), unsafe.Sizeof(args), 0) if errno != 0 { return errno } if pid == 0 { unix.RawSyscall(unix.SYS_EXIT_GROUP, 0, 0, 0) } var ws unix.WaitStatus unix.Wait4(int(pid), &ws, 0, nil) return nil }