From: John Hodge Date: Thu, 11 Oct 2012 10:01:48 +0000 (+0800) Subject: AcessNative - Implimented user side of SysSpawn X-Git-Tag: rel0.15~684 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9a0444cde872613a1fad42857506ae17dde4b2b8;p=tpg%2Facess2.git AcessNative - Implimented user side of SysSpawn --- diff --git a/AcessNative/acesskernel_src/syscalls.c b/AcessNative/acesskernel_src/syscalls.c index 69192399..886eb1bf 100644 --- a/AcessNative/acesskernel_src/syscalls.c +++ b/AcessNative/acesskernel_src/syscalls.c @@ -247,6 +247,7 @@ const tSyscallHandler caSyscalls[] = { Syscall_Sleep, Syscall_AN_Fork, + NULL, Syscall_SendMessage, Syscall_GetMessage, diff --git a/AcessNative/ld-acess_src/exports.c b/AcessNative/ld-acess_src/exports.c index 90eef865..b75b8fdf 100644 --- a/AcessNative/ld-acess_src/exports.c +++ b/AcessNative/ld-acess_src/exports.c @@ -37,6 +37,7 @@ extern int AllocateMemory(uintptr_t VirtAddr, size_t ByteCount); // === GLOBALS === int acess__errno; +char *gsExecutablePath = "./ld-acess"; // === CODE === // --- VFS Calls @@ -253,6 +254,37 @@ int acess_execve(char *path, char **argv, const char **envp) return native_execve("./ld-acess", new_argv, envp); } +int acess__SysSpawn(const char *binary, const char **argv, const char **envp, int nfd, int fds[], struct s_sys_spawninfo *info) +{ + int kernel_tid; + int newID; + newID = _Syscall(SYS_AN_SPAWN, "d>d", sizeof(int), &kernel_tid, + nfd*sizeof(int), fds, + info ? sizeof(*info) : 0, info); + + int argc = 0; + while( argv[argc++] ); + + const char *new_argv[5+argc+1]; + int new_argc = 0, i; + char client_id_str[11]; + sprintf(client_id_str, "%i", newID); + new_argv[new_argc++] = gsExecutablePath; // TODO: Get path to ld-acess executable + new_argv[new_argc++] = "--key"; + new_argv[new_argc++] = client_id_str; + new_argv[new_argc++] = "--binary"; + new_argv[new_argc++] = binary; + for( i = 0; argv[i]; i ++) + new_argv[new_argc++] = argv[i]; + new_argv[new_argc++] = NULL; + + // TODO: Debug output? + + native_spawn(gsExecutablePath, new_argv, envp); + + return kernel_tid; +} + void acess_sleep(void) { DEBUG("%s()", __func__); @@ -339,6 +371,7 @@ const tSym caBuiltinSymbols[] = { DEFSYM(clone), DEFSYM(execve), + DEFSYM(_SysSpawn), DEFSYM(sleep), DEFSYM(waittid), diff --git a/AcessNative/ld-acess_src/exports.h b/AcessNative/ld-acess_src/exports.h index 880e74ca..dc319acc 100644 --- a/AcessNative/ld-acess_src/exports.h +++ b/AcessNative/ld-acess_src/exports.h @@ -21,6 +21,7 @@ extern int native_seek(int FD, int64_t Offset, int Dir); extern uint64_t native_tell(int FD); extern int native_execve(const char *filename, const char *const argv[], const char *const envp[]); +extern int native_spawn(const char *filename, const char *const argv[], const char *const envp[]); // Syscalls used by the linker extern int acess_open(const char *Path, int Flags); diff --git a/AcessNative/ld-acess_src/syscalls.c b/AcessNative/ld-acess_src/syscalls.c index 3fdbc729..26f6c44c 100644 --- a/AcessNative/ld-acess_src/syscalls.c +++ b/AcessNative/ld-acess_src/syscalls.c @@ -9,6 +9,7 @@ #include #include #include +#include // posix_spawn #include "request.h" #if SYSCALL_TRACE @@ -335,3 +336,12 @@ int native_execve(const char *filename, const char *const argv[], const char *co perror("native_execve"); return ret; } + +int native_spawn(const char *filename, const char *const argv[], const char *const envp[]) +{ + int rv; + + rv = posix_spawn(NULL, filename, NULL, NULL, (void*)argv, (void*)envp); + + return rv; +} diff --git a/AcessNative/syscalls.h b/AcessNative/syscalls.h index d7ee2d59..21a9cb53 100644 --- a/AcessNative/syscalls.h +++ b/AcessNative/syscalls.h @@ -67,6 +67,7 @@ enum eSyscalls { // IPC SYS_SLEEP, SYS_AN_FORK, + SYS_AN_SPAWN, SYS_SENDMSG, SYS_GETMSG, SYS_SELECT,