about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/include/env.h8
-rw-r--r--src/os/os_wine.c7
-rw-r--r--src/tools/env.c79
-rw-r--r--wow64/CMakeLists.txt3
-rw-r--r--wow64/compiler.h7
-rw-r--r--wow64/wowbox64.c13
6 files changed, 105 insertions, 12 deletions
diff --git a/src/include/env.h b/src/include/env.h
index 2fed1341..0358bd9b 100644
--- a/src/include/env.h
+++ b/src/include/env.h
@@ -21,8 +21,14 @@
     STRING(NAME, name)
 */
 
+#ifdef _WIN32
+#define DEFAULT_LOG_LEVEL (LOG_INFO)
+#define BOX64_NOBANNER_DEFAULT (1)
+#else
 extern char* ftrace_name;
 #define DEFAULT_LOG_LEVEL (ftrace_name ? LOG_INFO : (isatty(fileno(stdout)) ? LOG_INFO : LOG_NONE))
+#define BOX64_NOBANNER_DEFAULT (isatty(fileno(stdout)) ? 0 : 1)
+#endif
 
 #define ENVSUPER1()                                                        \
     STRING(BOX64_ADDLIBS, addlibs)                                         \
@@ -83,7 +89,7 @@ extern char* ftrace_name;
     INTEGER(BOX64_LOG, log, DEFAULT_LOG_LEVEL, 0, 3)                       \
     INTEGER(BOX64_MALLOC_HACK, malloc_hack, 0, 0, 2)                       \
     INTEGER(BOX64_MAXCPU, new_maxcpu, 0, 0, 100)                           \
-    BOOLEAN(BOX64_NOBANNER, nobanner, (isatty(fileno(stdout)) ? 0 : 1))    \
+    BOOLEAN(BOX64_NOBANNER, nobanner, BOX64_NOBANNER_DEFAULT)    \
     STRING(BOX64_NODYNAREC, nodynarec)                                     \
     BOOLEAN(BOX64_NOGTK, nogtk, 0)                                         \
     BOOLEAN(BOX64_NOPULSE, nopulse, 0)                                     \
diff --git a/src/os/os_wine.c b/src/os/os_wine.c
index 949d7731..e7f34a99 100644
--- a/src/os/os_wine.c
+++ b/src/os/os_wine.c
@@ -187,4 +187,9 @@ void WinFree(void* ptr)
 void free(void* ptr)
 {
     RtlFreeHeap(myGetProcessHeap(), 0, ptr);
-}
\ No newline at end of file
+}
+
+int VolatileRangesContains(uintptr_t addr)
+{
+    return 0;
+}
diff --git a/src/tools/env.c b/src/tools/env.c
index 95012386..178db99b 100644
--- a/src/tools/env.c
+++ b/src/tools/env.c
@@ -2,8 +2,12 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
+#ifndef _WIN32
 #include <sys/mman.h>
 #include <sys/stat.h>
+#else
+#include <winternl.h>
+#endif
 #include <fcntl.h>
 #include <string.h>
 
@@ -73,6 +77,7 @@ static const char default_rcfile[] =
 
 static void addNewEnvVar(const char* s)
 {
+#ifndef _WIN32
     if (!s) return;
     char* p = box_strdup(s);
     char* e = strchr(p, '=');
@@ -85,6 +90,7 @@ static void addNewEnvVar(const char* s)
     ++e;
     setenv(p, e, 1);
     box_free(p);
+#endif
 }
 
 static void parseRange(const char* s, uintptr_t* start, uintptr_t* end)
@@ -106,6 +112,7 @@ static void applyCustomRules()
         SET_BOX64ENV(dump, 1);
     }
 
+#ifndef _WIN32
     if(box64env.is_cycle_log_overridden) {
         freeCycleLog(my_context);
         box64env.rolling_log = BOX64ENV(cycle_log);
@@ -158,6 +165,7 @@ static void applyCustomRules()
 
     if (box64env.is_dynarec_dump_range_overridden)
         parseRange(box64env.dynarec_dump_range, &box64env.dynarec_dump_range_start, &box64env.dynarec_dump_range_end);
+#endif
 
     if (box64env.dynarec_test) {
         SET_BOX64ENV(dynarec_fastnan, 0);
@@ -175,6 +183,7 @@ static void applyCustomRules()
         box64env.maxcpu = box64env.new_maxcpu;
     }
 
+#ifndef _WIN32
     if (box64env.dynarec_perf_map) {
         char pathname[32];
         snprintf(pathname, sizeof(pathname), "/tmp/perf-%d.map", getpid());
@@ -187,12 +196,16 @@ static void applyCustomRules()
         const char *p = getenv("SDL_VIDEO_GL_DRIVER");
         if(p) SET_BOX64ENV(libgl, box_strdup(p));
     }
+#endif
+
     if (box64env.avx == 2) {
         box64env.avx = 1;
         box64env.avx2 = 1;
     }
 
+#ifndef _WIN32
     if (box64env.exit) exit(0);
+#endif
 
     if (box64env.env) addNewEnvVar(box64env.env);
     if (box64env.env1) addNewEnvVar(box64env.env1);
@@ -201,7 +214,9 @@ static void applyCustomRules()
     if (box64env.env4) addNewEnvVar(box64env.env4);
     if (box64env.env5) addNewEnvVar(box64env.env5);
 
+#ifndef _WIN32
     if (box64env.addlibs) AddNewLibs(box64env.addlibs);
+#endif
 }
 
 static void trimStringInplace(char* s)
