8000 [WOW64] Supported logging to stdout by ksco · Pull Request #2679 · ptitSeb/box64 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[WOW64] Supported logging to stdout #2679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/build_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

void PrintBox64Version(int prefix)
{
printf_ftrace(prefix, BOX64_BUILD_INFO_STRING WITH_DYNAREC_STR WITH_TRACE_STR " built on %s %s\n",
PrintfFtrace(prefix, BOX64_BUILD_INFO_STRING WITH_DYNAREC_STR WITH_TRACE_STR " built on %s %s\n",
__DATE__, __TIME__);
}

Expand Down
42 changes: 6 additions & 36 deletions src/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,36 +194,6 @@ void openFTrace(int reopen)
}
}

static void check_ftrace()
{
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 printf_ftrace(int prefix, const char* fmt, ...)
{
if(ftrace_name) {
check_ftrace();
}

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);
}

void my_prepare_fork()
{
if (ftrace_has_pid && ftrace && (ftrace != stdout) && (ftrace != stderr)) {
Expand Down Expand Up @@ -575,12 +545,12 @@ void AddNewLibs(const char* list)
}

void PrintHelp() {
printf_ftrace(0, "This is Box64, the Linux x86_64 emulator with a twist.\n");
printf_ftrace(0, "Usage is 'box64 [options] path/to/software [args]' to launch x86_64 software.\n");
printf_ftrace(0, " options are:\n");
printf_ftrace(0, " '-v'|'--version' to print box64 version and quit\n");
printf_ftrace(0, " '-h'|'--help' to print this and quit\n");
printf_ftrace(0, " '-k'|'--kill-all' to kill all box64 instances\n");
PrintfFtrace(0, "This is Box64, the Linux x86_64 emulator with a twist.\n");
PrintfFtrace(0, "Usage is 'box64 [options] path/to/software [args]' to launch x86_64 software.\n");
PrintfFtrace(0, " options are:\n");
PrintfFtrace(0, " '-v'|'--version' to print box64 version and quit\n");
PrintfFtrace(0, " '-h'|'--help' to print this and quit\n");
PrintfFtrace(0, " '-k'|'--kill-all' to kill all box64 instances\n");
}

void KillAllInstances()
Expand Down
4 changes: 2 additions & 2 deletions src/dynarec/arm64/dynarec_arm64_00.c
Original file line number Diff line number Diff line change
Expand Up @@ -2591,7 +2591,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
*ok = 0;
*need_epilog = 1;
} else {
MESSAGE(LOG_DUMP, "Native Call to %s\n", getBridgeName((void*)ip)?:GetNativeName(GetNativeFnc(ip)));
MESSAGE(LOG_DUMP, "Native Call to %s\n", GetBridgeName((void*)ip) ?: GetNativeName(GetNativeFnc(ip)));
x87_stackcount(dyn, ninst, x1);
x87_forget(dyn, ninst, x3, x4, 0);
sse_purge07cache(dyn, ninst, x3);
Expand Down Expand Up @@ -3374,7 +3374,7 @@ uintptr_t dynarec64_00(dynarec_arm_t* dyn, uintptr_t addr, uintptr_t ip, int nin
MOV64x(x2, addr);
}
PUSH1(x2);
MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", getBridgeName((void*)(dyn->insts[ninst].natcall-1))?:GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall-1)), dyn->insts[ninst].retn);
MESSAGE(LOG_DUMP, "Native Call to %s (retn=%d)\n", GetBridgeName((void*)(dyn->insts[ninst].natcall - 1)) ?: GetNativeName(GetNativeFnc(dyn->insts[ninst].natcall - 1)), dyn->insts[ninst].retn);
SKIPTEST(x1); // disable test as this hack dos 2 instructions for 1
// calling a native function
SMEND();
Expand Down
43 changes: 15 additions & 28 deletions src/include/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,55 +70,42 @@ extern int box64_tcmalloc_minimal; // when using tcmalloc_minimal
#define LOG_NEVER 3
#define LOG_VERBOSE 3

#ifndef _WIN32 // TODO: better wow64 support?
void printf_ftrace(int prefix, const char* fmt, ...);

#define printf_log_prefix(prefix, L, ...) \
do { \
if ((L) <= BOX64ENV(log)) { printf_ftrace(prefix + (prefix && (L) == LOG_NONE), __VA_ARGS__); } \
#define printf_log_prefix(prefix, L, ...) \
do { \
if ((L) <= BOX64ENV(log)) { PrintfFtrace(prefix + (prefix && (L) == LOG_NONE), __VA_ARGS__); } \
} while (0)

#define printf_log(L, ...) printf_log_prefix(1, L, __VA_ARGS__)

#define printf_dump_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dump) || ((L) <= BOX64ENV(log))) { printf_ftrace(prefix, __VA_ARGS__); } \
#define printf_dump_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dump) || ((L) <= BOX64ENV(log))) { PrintfFtrace(prefix, __VA_ARGS__); } \
} while (0)

#define printf_dump(L, ...) printf_dump_prefix(1, L, __VA_ARGS__)

#define printf_dlsym_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dlsym_error) || BOX64ENV(dump) || ((L) <= BOX64ENV(log))) { printf_ftrace(prefix, __VA_ARGS__); } \
#define printf_dlsym_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dlsym_error) || BOX64ENV(dump) || ((L) <= BOX64ENV(log))) { PrintfFtrace(prefix, __VA_ARGS__); } \
} while (0)

