X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=ginge.git;a=blobdiff_plain;f=loader%2Foverride.c;h=c5b0a09d982de4503481b263d26e14c6ba52a818;hp=a9d545b420e38133bea2a9bd2c6877fe0f5d58a6;hb=d5a3e1bccc54036e8b659f22dc704fa257f5734d;hpb=b4f4cb40a6f3f4ecc05c7b6c8f2e852282234519 diff --git a/loader/override.c b/loader/override.c index a9d545b..c5b0a09 100644 --- a/loader/override.c +++ b/loader/override.c @@ -251,15 +251,20 @@ static UNUSED int w_execvp(const char *file, char *const argv[]) return emu_do_execve(file, argv, environ); } -// static note: this can't safely return because of the way it's patched in -// static note2: can't be used, execve hangs? -static UNUSED int w_execve(const char *filename, char *const argv[], - char *const envp[]) +long w_execve_raw(const char *filename, char * const argv[], + char * const envp[]) { strace("execve(%s, %p, %p) = ?\n", filename, argv, envp); return emu_do_execve(filename, argv, envp); } +static UNUSED int w_execve(const char *filename, char * const argv[], + char * const envp[]) +{ + long ret = w_execve_raw(filename, argv, envp); + return g_syscall_error(ret); +} + static int w_chdir(const char *path) { long ret; @@ -268,7 +273,28 @@ static int w_chdir(const char *path) ret = 0; else ret = g_chdir_raw(path); - strace("chdir(%s) = %d\n", path, ret); + + strace("chdir(%s) = %ld\n", path, ret); + return g_syscall_error(ret); +} + +static ssize_t w_readlink(const char *path, char *buf, size_t bufsiz) +{ + long ret; + +#ifndef DL + if (path != NULL && strncmp(path, "/proc/", 6) == 0 + && strcmp(strrchr(path, '/'), "/exe") == 0) + { + ret = snprintf(buf, bufsiz, "%s", bin_path); + if (ret > bufsiz) + ret = bufsiz; + } + else +#endif + ret = g_readlink_raw(path, buf, bufsiz); + + strace("readlink(%s, %s, %zd) = %ld\n", path, buf, bufsiz, ret); return g_syscall_error(ret); } @@ -290,6 +316,7 @@ static int w_chdir(const char *path) #undef execvp #undef execve #undef chdir +#undef readlink #ifdef DL @@ -318,8 +345,9 @@ MAKE_WRAP_SYM_N(execlp); MAKE_WRAP_SYM_N(execle); MAKE_WRAP_SYM_N(execv); MAKE_WRAP_SYM_N(execvp); -MAKE_WRAP_SYM(execve); +MAKE_WRAP_SYM_N(execve); MAKE_WRAP_SYM_N(chdir); +MAKE_WRAP_SYM_N(readlink); typeof(mmap) mmap2 __attribute__((alias("w_mmap"))); #define REAL_FUNC_NP(name) \ @@ -340,7 +368,7 @@ static const struct { REAL_FUNC_NP(tcsetattr), REAL_FUNC_NP(system), // exec* - skipped - REAL_FUNC_NP(execve), + //REAL_FUNC_NP(execve), //REAL_FUNC_NP(chdir), }; @@ -354,7 +382,7 @@ static const struct { #define tcgetattr p_real_tcgetattr #define tcsetattr p_real_tcsetattr #define system p_real_system -#define execve p_real_execve +//#define execve p_real_execve //#define chdir p_real_chdir #undef MAKE_WRAP_SYM @@ -437,7 +465,8 @@ int real_system(const char *command) int real_execve(const char *filename, char *const argv[], char *const envp[]) { - return execve(filename, argv, envp); + long ret = g_execve_raw(filename, argv, envp); + return g_syscall_error(ret); } int real_chdir(const char *path) @@ -446,6 +475,12 @@ int real_chdir(const char *path) return g_syscall_error(ret); } +ssize_t real_readlink(const char *path, char *buf, size_t bufsiz) +{ + long ret = g_readlink_raw(path, buf, bufsiz); + return g_syscall_error(ret); +} + void real_sleep(unsigned int seconds) { struct timespec ts = { seconds, 0 };