Skip to content

Commit b318a94

Browse files
leongrossdeadprogram
authored andcommitted
add Fork and Exec libc hooks
Signed-off-by: leongross <leon.gross@9elements.com>
1 parent 725518f commit b318a94

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/syscall/syscall_libc.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,37 @@ func Chown(path string, uid, gid int) (err error) {
172172
return
173173
}
174174

175+
func Fork() (err error) {
176+
fail := int(libc_fork())
177+
if fail < 0 {
178+
err = getErrno()
179+
}
180+
return
181+
}
182+
183+
func Execve(pathname string, argv []string, envv []string) (err error) {
184+
argv0 := cstring(pathname)
185+
186+
// transform argv and envv into the format expected by execve
187+
argv1 := make([]*byte, len(argv)+1)
188+
for i, arg := range argv {
189+
argv1[i] = &cstring(arg)[0]
190+
}
191+
argv1[len(argv)] = nil
192+
193+
env1 := make([]*byte, len(envv)+1)
194+
for i, env := range envv {
195+
env1[i] = &cstring(env)[0]
196+
}
197+
env1[len(envv)] = nil
198+
199+
fail := int(libc_execve(&argv0[0], &argv1[0], &env1[0]))
200+
if fail < 0 {
201+
err = getErrno()
202+
}
203+
return
204+
}
205+
175206
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
176207

177208
func Kill(pid int, sig Signal) (err error) {
@@ -410,3 +441,13 @@ func libc_readlink(path *byte, buf *byte, count uint) int
410441
//
411442
//export unlink
412443
func libc_unlink(pathname *byte) int32
444+
445+
// pid_t fork(void);
446+
//
447+
//export fork
448+
func libc_fork() int32
449+
450+
// int execve(const char *filename, char *const argv[], char *const envp[]);
451+
//
452+
//export execve
453+
func libc_execve(filename *byte, argv **byte, envp **byte) int

0 commit comments

Comments
 (0)