diff options
author | leongross <[email protected]> | 2024-07-23 11:50:35 +0200 |
---|---|---|
committer | Ron Evans <[email protected]> | 2024-07-23 16:24:41 +0200 |
commit | b318a941a4d5ffd22ff227606b9e74822901c8ef (patch) | |
tree | a63b06c7f9e21e89673dcf1f5f17fbc061e17f66 | |
parent | 725518f007663d6742f1e92ebc2d6d88418ccf61 (diff) | |
download | tinygo-b318a941a4d5ffd22ff227606b9e74822901c8ef.tar.gz tinygo-b318a941a4d5ffd22ff227606b9e74822901c8ef.zip |
add Fork and Exec libc hooks
Signed-off-by: leongross <[email protected]>
-rw-r--r-- | src/syscall/syscall_libc.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/syscall/syscall_libc.go b/src/syscall/syscall_libc.go index 07a8acb0b..0dec4c74d 100644 --- a/src/syscall/syscall_libc.go +++ b/src/syscall/syscall_libc.go @@ -172,6 +172,37 @@ func Chown(path string, uid, gid int) (err error) { return } +func Fork() (err error) { + fail := int(libc_fork()) + if fail < 0 { + err = getErrno() + } + return +} + +func Execve(pathname string, argv []string, envv []string) (err error) { + argv0 := cstring(pathname) + + // transform argv and envv into the format expected by execve + argv1 := make([]*byte, len(argv)+1) + for i, arg := range argv { + argv1[i] = &cstring(arg)[0] + } + argv1[len(argv)] = nil + + env1 := make([]*byte, len(envv)+1) + for i, env := range envv { + env1[i] = &cstring(env)[0] + } + env1[len(envv)] = nil + + fail := int(libc_execve(&argv0[0], &argv1[0], &env1[0])) + if fail < 0 { + err = getErrno() + } + return +} + func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) func Kill(pid int, sig Signal) (err error) { @@ -410,3 +441,13 @@ func libc_readlink(path *byte, buf *byte, count uint) int // //export unlink func libc_unlink(pathname *byte) int32 + +// pid_t fork(void); +// +//export fork +func libc_fork() int32 + +// int execve(const char *filename, char *const argv[], char *const envp[]); +// +//export execve +func libc_execve(filename *byte, argv **byte, envp **byte) int |