// syscall defines this global on our behalf to avoid a build dependency on other platforms
func init() {
- execveLibc = execve
+ execveLibc = execveLibcWrapper
+}
+
+func execveLibcWrapper(path *byte, argv **byte, envp **byte) error {
+ return execve(uintptr(unsafe.Pointer(path)),
+ uintptr(unsafe.Pointer(argv)),
+ uintptr(unsafe.Pointer(envp)))
}
// Fork, dup fd onto 0..len(fd), and exec(argv0, argvv, envv) in child.
// execveLibc is non-nil on OS using libc syscall, set to execve in exec_libc.go; this
// avoids a build dependency for other platforms.
-var execveLibc func(path uintptr, argv uintptr, envp uintptr) Errno
-var execveDarwin func(path *byte, argv **byte, envp **byte) error
-var execveOpenBSD func(path *byte, argv **byte, envp **byte) error
+var execveLibc func(path *byte, argv **byte, envp **byte) error
// Exec invokes the execve(2) system call.
func Exec(argv0 string, argv []string, envv []string) (err error) {
}
var err1 error
- if runtime.GOOS == "solaris" || runtime.GOOS == "illumos" || runtime.GOOS == "aix" {
- // RawSyscall should never be used on Solaris, illumos, or AIX.
- err1 = execveLibc(
- uintptr(unsafe.Pointer(argv0p)),
- uintptr(unsafe.Pointer(&argvp[0])),
- uintptr(unsafe.Pointer(&envvp[0])))
- } else if runtime.GOOS == "darwin" || runtime.GOOS == "ios" {
- // Similarly on Darwin.
- err1 = execveDarwin(argv0p, &argvp[0], &envvp[0])
- } else if runtime.GOOS == "openbsd" && runtime.GOARCH != "mips64" {
- // Similarly on OpenBSD.
- err1 = execveOpenBSD(argv0p, &argvp[0], &envvp[0])
- } else {
+ switch runtime.GOOS {
+ case "aix", "darwin", "illumos", "ios", "openbsd", "solaris":
+ // RawSyscall should never be used on these platforms.
+ err1 = execveLibc(argv0p, &argvp[0], &envvp[0])
+
+ default:
_, _, err1 = RawSyscall(SYS_EXECVE,
uintptr(unsafe.Pointer(argv0p)),
uintptr(unsafe.Pointer(&argvp[0])),