mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 20:10:44 +00:00
An original C program, tests/compat_fixtures/gate_a2.c, is built from source with the mingw-w64 C runtime (UCRT) and run through the loader, the standard services and the ARM64 DBT. The runtime's own startup code runs before main; the program uses argc and argv, the heap, qsort, printf, a file written with fprintf and read back with fgets, atexit, and a return from main. Expected output is recomputed in Rust, not read back from a run. Control variants end in a failed check, in exit(42) and in abort(). The test fails, and does not skip, when the compiler is missing, so the CI workflow installs mingw-w64. Nothing from mingw-w64 is stored in the repository. Signed-off-by: zachdoxsee <zachdoxsee36@gmail.com>
106 lines
6.9 KiB
Markdown
106 lines
6.9 KiB
Markdown
# Gate A: a compiled C program
|
|
|
|
Gate A asks for an independently compiled C program, exercising allocation,
|
|
file operations, arithmetic, function calls and error handling, to run through
|
|
Xenora. The maintainer split it into two milestones. Gate A is complete only
|
|
when both pass.
|
|
|
|
| Milestone | What it is | Status |
|
|
| --- | --- | --- |
|
|
| A1 | An original C program with no C library linked, importing documented `kernel32.dll` and `ucrtbase.dll` functions, run through the loader and the ARM64 DBT with proper process exit | Passes locally; awaiting independent review |
|
|
| A2 | A hosted C program: a real C runtime startup, the standard C library, `argc` and `argv`, stdio and formatted output, normal exit and runtime cleanup | Passes locally; awaiting independent review |
|
|
|
|
## A1
|
|
|
|
The program is [`tests/compat_fixtures/gate_a1.c`](../../tests/compat_fixtures/gate_a1.c).
|
|
Its build configuration and provenance are in
|
|
[`tests/compat_fixtures/README.md`](../../tests/compat_fixtures/README.md#gate-a1-a-c-program-with-no-c-library).
|
|
The gate is `crates/loader/tests/gate_a1.rs`:
|
|
|
|
```sh
|
|
cargo test --locked -p xenora-loader --test gate_a1 -- --nocapture
|
|
```
|
|
|
|
The test builds the program from source, then runs each build through
|
|
`run_synthetic_startup` with `register_standard_services`, loaded away from its
|
|
preferred base. It checks, at `-O0`, `-O1`, `-O2` and `-Os`:
|
|
|
|
- the 20 imports are bound and the 6 base relocations applied;
|
|
- the guest ends with `ExitReason::ProcessExit(0x00A1A1A1)`, all 32 bits;
|
|
- it ran as translated code, with service calls;
|
|
- the text report it wrote matches a report recomputed in Rust;
|
|
- the data file holds the 64 sorted records, the file it looked for does not exist, and the handle it left open was closed by the exit;
|
|
- its result block in guest memory holds the expected values, the block it kept is readable and the block it freed is unmapped.
|
|
|
|
Three controls must fail in the stated way: a wrong expectation exits with the
|
|
number of the failed check, an import that no service provides is refused
|
|
before entry, and a step budget that is too small is not an exit. A variant
|
|
whose entry point returns its status gives the same result as `ExitProcess`.
|
|
|
|
### What A1 does not show
|
|
|
|
- It is one program. Local runs used Homebrew clang 23.1.6 and Apple clang 17.0.0, each with LLD 23.1.5. Another compiler or a larger program can need instructions and services this one does not.
|
|
- Most services it calls are marked partial in the registry. They did what this program needs.
|
|
- It runs in the DBT only. The interpreter has no import dispatch.
|
|
- It reaches the guest through a test, not through `xenora run`, which accepts only two built-in fixtures.
|
|
- Nothing here concerns a commercial game or an Xbox launch environment.
|
|
|
|
## A2
|
|
|
|
The program is [`tests/compat_fixtures/gate_a2.c`](../../tests/compat_fixtures/gate_a2.c).
|
|
Its build configuration and provenance are in
|
|
[`tests/compat_fixtures/README.md`](../../tests/compat_fixtures/README.md#gate-a2-a-hosted-c-program).
|
|
The gate is `crates/loader/tests/gate_a2.rs`:
|
|
|
|
```sh
|
|
cargo test --locked -p xenora-loader --test gate_a2 -- --nocapture
|
|
```
|
|
|
|
"Hosted" means the program is linked with a real C runtime, whose own startup
|
|
code runs before `main`. Here that runtime is mingw-w64's, in its UCRT
|
|
flavour: the startup objects and a little of GCC's support library are linked
|
|
into the executable, and the C library itself is imported by name from the
|
|
Universal C Runtime's API-set DLLs and from `kernel32.dll`. Xenora's services
|
|
answer those imports. Nothing from Windows is loaded.
|
|
|
|
The test builds the program from source with `x86_64-w64-mingw32-gcc`. It
|
|
fails, and does not skip, when that compiler is missing. It then runs each
|
|
build through `run_synthetic_startup` with `register_standard_services`,
|
|
loaded away from its preferred base, with the command line
|
|
`gate-a2.exe 2026 xenora` set through `ServicesState::set_program_arguments`.
|
|
It checks, at `-O0`, `-O1`, `-O2` and `-Os`:
|
|
|
|
- every import is bound (50 at each level with the toolchain used locally; the test prints the count) and base relocations are applied;
|
|
- the guest ends with `ExitReason::ProcessExit(0)`: `main` returned and the runtime's startup code passed its result to `exit`;
|
|
- captured standard output equals, byte for byte, text recomputed in Rust from the description of the program, including the line a function registered with `atexit` prints after `main` has returned; standard error is empty;
|
|
- the report file the program wrote with `fprintf` and `fputs` is on the in-memory drive with the recomputed contents, the file it looked for was not created, and no handle is left open;
|
|
- it ran as translated code, with service calls.
|
|
|
|
The program checks its own results as well: it prints its arguments, fills
|
|
heap memory from a small generator, sorts it with `qsort` and a callback,
|
|
checksums it before and after, writes the report, reads it back with `fgets`,
|
|
`strtoul` and `strtoull`, and confirms that a missing file is reported. It
|
|
exits with the number of the first check that fails, and counts the checks
|
|
that passed; a complete run counts 76.
|
|
|
|
Seven more tests guard against a runtime that reports success for everything:
|
|
|
|
- another seed and label give another output and another report;
|
|
- four wrong command lines each fail the check that looks at them, with that check's number as the exit status and its message on standard error;
|
|
- a variant with one wrong expectation exits with 22;
|
|
- a variant that calls `exit(42)` half way ends with 42, its `atexit` function still runs, and the report is never written;
|
|
- a variant that calls `abort()` half way ends with 3 and its `atexit` function does not run;
|
|
- a step budget that is too small is not an exit;
|
|
- the Rust restatement of the program is itself checked not to be degenerate.
|
|
|
|
### What A2 does not show
|
|
|
|
- It is one program and one C runtime: mingw-w64 14.0.0 with GCC 16.2.0 locally. A program built with Microsoft's compiler starts differently and imports other functions; none has been tried. A larger program can need instructions and services this one does not.
|
|
- The same source built natively with Apple clang prints the same text once carriage returns are removed. That comparison was made by hand and is not part of the test. Nothing was compared with Windows or with x86 hardware.
|
|
- No floating point is formatted and no input is read. `printf` refuses the floating-point and wide-character conversions, and `stdin` and the `scanf` family do not exist.
|
|
- Most services the program calls are marked partial in the registry. No locale exists, no signal handler or exception filter is ever called, the environment table is empty, and a C stream is unbuffered and has no seek. They did what this program needs.
|
|
- `VirtualProtect`, `VirtualQuery` and `__C_specific_handler` are stubs that stop the guest if called. The program imports them and never calls them.
|
|
- It runs in the DBT only, on one guest thread.
|
|
- It reaches the guest through a test, not through `xenora run`.
|
|
- Nothing here concerns a commercial game or an Xbox launch environment.
|