11 #include "../ld-acess_src/exports.h"
13 extern int gbSyscallDebugEnabled;
18 fprintf(stderr, "TODO: Windows libacessnative setup\n");
25 int __attribute__ ((constructor(102))) libacessnative_init(int argc, char *argv[], char **envp);
27 const char *getenv_p(char **envp, const char *name)
29 size_t namelen = strlen(name);
32 if( strncmp(*envp, name, namelen) != 0 )
34 if( (*envp)[namelen] != '=' )
36 return (*envp)+namelen+1;
41 int libacessnative_init(int argc, char *argv[], char **envp)
45 //gbSyscallDebugEnabled = 1;
47 const char *preopens = getenv_p(envp, ENV_VAR_PREOPENS);
48 printf("preopens = %s\n", preopens);
53 const char *splitter = strchr(preopens, ':');
56 len = strlen(preopens);
59 len = splitter - preopens;
62 memcpy(path, preopens, len);
64 int fd = acess__SysOpen(path, 6); // WRITE,READ,no EXEC
66 fprintf(stderr, "Unable to preopen '%s' errno=%i\n", path, acess__errno);
71 preopens = splitter + 1;
75 // if( !getenv(ENV_VAR_KEY)
81 int acessnative_spawn(const char *Binary, int SyscallID, const char * const * argv, const char * const * envp)
84 while( envp && envp[envc++] )
87 // Set environment variables for libacess-native
88 // > ACESSNATIVE_KEY=`newID`
89 size_t keystr_len = snprintf(NULL, 0, "%s=%i", ENV_VAR_KEY, SyscallID);
90 char keystr[keystr_len+1];
91 snprintf(keystr, keystr_len+1, "%s=%i", ENV_VAR_KEY, SyscallID);
94 const char *newenv[envc+2+1];
96 for( ; envp && envp[i]; i ++ )
98 const char *ev = envp[i];
99 if( strncmp(ev, ENV_VAR_KEY"=", sizeof(ENV_VAR_KEY"=")) == 0 ) {
106 newenv[i++] = keystr;
107 newenv[i++] = getenv("LD_LIBRARY_PATH") - (sizeof("LD_LIBRARY_PATH=")-1); // VERY hacky
110 // TODO: Detect native_spawn failing
111 return native_spawn(Binary, argv, newenv);
114 void Debug(const char *format, ...)
118 va_start(args, format);
119 vfprintf(stdout, format, args);
124 void Warning(const char *format, ...)
128 va_start(args, format);
129 vfprintf(stdout, format, args);
134 void __libc_csu_fini()
138 void __libc_csu_init()
142 void __stack_chk_fail(void)
144 fprintf(stderr, "__stack_chk_fail");