Implemented running executables in memory
All checks were successful
/ test (push) Successful in 16s

This commit is contained in:
Eduard Urbach 2025-07-06 20:02:28 +02:00
parent e5aa006623
commit a7fd4172b9
Signed by: akyoto
GPG key ID: 49226B848C78F6C8
10 changed files with 183 additions and 42 deletions

47
src/memfile/Exec_linux.go Normal file
View file

@ -0,0 +1,47 @@
//go:build linux
package memfile
import (
"os"
"strconv"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
// Exec executes an in-memory file.
func Exec(file *os.File) error {
empty, err := syscall.BytePtrFromString("")
if err != nil {
return err
}
argv := []string{"/proc/self/fd/" + strconv.Itoa(int(file.Fd()))}
argvp, err := syscall.SlicePtrFromStrings(argv)
if err != nil {
return err
}
envv := os.Environ()
envvp, err := syscall.SlicePtrFromStrings(envv)
if err != nil {
return err
}
_, _, errno := syscall.Syscall6(
unix.SYS_EXECVEAT,
uintptr(file.Fd()),
uintptr(unsafe.Pointer(empty)),
uintptr(unsafe.Pointer(&argvp[0])),
uintptr(unsafe.Pointer(&envvp[0])),
uintptr(unix.AT_EMPTY_PATH),
0,
)
return errno
}