aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit 60af6e70b6f2d099c933812692dcc4f5e139ee2c
parent 284a28bfb78993b5ac785686bedaa72bc6d5451c
Author: anon <anon@example.com>
Date:   Thu, 15 Oct 2026 00:55:57 +0000

Translate legacy file permissions and metadata for Linux startup

Diffstat:
Mdecompiled/Makefile.linux | 12+++++++++++-
Mdecompiled/runtime/guest_stdio.c | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adecompiled/tests/chmod.c | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Adecompiled/tests/guest_stat.c | 175+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools/reconstruction/test_portable_chmod.py | 27+++++++++++++++++++++++++++
Atools/reconstruction/test_portable_stat.py | 27+++++++++++++++++++++++++++
6 files changed, 443 insertions(+), 1 deletion(-)

diff --git a/decompiled/Makefile.linux b/decompiled/Makefile.linux @@ -108,6 +108,14 @@ build/linux/guest-stdio: tests/guest_stdio.c runtime/guest_stdio.c runtime/guest mkdir -p $(@D) $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@ +build/linux/chmod: tests/chmod.c runtime/guest_stdio.c runtime/guest_crt.c runtime/guest_format.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_stdio.h runtime/guest_crt.h runtime/guest_format.h runtime/guest_heap.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@ + +build/linux/guest-stat: tests/guest_stat.c runtime/guest_stdio.c runtime/guest_crt.c runtime/guest_format.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c runtime/recomp_types.h runtime/guest_stdio.h runtime/guest_crt.h runtime/guest_format.h runtime/guest_heap.h runtime/guest_memory.h + mkdir -p $(@D) + $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -lm -o $@ + build/linux/dynamic-imports: tests/dynamic_imports.c runtime/linux_imports.c runtime/linux_platform.c runtime/linux_sync.c runtime/linux_tls.c runtime/linux_network.c runtime/guest_crt.c runtime/guest_stdio.c runtime/guest_format.c runtime/guest_exception.c runtime/guest_msvcp.c runtime/guest_heap.c runtime/guest_memory.c runtime/recomp_state.c $(wildcard runtime/*.h) mkdir -p $(@D) $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -pthread -lm -o $@ @@ -116,7 +124,7 @@ build/linux/create-directory: tests/create_directory.c runtime/linux_platform.c mkdir -p $(@D) $(CC) $(CPPFLAGS) $(CFLAGS) $(filter %.c,$^) -pthread -lm -o $@ -test: build/linux/create-directory build/linux/dynamic-imports build/linux/linecrypt build/linux/guest-heap build/linux/guest-crt build/linux/linux-platform build/linux/msvcp-strings build/linux/ace-token build/linux/msvcp-stdio-data build/linux/guest-eh build/linux/guest-rand build/linux/semaphore build/linux/guest-scanf build/linux/network-startup build/linux/os-version build/linux/guest-format build/linux/event build/linux/tls build/linux/module-filename build/linux/delete-file build/linux/guest-stdio build/linux/guest-exception build/linux/platform-diagnostics build/linux/new-handler +test: build/linux/guest-stat build/linux/chmod build/linux/create-directory build/linux/dynamic-imports build/linux/linecrypt build/linux/guest-heap build/linux/guest-crt build/linux/linux-platform build/linux/msvcp-strings build/linux/ace-token build/linux/msvcp-stdio-data build/linux/guest-eh build/linux/guest-rand build/linux/semaphore build/linux/guest-scanf build/linux/network-startup build/linux/os-version build/linux/guest-format build/linux/event build/linux/tls build/linux/module-filename build/linux/delete-file build/linux/guest-stdio build/linux/guest-exception build/linux/platform-diagnostics build/linux/new-handler ./build/linux/linecrypt ./build/linux/guest-heap ./build/linux/guest-crt @@ -141,5 +149,7 @@ test: build/linux/create-directory build/linux/dynamic-imports build/linux/linec ./build/linux/new-handler ./build/linux/dynamic-imports ./build/linux/create-directory + ./build/linux/chmod + ./build/linux/guest-stat -include $(OBJECTS:.o=.d) diff --git a/decompiled/runtime/guest_stdio.c b/decompiled/runtime/guest_stdio.c @@ -6,6 +6,7 @@ #include <errno.h> #include <fcntl.h> #include <limits.h> +#include <strings.h> #include <sys/stat.h> #include <unistd.h> @@ -312,6 +313,92 @@ static void print_file(int list) g_esp += 4; } +static void crt_chmod(void) +{ + const char *name = (const char *)ADDR(MEM32(g_esp + 4)); + uint32_t mode = MEM32(g_esp + 8); + if (strchr(name, ':') || !strncmp(name, "\\\\", 2)) { + fprintf(stderr, "Windows drive/UNC chmod paths are not implemented: %s\n", name); + abort(); + } + char *path = strdup(name); + if (!path) abort(); + for (char *p = path; *p; ++p) if (*p == '\\') *p = '/'; + struct stat info; + if (stat(path, &info)) g_eax = file_error(errno); + else { + if (!S_ISREG(info.st_mode)) { + fprintf(stderr, "Guest chmod on non-regular files is not implemented: %s\n", name); + abort(); + } + /* MSVCRT controls the read-only attribute; preserve host read/execute + * permissions and restore owner write access when _S_IWRITE is set. */ + mode_t permissions = mode & 0x80 ? info.st_mode | S_IWUSR : info.st_mode & ~0222; + g_eax = chmod(path, permissions) ? file_error(errno) : 0; + } + free(path); + g_esp += 4; +} + +static void crt_stat(void) +{ + const char *name = (const char *)ADDR(MEM32(g_esp + 4)); + uint32_t output = MEM32(g_esp + 8); + if (strchr(name, ':') || !strncmp(name, "\\\\", 2)) { + fprintf(stderr, "Windows drive/UNC stat paths are not implemented: %s\n", name); + abort(); + } + size_t length = strlen(name); + /* The legacy CRT rejects trailing separators and wildcard queries. */ + if (!length || name[length - 1] == '/' || name[length - 1] == '\\' || strpbrk(name, "*?")) { + g_eax = file_error(ENOENT); + g_esp += 4; + return; + } + char *path = strdup(name); + if (!path) abort(); + for (char *p = path; *p; ++p) if (*p == '\\') *p = '/'; + struct statx info; + if (statx(AT_FDCWD, path, 0, STATX_BASIC_STATS | STATX_BTIME, &info)) { + g_eax = file_error(errno); + free(path); + g_esp += 4; + return; + } + + uint16_t mode = S_ISDIR(info.stx_mode) ? 0x4000 : 0x8000; + if (!S_ISDIR(info.stx_mode) && !S_ISREG(info.stx_mode)) { + fprintf(stderr, "Guest stat on special files is not implemented: %s\n", name); + abort(); + } + mode |= 0444; + if (info.stx_mode & 0222) mode |= 0222; + const char *extension = strrchr(path, '.'); + if (S_ISDIR(info.stx_mode) || (extension && + (!strcasecmp(extension, ".exe") || !strcasecmp(extension, ".com") || + !strcasecmp(extension, ".bat") || !strcasecmp(extension, ".cmd")))) mode |= 0111; + + /* VC6 _stat is 36 bytes, with two untouched padding bytes at offset 14. + * Device zero identifies the portable filesystem; host inode/UID widths + * never enter this Windows structure. The legacy size field wraps at 32 bits. */ + MEM32(output) = MEM32(output + 16) = 0; + MEM16(output + 4) = MEM16(output + 10) = MEM16(output + 12) = 0; + MEM16(output + 6) = mode; + MEM16(output + 8) = 1; + MEM32(output + 20) = S_ISDIR(info.stx_mode) ? 0 : (uint32_t)info.stx_size; + int64_t times[] = {info.stx_atime.tv_sec, info.stx_mtime.tv_sec, + info.stx_mask & STATX_BTIME ? info.stx_btime.tv_sec : info.stx_mtime.tv_sec}; + for (unsigned i = 0; i < 3; ++i) { + if (times[i] < 0 || times[i] > INT32_MAX) { + MEM32(output + 24 + i * 4) = UINT32_MAX; + file_error(EINVAL); + } else MEM32(output + 24 + i * 4) = (uint32_t)times[i]; + } + free(path); + g_eax = 0; + g_esp += 4; +} + static void crt_fprintf(void) { print_file(0); } static void crt_vfprintf(void) { print_file(1); } @@ -322,6 +409,7 @@ recomp_func_t guest_stdio_lookup(const char *name) {"fflush", crt_fflush}, {"fputc", crt_fputc}, {"fwrite", crt_fwrite}, {"fputs", crt_fputs}, {"setvbuf", crt_setvbuf}, {"_fileno", crt_fileno}, {"fprintf", crt_fprintf}, {"vfprintf", crt_vfprintf}, + {"_chmod", crt_chmod}, {"_stat", crt_stat}, }; for (unsigned i = 0; i < sizeof(functions) / sizeof(functions[0]); ++i) if (!strcmp(name, functions[i].name)) return functions[i].function; diff --git a/decompiled/tests/chmod.c b/decompiled/tests/chmod.c @@ -0,0 +1,115 @@ +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#ifdef _WIN32 +#include <windows.h> +static HMODULE crt; +#else +#include "guest_stdio.h" +#include "guest_crt.h" +#include "guest_memory.h" +#include <sys/stat.h> +#include <unistd.h> +recomp_func_t recomp_lookup(uint32_t address) { (void)address; abort(); } +recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); } +#endif + +static void check_mode(const char *path, unsigned mode, int expected_result, unsigned expected_error) +{ +#ifdef _WIN32 + int *(__cdecl *crt_errno)(void) = (void *)GetProcAddress(crt, "_errno"); + int (__cdecl *crt_chmod)(const char *, int) = (void *)GetProcAddress(crt, "_chmod"); + assert(crt_errno && crt_chmod); + *crt_errno() = 77; +#else + strcpy((char *)ADDR(0x50002000u), path); + MEM32(guest_crt_errno_address()) = 77; + g_esp = 0x5000ff00u; + MEM32(g_esp + 4) = 0x50002000u; + MEM32(g_esp + 8) = mode; + g_ebx = 0x12345678u; + g_esi = 0x23456789u; + g_edi = 0x3456789au; + g_ebp = 0x456789abu; +#endif + +#ifdef _WIN32 + int result = crt_chmod(path, mode); + unsigned error = *crt_errno(); +#else + guest_stdio_lookup("_chmod")(); + int result = (int32_t)g_eax; + unsigned error = MEM32(guest_crt_errno_address()); +#endif + + if (result != expected_result || error != expected_error) + fprintf(stderr, "chmod %s mode %x: result %d errno %u\n", path, mode, result, error); + assert(result == expected_result && error == expected_error); + if (!result) { +#ifdef _WIN32 + DWORD attributes = GetFileAttributesA(path); + assert(attributes != INVALID_FILE_ATTRIBUTES); + assert(!!(attributes & FILE_ATTRIBUTE_READONLY) == !(mode & 0x80)); +#else + char normalized[128]; + strcpy(normalized, path); + for (char *p = normalized; *p; ++p) if (*p == '\\') *p = '/'; + struct stat info; + assert(!stat(normalized, &info)); + assert(!!(info.st_mode & S_IWUSR) == !!(mode & 0x80)); + assert((info.st_mode & 0444) == 0444 && !(info.st_mode & 0111)); +#endif + } +#ifndef _WIN32 + assert(g_esp == 0x5000ff04u); + assert(g_ebx == 0x12345678u && g_esi == 0x23456789u); + assert(g_edi == 0x3456789au && g_ebp == 0x456789abu); +#endif +} + +int main(void) +{ + /* Compare the legacy system CRT in isolated directories. */ +#ifdef _WIN32 + crt = LoadLibraryA("msvcrt.dll"); + assert(crt); + char temporary[MAX_PATH], directory[MAX_PATH]; + assert(GetTempPathA(sizeof(temporary), temporary)); + assert(GetTempFileNameA(temporary, "aoc", 0, directory)); + assert(DeleteFileA(directory) && CreateDirectoryA(directory, NULL)); + assert(SetCurrentDirectoryA(directory) && CreateDirectoryA("nested", NULL)); +#else + assert(guest_map("chmod test memory", 0x50000000u, 0x10000u)); + g_fs_base = 0x50001000u; + char directory[] = "/tmp/ao-chmod-test-XXXXXX"; + assert(mkdtemp(directory) && !chdir(directory) && !mkdir("nested", 0700)); +#endif + FILE *file = fopen("nested/file.txt", "w"); + assert(file && fputs("preserved", file) >= 0 && !fclose(file)); +#ifndef _WIN32 + assert(!chmod("nested/file.txt", 0644)); +#endif + check_mode("nested\\file.txt", 0x100, 0, 77); + check_mode("nested/file.txt", 0x180, 0, 77); + check_mode("nested/file.txt", 0, 0, 77); + check_mode("nested/file.txt", 0x80, 0, 77); + check_mode("nested/file.txt", 1, 0, 77); + check_mode("nested/file.txt", 0xffffffffu, 0, 77); + check_mode("missing", 0x180, -1, 2); + check_mode("missing\\file", 0x180, -1, 2); + check_mode("nested\\file.txt\\child", 0x180, -1, 2); + check_mode("", 0x180, -1, 2); + file = fopen("nested/file.txt", "r"); + char contents[16] = {0}; + assert(file && fread(contents, 1, sizeof(contents), file) == 9 && !fclose(file)); + assert(!strcmp(contents, "preserved") && !remove("nested/file.txt")); +#ifdef _WIN32 + assert(RemoveDirectoryA("nested") && SetCurrentDirectoryA(temporary) && RemoveDirectoryA(directory)); +#else + assert(!rmdir("nested") && !chdir("/tmp") && !rmdir(directory)); +#endif + puts("chmod: 10 cases, read-only transitions, mode bits, errors, preserved contents and ABI passed"); + return 0; +} diff --git a/decompiled/tests/guest_stat.c b/decompiled/tests/guest_stat.c @@ -0,0 +1,175 @@ +#define _GNU_SOURCE +#include <assert.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> +#ifdef _WIN32 +#include <windows.h> +#include <winioctl.h> +static HMODULE crt; +static uint32_t storage[11]; +#else +#include "guest_stdio.h" +#include "guest_crt.h" +#include "guest_memory.h" +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> +recomp_func_t recomp_lookup(uint32_t address) { (void)address; abort(); } +recomp_func_t recomp_lookup_import(uint32_t address) { return recomp_lookup(address); } +#endif +static int64_t timestamp; + +static unsigned char *record(void) +{ +#ifdef _WIN32 + return (unsigned char *)storage + 4; +#else + return (unsigned char *)ADDR(0x50005004u); +#endif +} + +static int query(const char *path) +{ + memset(record() - 4, 0xa5, 44); +#ifdef _WIN32 + int *(__cdecl *crt_errno)(void) = (void *)GetProcAddress(crt, "_errno"); + int (__cdecl *crt_stat)(const char *, void *) = (void *)GetProcAddress(crt, "_stat"); + assert(crt_errno && crt_stat); + *crt_errno() = 77; + int result = crt_stat(path, record()); + unsigned error = *crt_errno(); +#else + strcpy((char *)ADDR(0x50002000u), path); + MEM32(guest_crt_errno_address()) = 77; + g_esp = 0x5000ff00u; + MEM32(g_esp + 4) = 0x50002000u; + MEM32(g_esp + 8) = 0x50005004u; + g_ebx = 0x12345678u; + g_esi = 0x23456789u; + g_edi = 0x3456789au; + g_ebp = 0x456789abu; + guest_stdio_lookup("_stat")(); + int result = (int32_t)g_eax; + unsigned error = MEM32(guest_crt_errno_address()); + assert(g_esp == 0x5000ff04u); + assert(g_ebx == 0x12345678u && g_esi == 0x23456789u); + assert(g_edi == 0x3456789au && g_ebp == 0x456789abu); +#endif + assert(error == (result ? 2 : 77)); + assert(*(uint32_t *)(record() - 4) == 0xa5a5a5a5u); + assert(*(uint32_t *)(record() + 36) == 0xa5a5a5a5u); + return result; +} + +static void check_file(const char *path, unsigned mode, uint32_t size) +{ + unsigned char *bytes = record(); + + int result = query(path); + + assert(result == 0); + assert(*(uint32_t *)bytes == *(uint32_t *)(bytes + 16)); + assert(*(uint16_t *)(bytes + 4) == 0); + assert(*(uint16_t *)(bytes + 6) == mode); + assert(*(uint16_t *)(bytes + 8) == 1); + assert(*(uint16_t *)(bytes + 10) == 0 && *(uint16_t *)(bytes + 12) == 0); + assert(bytes[14] == 0xa5 && bytes[15] == 0xa5); + assert(*(uint32_t *)(bytes + 20) == size); + for (unsigned i = 24; i < 36; i += 4) { + int64_t value = *(uint32_t *)(bytes + i); + int64_t now = time(NULL); + if (value < timestamp - 1 || value > now + 1) + fprintf(stderr, "%s time offset %u: %lld outside creation interval\n", path, i, (long long)value); + assert(value >= timestamp - 1 && value <= now + 1); + } +} + +static void missing_path_preserves_output(const char *path) +{ + unsigned char expected[44]; + memset(expected, 0xa5, sizeof(expected)); + + int result = query(path); + + assert(result == -1 && !memcmp(record() - 4, expected, sizeof(expected))); +} + +static void resize_sparse_file(uint64_t size) +{ +#ifdef _WIN32 + HANDLE file = CreateFileA("large.dat", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, 0, NULL); + assert(file != INVALID_HANDLE_VALUE); + DWORD written; + assert(DeviceIoControl(file, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &written, NULL)); + LARGE_INTEGER length; + length.QuadPart = size; + assert(SetFilePointerEx(file, length, NULL, FILE_BEGIN) && SetEndOfFile(file)); + assert(CloseHandle(file)); +#else + int file = open("large.dat", O_WRONLY | O_CREAT, 0644); + assert(file >= 0 && !ftruncate(file, size) && !close(file)); +#endif +} + +int main(void) +{ + /* Use current timestamps to avoid the legacy CRT's historical-DST bug. */ + timestamp = time(NULL); +#ifdef _WIN32 + crt = LoadLibraryA("msvcrt.dll"); + assert(crt); + char temporary[MAX_PATH], directory[MAX_PATH]; + assert(GetTempPathA(sizeof(temporary), temporary)); + assert(GetTempFileNameA(temporary, "ast", 0, directory)); + assert(DeleteFileA(directory) && CreateDirectoryA(directory, NULL)); + assert(SetCurrentDirectoryA(directory) && CreateDirectoryA("nested", NULL)); +#else + assert(guest_map("stat test memory", 0x50000000u, 0x10000u)); + g_fs_base = 0x50001000u; + char directory[] = "/tmp/ao-stat-test-XXXXXX"; + assert(mkdtemp(directory) && !chdir(directory) && !mkdir("nested", 0700)); +#endif + const char *names[] = {"file.txt", "file.EXE", "file.com", "file.bat", "file.cmd", "file.py", "nested/file"}; + for (unsigned i = 0; i < 7; ++i) { + FILE *file = fopen(names[i], "wb"); + assert(file && fwrite("abcdefghij", 1, 10, file) == 10 && !fclose(file)); + check_file(names[i], i >= 1 && i <= 4 ? 0x81ff : 0x81b6, 10); + } + check_file("nested\\file", 0x81b6, 10); + check_file("nested", 0x41ff, 0); + check_file(".", 0x41ff, 0); +#ifdef _WIN32 + assert(SetFileAttributesA("file.txt", FILE_ATTRIBUTE_READONLY)); +#else + assert(!chmod("file.txt", 0444)); +#endif + check_file("file.txt", 0x8124, 10); + missing_path_preserves_output("missing"); + missing_path_preserves_output("missing/file"); + missing_path_preserves_output("file.txt/child"); + missing_path_preserves_output("nested\\"); + missing_path_preserves_output("nested/"); + missing_path_preserves_output("*"); + missing_path_preserves_output(""); + resize_sparse_file(0x80000001ull); + check_file("large.dat", 0x81b6, 0x80000001u); + resize_sparse_file(0x100000009ull); + check_file("large.dat", 0x81b6, 9); +#ifdef _WIN32 + assert(SetFileAttributesA("file.txt", FILE_ATTRIBUTE_NORMAL)); +#else + assert(!chmod("file.txt", 0644)); +#endif + for (unsigned i = 0; i < 7; ++i) assert(!remove(names[i])); + assert(!remove("large.dat")); +#ifdef _WIN32 + assert(RemoveDirectoryA("nested") && SetCurrentDirectoryA(temporary) && RemoveDirectoryA(directory)); +#else + assert(!rmdir("nested") && !chdir("/tmp") && !rmdir(directory)); +#endif + puts("stat: 20 cases, 36-byte layout, modes, timestamps, sparse sizes, errors, padding and ABI passed"); + return 0; +} diff --git a/tools/reconstruction/test_portable_chmod.py b/tools/reconstruction/test_portable_chmod.py @@ -0,0 +1,27 @@ +"""Compare guest file permissions with Windows x86 MSVCRT.""" +import pathlib +import subprocess + + +root = pathlib.Path(__file__).resolve().parents[2] +decompiled = root / "decompiled" +work = root / "tools/reconstruction/work/portable-chmod" +work.mkdir(parents=True, exist_ok=True) +reference = work / "reference.exe" +subprocess.run([ + str(root / "tools/rust/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe"), + "-O2", "tests/chmod.c", "-o", str(reference), +], cwd=decompiled, check=True) +expected = subprocess.check_output([str(reference)], text=True, timeout=30) +linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:] +linux_output = "/mnt/" + work.drive[0].lower() + work.as_posix()[2:] + "/translated" +wsl = ["wsl", "-d", "Ubuntu-26.04", "--cd", linux_path, "--exec"] +subprocess.run(wsl + [ + "gcc", "-O2", "-DRECOMP_PORTABLE", "-Iruntime", "-fno-strict-aliasing", + "tests/chmod.c", "runtime/guest_stdio.c", "runtime/guest_crt.c", "runtime/guest_format.c", + "runtime/guest_heap.c", "runtime/guest_memory.c", "runtime/recomp_state.c", + "-lm", "-o", linux_output, +], check=True) +actual = subprocess.check_output(wsl + [linux_output], text=True, timeout=30) +assert actual == expected, (expected, actual) +print("Windows == Linux: " + actual.strip()) diff --git a/tools/reconstruction/test_portable_stat.py b/tools/reconstruction/test_portable_stat.py @@ -0,0 +1,27 @@ +"""Compare guest file metadata with Windows x86 MSVCRT.""" +import pathlib +import subprocess + + +root = pathlib.Path(__file__).resolve().parents[2] +decompiled = root / "decompiled" +work = root / "tools/reconstruction/work/portable-stat" +work.mkdir(parents=True, exist_ok=True) +reference = work / "reference.exe" +subprocess.run([ + str(root / "tools/rust/llvm-mingw-20261006-ucrt-x86_64/bin/i686-w64-mingw32-clang.exe"), + "-O2", "tests/guest_stat.c", "-o", str(reference), +], cwd=decompiled, check=True) +expected = subprocess.check_output([str(reference)], text=True, timeout=30) +linux_path = "/mnt/" + decompiled.drive[0].lower() + decompiled.as_posix()[2:] +linux_output = "/mnt/" + work.drive[0].lower() + work.as_posix()[2:] + "/translated" +wsl = ["wsl", "-d", "Ubuntu-26.04", "--cd", linux_path, "--exec"] +subprocess.run(wsl + [ + "gcc", "-O2", "-DRECOMP_PORTABLE", "-Iruntime", "-fno-strict-aliasing", + "tests/guest_stat.c", "runtime/guest_stdio.c", "runtime/guest_crt.c", "runtime/guest_format.c", + "runtime/guest_heap.c", "runtime/guest_memory.c", "runtime/recomp_state.c", + "-lm", "-o", linux_output, +], check=True) +actual = subprocess.check_output(wsl + [linux_output], text=True, timeout=30) +assert actual == expected, (expected, actual) +print("Windows == Linux: " + actual.strip())