#define printf_dlsym_dump(L, ...) printf_dlsym_dump_prefix(1, L, __VA_ARGS__)

#define printf_dlsym_dump_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dlsym_error) || ((L) <= BOX64ENV(log))) { printf_ftrace(prefix, __VA_ARGS__); } \
#define printf_dlsym_dump_prefix(prefix, L, ...) \
do { \
if (BOX64ENV(dlsym_error) || ((L) <= BOX64ENV(log))) { PrintfFtrace(prefix, __VA_ARGS__); } \
} while (0)

#define printf_dlsym(L, ...) printf_dlsym_prefix(1, L, __VA_ARGS__)

#define dynarec_log_prefix(prefix, L, ...) \
do { \
if ((L) <= BOX64ENV(dynarec_log)) { printf_ftrace(prefix, __VA_ARGS__); } \
#define dynarec_log_prefix(prefix, L, ...) \
do { \
if ((L) <= BOX64ENV(dynarec_log)) { PrintfFtrace(prefix, __VA_ARGS__); } \
} while (0)

#define dynarec_log(L, ...) dynarec_log_prefix(1, L, __VA_ARGS__)

#else
#define printf_log_prefix(prefix, L, ...)
#define printf_log(L, ...)
#define printf_dump_prefix(prefix, L, ...)
#define printf_dump(L, ...)
#define printf_dlsym_prefix(prefix, L, ...)
#define printf_dlsym(L, ...)
#define dynarec_log_prefix(prefix, L, ...)
#define dynarec_log(L, ...)
#endif


#define EXPORT __attribute__((visibility("default")))
#ifdef BUILD_DYNAMIC
Expand Down
2 changes: 1 addition & 1 deletion src/include/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#ifdef _WIN32
#define DEFAULT_LOG_LEVEL (LOG_INFO)
#define BOX64_NOBANNER_DEFAULT (1)
#define BOX64_NOBANNER_DEFAULT (0)
#else
extern char* ftrace_name;
#define DEFAULT_LOG_LEVEL (ftrace_name ? LOG_INFO : (isatty(fileno(stdout)) ? LOG_INFO : LOG_NONE))
Expand Down
3 changes: 3 additions & 0 deletions src/include/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void PersonalityAddrLimit32Bit(void);

int IsAddrElfOrFileMapped(uintptr_t addr);
const char* GetNativeName(void* p);
const char* GetBridgeName(void* p);
// ----------------------------------------------------------------

#ifndef _WIN32
Expand Down Expand Up @@ -96,4 +97,6 @@ extern int isnanf(float);
#define isinff isinf
#endif

void PrintfFtrace(int prefix, const char* fmt, ...);

#endif //__OS_H_
44 changes: 42 additions & 2 deletions src/os/os_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sys/personality.h>
#include <dlfcn.h>
#include <string.h>
#include <stdarg.h>

#include "os.h"
#include "signals.h"
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -161,4 +167,38 @@ int InternalMunmap(void* addr, unsigned long length)
int ret = libc_munmap(addr, length);
#endif
return ret;
}
}

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);
}
25 changes: 25 additions & 0 deletions src/os/os_wine.c
10000
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <ntstatus.h>
#include <winternl.h>

