11 #include "../ld-acess_src/exports.h"
16 fprintf(stderr, "TODO: Windows libacessnative setup\n");
23 int __attribute__ ((constructor(102))) libacessnative_init(int argc, char *argv[], char **envp);
25 const char *getenv_p(char **envp, const char *name)
27 size_t namelen = strlen(name);
30 if( strncmp(*envp, name, namelen) != 0 )
32 if( (*envp)[namelen] != '=' )
34 return (*envp)+namelen+1;
39 int libacessnative_init(int argc, char *argv[], char **envp)
43 const char *preopens = getenv_p(envp, ENV_VAR_PREOPENS);
44 printf("preopens = %s\n", preopens);
49 const char *splitter = strchr(preopens, ':');
52 len = strlen(preopens);
55 len = splitter - preopens;
58 memcpy(path, preopens, len);
60 int fd = acess__SysOpen(path, 6); // WRITE,READ,no EXEC
62 fprintf(stderr, "Unable to preopen '%s' errno=%i\n", path, acess__errno);
67 preopens = splitter + 1;
71 // if( !getenv(ENV_VAR_KEY)
77 int acessnative_spawn(const char *Binary, int SyscallID, const char * const * argv, const char * const * envp)
80 while( envp && envp[envc++] )
83 // Set environment variables for libacess-native
84 // > ACESSNATIVE_KEY=`newID`
85 size_t keystr_len = snprintf(NULL, 0, "%s=%i", ENV_VAR_KEY, SyscallID);
86 char keystr[keystr_len+1];
87 snprintf(keystr, keystr_len+1, "%s=%i", ENV_VAR_KEY, SyscallID);
90 const char *newenv[envc+2+1];
92 for( ; envp && envp[i]; i ++ )
94 const char *ev = envp[i];
95 if( strncmp(ev, ENV_VAR_KEY"=", sizeof(ENV_VAR_KEY"=")) == 0 ) {
102 newenv[i++] = keystr;
103 newenv[i++] = getenv("LD_LIBRARY_PATH") - (sizeof("LD_LIBRARY_PATH=")-1); // VERY hacky
106 // TODO: Detect native_spawn failing
107 return native_spawn(Binary, argv, newenv);
110 void Debug(const char *format, ...)
114 va_start(args, format);
115 vfprintf(stdout, format, args);
120 void Warning(const char *format, ...)
124 va_start(args, format);
125 vfprintf(stdout, format, args);
130 void __libc_csu_fini()
134 void __libc_csu_init()
138 void __stack_chk_fail(void)
140 fprintf(stderr, "__stack_chk_fail");