@@ -259,6 +274,7 @@ static void initializeEnvFile(const char* filename)
 {
     if (box64env.noenvfiles) return;
 
+#ifndef _WIN32
     FILE* f = NULL;
     if (filename) 
         f = fopen(filename, "r");
@@ -381,11 +397,13 @@ static void initializeEnvFile(const char* filename)
     }
     box_free(line);
     fclose(f);
+#endif
 }
 
 
 void InitializeEnvFiles()
 {
+#ifndef _WIN32
     if (BOX64ENV(envfile) && FileExist(BOX64ENV(envfile), IS_FILE))
         initializeEnvFile(BOX64ENV(envfile));
 #ifndef TERMUX
@@ -409,6 +427,7 @@ void InitializeEnvFiles()
             initializeEnvFile(tmp);
         }
     }
+#endif
 }
 
 static char old_entryname[256] = "";
@@ -458,6 +477,7 @@ static void internalApplyEnvFileEntry(const char* entryname, const box64env_t* e
 
 void ApplyEnvFileEntry(const char* entryname)
 {
+#ifndef _WIN32
     if (!entryname || !box64env_entries) return;
     if (!strcasecmp(entryname, old_entryname)) return;
 
@@ -480,6 +500,7 @@ void ApplyEnvFileEntry(const char* entryname)
     box64env_t* env = &kh_value(box64env_entries, k1);
     internalApplyEnvFileEntry(entryname, env);
     applyCustomRules();
+#endif
 }
 
 void LoadEnvVariables()
@@ -496,6 +517,7 @@ void LoadEnvVariables()
 #undef ADDRESS
 #undef STRING
 
+#ifndef _WIN32
     char* p;
     // load env vars from getenv()
 #define INTEGER(NAME, name, default, min, max)            \
@@ -544,6 +566,61 @@ void LoadEnvVariables()
 #undef BOOLEAN
 #undef ADDRESS
 #undef STRING
+#else /* _WIN32 */
+    char buffer[1024];
+    DWORD len;
+    // load env vars from getenv()
+#define INTEGER(NAME, name, default, min, max)                      \
+    len = GetEnvironmentVariableA(#NAME, buffer, sizeof(buffer));   \
+    if (len) {                                                      \
+        box64env.name = atoi(buffer);                               \
+        if (box64env.name < min || box64env.name > max) {           \
+            box64env.name = default;                                \
+        } else {                                                    \
+            box64env.is_##name##_overridden = 1;                    \
+            box64env.is_any_overridden = 1;                         \
+        }                                                           \
+    }
+#define INTEGER64(NAME, name, default)                              \
+    len = GetEnvironmentVariableA(#NAME, buffer, sizeof(buffer));   \
+    if (len) {                                                      \
+        ULONG tmp; /* FIXME: only positive 32-bit */                \
+        RtlCharToInteger(buffer, 10, &tmp);                         \
+        box64env.name = tmp;                                        \
+        box64env.is_##name##_overridden = 1;                        \
+        box64env.is_any_overridden = 1;                             \
+    }
+#define BOOLEAN(NAME, name, default)                                \
+    len = GetEnvironmentVariableA(#NAME, buffer, sizeof(buffer));   \
+    if (len) {                                                      \
+        box64env.name = buffer[0] != '0';                           \
+        box64env.is_##name##_overridden = 1;                        \
+        box64env.is_any_overridden = 1;                             \
+    }
+#define ADDRESS(NAME, name)                                         \
+    len = GetEnvironmentVariableA(#NAME, buffer, sizeof(buffer));   \
+    if (len) {                                                      \
+        ULONG tmp; /* FIXME: only positive 32-bit */                \
+        RtlCharToInteger(buffer, 10, &tmp);                         \
+        box64env.name = (uintptr_t)tmp;                             \
+        box64env.is_##name##_overridden = 1;                        \
+        box64env.is_any_overridden = 1;                             \
+    }
+#define STRING(NAME, name)                                                      \
+    len = GetEnvironmentVariableA(#NAME, buffer, sizeof(buffer));               \
+    if (len) {                                                                  \
+        box64env.name = (char*)RtlAllocateHeap(GetProcessHeap(), 0, len + 1);   \
+        if (box64env.name) strcpy(box64env.name, buffer);                       \
+        box64env.is_##name##_overridden = 1;                                    \
+        box64env.is_any_overridden = 1;                                         \
+    }
+    ENVSUPER()
+#undef INTEGER
+#undef INTEGER64
+#undef BOOLEAN
+#undef ADDRESS
+#undef STRING
+#endif /* _WIN32 */
     applyCustomRules();
 }
 
@@ -595,6 +672,7 @@ static kh_mapping_entry_t* mapping_entries = NULL;
 
 void RecordEnvMappings(uintptr_t addr, size_t length, int fd)
 {
+#ifndef _WIN32
     if (!envmap) { envmap = rbtree_init("envmap"); }
     if(!mapping_entries) mapping_entries = kh_init(mapping_entry);
 
@@ -642,6 +720,7 @@ void RecordEnvMappings(uintptr_t addr, size_t length, int fd)
         PrintEnvVariables(mapping->env, LOG_DEBUG);
     }
     box_free(lowercase_filename);
+#endif
 }
 
 void RemoveMapping(uintptr_t addr, size_t length)
diff --git a/wow64/CMakeLists.txt b/wow64/CMakeLists.txt
index 80fb9368..ca2adacb 100644
--- a/wow64/CMakeLists.txt
+++ b/wow64/CMakeLists.txt
@@ -72,6 +72,7 @@ set(WOW64_BOX64CPU_SRC
     "${BOX64_ROOT}/src/os/perfmap.c"
     "${BOX64_ROOT}/src/os/my_cpuid_wine.c"
     "${BOX64_ROOT}/src/tools/alternate.c"
+    "${BOX64_ROOT}/src/tools/env.c"
     "${BOX64_ROOT}/src/tools/rbtree.c"
 )
 
@@ -118,4 +119,4 @@ add_compile_definitions(DYNAREC ARM64)
 
 target_link_options(wowbox64 PRIVATE -nostdlib -nodefaultlibs -lclang_rt.builtins-aarch64)
 
-set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
\ No newline at end of file
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
diff --git a/wow64/compiler.h b/wow64/compiler.h
new file mode 100644
index 00000000..1fff78b3
--- /dev/null
+++ b/wow64/compiler.h
@@ -0,0 +1,7 @@
+#ifndef __COMPILER_H_
+#define __COMPILER_H_
+
+/* Things missing from mingw64 right now */
+#define ThreadWow64Context (29)
+
+#endif //__COMPILER_H_
diff --git a/wow64/wowbox64.c b/wow64/wowbox64.c
index d507d339..86a5fdfd 100644
--- a/wow64/wowbox64.c
+++ b/wow64/wowbox64.c
@@ -1,8 +1,10 @@
 #include <stdio.h>
 #include <windows.h>
 #include <ntstatus.h>
+#include <winternl.h>
 #include <winnt.h>
 
+#include "compiler.h"
 #include "os.h"
 #include "custommem.h"
 #include "env.h"
@@ -19,11 +21,6 @@ uint8_t box64_rdtsc_shift = 0;
 int box64_is32bits = 0;
 int box64_wine = 0; // this is for the emulated x86 Wine.
 
-box64env_t box64env = { 0 }; // FIXME: add real env support.
-
-box64env_t* GetCurEnvByAddr(uintptr_t addr) {
-    return &box64env;
-}
 
 int is_addr_unaligned(uintptr_t addr)
 {
@@ -81,8 +78,7 @@ void* WINAPI __wine_get_unix_opcode(void)
 
 NTSTATUS WINAPI BTCpuGetContext(HANDLE thread, HANDLE process, void* unknown, WOW64_CONTEXT* ctx)
 {
-    // NYI
-    return STATUS_SUCCESS;
+    return NtQueryInformationThread( thread, ThreadWow64Context, ctx, sizeof(*ctx), NULL );
 }
 
 void WINAPI BTCpuNotifyMemoryFree(PVOID addr, SIZE_T size, ULONG free_type)
@@ -115,8 +111,7 @@ NTSTATUS WINAPI BTCpuResetToConsistentState(EXCEPTION_POINTERS* ptrs)
 
 NTSTATUS WINAPI BTCpuSetContext(HANDLE thread, HANDLE process, void* unknown, WOW64_CONTEXT* ctx)
 {
-    // NYI
-    return STATUS_SUCCESS;
+    return NtSetInformationThread( thread, ThreadWow64Context, ctx, sizeof(*ctx) );
 }
 
 void WINAPI BTCpuSimulate(void)