diff options
Diffstat (limited to 'src/os/os_linux.c')
| -rw-r--r-- | src/os/os_linux.c | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/os/os_linux.c b/src/os/os_linux.c index 556d4d9b..a8258db6 100644 --- a/src/os/os_linux.c +++ b/src/os/os_linux.c @@ -6,6 +6,7 @@ #include <sys/personality.h> #include <dlfcn.h> #include <string.h> +#include <stdarg.h> #include "os.h" #include "signals.h" @@ -89,11 +90,16 @@ void* GetSegmentBase(uint32_t desc) return ptr; } +const char* GetBridgeName(void* p) +{ + return getBridgeName(p); +} + const char* GetNativeName(void* p) { static char buff[500] = { 0 }; { - const char* n = getBridgeName(p); + const char* n = GetBridgeName(p); if (n) return n; } @@ -161,4 +167,38 @@ int InternalMunmap(void* addr, unsigned long length) int ret = libc_munmap(addr, length); #endif return ret; -} \ No newline at end of file +} + +extern FILE* ftrace; +extern char* ftrace_name; + +static void checkFtrace() +{ + int fd = fileno(ftrace); + if (fd < 0 || lseek(fd, 0, SEEK_CUR) == (off_t)-1) { + ftrace = fopen(ftrace_name, "a"); + printf_log(LOG_INFO, "%04d|Recreated trace because fd was invalid\n", GetTID()); + } +} + +void PrintfFtrace(int prefix, const char* fmt, ...) +{ + if (ftrace_name) { + checkFtrace(); + } + + static const char* names[2] = { "BOX64", "BOX32" }; + + if (prefix && ftrace == stdout) { + if (prefix > 1) { + fprintf(ftrace, "[\033[31m%s\033[0m] ", names[box64_is32bits]); + } else { + fprintf(ftrace, "[%s] ", names[box64_is32bits]); + } + } + va_list args; + va_start(args, fmt); + vfprintf(ftrace, fmt, args); + fflush(ftrace); + va_end(args); +} |