#include "os.h"
#include "wine/debug.h"

#define HandleToULong(h) ((ULONG)(ULONG_PTR)(h))

Expand Down Expand Up @@ -54,11 +57,20 @@ void EmuX86Syscall(void* emu)
// FIXME
}

const char* GetBridgeName(void* p)
{
return NULL;
}

const char* GetNativeName(void* p)
{
return NULL;
}

void* GetNativeFnc(uintptr_t fnc)
{
return NULL;
}

void PersonalityAddrLimit32Bit(void)
{
Expand Down Expand Up @@ -193,3 +205,16 @@ int VolatileRangesContains(uintptr_t addr)
{
return 0;
}

void PrintfFtrace(int prefix, const char* fmt, ...)
{
static char buf[1024] = { 0 };

char* p = buf;
strcpy(p, prefix > 1 ? "[\033[31mBOX64\033[0m] " : "[BOX64] ");
va_list args;
va_start(args, fmt);
vsprintf(p + strlen(p), fmt, args);
va_end(args);
__wine_dbg_output(p);
}
1 change: 1 addition & 0 deletions wow64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set_target_properties(wow64_test_interpreter PROPERTIES COMPILE_DEFINITIONS "TES
set(WOW64_BOX64CPU_SRC
"${BOX64_ROOT}/src/custommem.c"
"${BOX64_ROOT}/src/dynarec/arm64/arm64_immenc.c"
"${BOX64_ROOT}/src/dynarec/arm64/arm64_printer.c"
"${BOX64_ROOT}/src/dynarec/arm64/dynarec_arm64_arch.c"
"${BOX64_ROOT}/src/dynarec/arm64/dynarec_arm64_functions.c"
"${BOX64_ROOT}/src/dynarec/arm64/dynarec_arm64_jmpnext.c"
Expand Down
15 changes: 15 additions & 0 deletions wow64/crt.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
#include <windows.h>
Expand Down Expand Up @@ -83,4 +84,18 @@ ldiv_t __cdecl ldiv(long num, long denom)
void _assert (const char *_Message, const char *_File, unsigned _Line)
{
// NYI
}

char* strerror(int e)
{
return "error";
}

int snprintf(char* restrict s, size_t n, const char* restrict fmt, ...)
{
va_list args;
va_start(args, fmt);
int result = _vsnprintf(s, n, fmt, args);
va_end(args);
return result;
}
5 changes: 4 additions & 1 deletion wow64/wowbox64.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <winnt.h>

#include "compiler.h"
#include "debug.h"
#include "os.h"
#include "custommem.h"
#include "dynablock.h"
Expand Down Expand Up @@ -207,6 +208,8 @@ STATIC_ASSERT(offsetof(x64emu_t, win64_teb) == 3120, offset_of_b_must_be_4);

LoadEnvVariables();

printf_log(LOG_INFO, "libwowbox64.dll process initializing.\n");

memset(bopcode, 0xc3, sizeof(bopcode));
memset(unxcode, 0xc3, sizeof(unxcode));
bopcode[0] = 0x2ecd;
Expand All @@ -217,7 +220,7 @@ STATIC_ASSERT(offsetof(x64emu_t, win64_teb) == 3120, offset_of_b_must_be_4);

if ((ULONG_PTR)bopcode >> 32 || (ULONG_PTR)unxcode >> 32)
{
__wine_dbg_output( "box64cpu loaded above 4G, disabling\n" );
printf_log(LOG_NONE, "box64cpu loaded above 4G, disabling\n");
return STATUS_INVALID_ADDRESS;
}

Expand Down
0