AcessNative - Spawn in libacess-native (with AN_GETPATH syscall)
[tpg/acess2.git] / AcessNative / libacess-native.so_src / exports.c
index 70c7d77..2f960c4 100644 (file)
@@ -1,3 +1,4 @@
+#include "common.h"
 
 #define acess__SysSpawn        _disabled_acess__SysSpawn
 #include "../ld-acess_src/exports.c"
@@ -14,26 +15,38 @@ int *libc_geterrno(void)
 int acess__SysSpawn(const char *binary, const char **argv, const char **envp, int nfd, int fds[], struct s_sys_spawninfo *info)
 {
         int    argc = 0;
-       while( argv[argc++] );
+       while( argv[argc++] )
+               ;
 
        Debug("_SysSpawn('%s', %p (%i), %p, %i, %p, %p)",
                binary, argv, argc, envp, nfd, fds, info);
 
-        int    kernel_tid;
-        int    newID;
-       newID = _Syscall(SYS_AN_SPAWN, "<d >d >d", sizeof(int), &kernel_tid,
+       char realpath[256];
+       realpath[255] = 0;
+
+       if( _Syscall(SYS_AN_GETPATH, "<d >s", sizeof(realpath)-1, realpath, binary) <= 0 ) {
+               Warning("No translation for path '%s'", binary);
+               acess__errno = -11;
+               return -1;
+       }
+
+       Warning("TODO: Spawn '%s' = '%s'", binary, realpath);
+
+        int    emulated_tid;
+       int newID = _Syscall(SYS_AN_SPAWN, "<d >d >d",
+               sizeof(emulated_tid), &emulated_tid,
                nfd*sizeof(int), fds,
-               info ? sizeof(*info) : 0, info);
-       
+               (info ? sizeof(*info) : 0), info
+               );
 
-       Warning("TODO: Spawn '%s'", binary);
-       // TODO: Translate internal path to actual path 
+       if( newID <= 0 ) {
+               return -1;
+       }
 
-       // TODO: set environment variables for libacess-native
-       // > ACESSNATIVE_KEY=`newID`
-       //native_spawn(binary, argv, envp);
+       if( acessnative_spawn(realpath, newID, argv, envp) ) {
+       }
 
-       return 0;
+       return emulated_tid;
 }
 
 void ldacess_DumpLoadedLibraries(void)

UCC git Repository :: git.ucc.asn.au