Skip to content
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: 2 additions & 0 deletions players/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.wasm
target/
7 changes: 7 additions & 0 deletions players/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions players/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "players"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib"]

[profile.release]
panic = "abort"
opt-level = "s"
lto = true
codegen-units = 1
debug = false
44 changes: 44 additions & 0 deletions players/IMPLEMENTATION-NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# players implementation notes

## What was built
`players/` is a `no_std` Rust cdylib (`src/lib.rs`), built by `build.sh`:
- `ld-wrap.sh` (the same linker wrapper as wind_meteors') drops rustc's `--stack-first`, `--allow-undefined`, `__heap_base` and `__data_end`.
- Link options: data base 524288, table base 368, stack 4096. The stack falls after the data, inside the window (`__stack_pointer` starts at 528560).
- Fuel: `/data/tools/wasm_fuel.py` runs on the linked module (rule v1); `--check` passes.
- All eleven exports and the five data words follow the manifest entry; imports are exactly the entry's list.
- All block access is unaligned raw loads and stores at the offsets of `layout.json`. The module has no statics beyond the five data words and a one-entry function-pointer table that keeps the `env.__indirect_function_table` import (read volatile in `Shutdown`).
- Buffers (path event 28 bytes, 64 waypoints, 256 unit ids, mission params) are on the stack, about 1 KiB at the deepest.
- The module is 15283 bytes. The entry is `blocked`, so there is no size or fuel budget to meet.

## Verdicts, in order
1. req1 (first session): `equal` on all 11 recordings (`budgets: not_judged`, scenarios not judged: the entry is blocked).
2. req1 (after the review fixes, 15245 bytes; the mailbox restarted at req1): `equal` on all 11 recordings.
3. req1 (after the second review, 15283 bytes; the mailbox restarted again): `equal` on all 11 recordings.
4. req1 (third review fixes, 15284 bytes): `failed` — `mission-kill-of-type` gave `host-runtime`, the other ten `equal`; the module was unchanged between this and the next.
5. req2 (same module): `equal` on all 11 recordings.

## Unclear or open points in the spec and kit
- A radius condition (`VictoryMoveUnitToRadius`) already satisfied: the spec states the clamp and the `UnitsInRange` walk without a `satisfied == 0` guard (unlike the passes and build classes), so the module repeats them on every check. No recording shows it.
- A scan of a slice whose `unitsBegin` is null is not defined; the module visits nothing.
- The condition count is capped at 16 where the lists are walked (the spec says "at most 16").
- `PLAYERS_KILL_UNITS` is specified to test only alive and dying flags, not `unitDefIndex`; implemented as written.
- Everything the spec lists under "Not covered by any recording" (respawn, watch mode, rank pass, cheats, SEND_UNIT, unannounced transfer, etc.) is implemented from the text alone and unverified by the gate.
- `docs/module-abi.md` §3.1 asks for `--no-stack-first`; the local wasm-ld (20.1.8) doesn't list it, so the wrapper only adds it when the help does. The resulting layout (stack after data) was checked by hand.

## Answers to /srv/inbox/review.md
1. Null `info`: reads give 0 and writes are skipped (`info8`, and guards in SET_TYPE, watch mode and the respawn's host figures). A second review found `commander_name` and the unit-type name unguarded: both now return 0 (null player, info or def, or a side of 5 or more), and a name match against 0 is false. The spec defines no null case; this keeps the module off address 0.
2. A null `services.SimAlloc` result: the check returns 0 and stores nothing.
3. `Apply`'s size is read as `i32`; a negative size is refused like a size below 8.
4. The slice walks stop when `u + 280` would wrap.
5. `event_size` has arms for 208, 209 (12) and 210 (48); `player_addr` is removed.
6. The stack top is 528560 (notes corrected). The wrapper adds `--no-stack-first` when the linker lists it; not run against 22.1.8 here.

## Second review (findings 1-6)
1-3: fixed as above; notes corrected. 4: `tg` read once. 5: left as is (the defeat and victory rules differ per class; the repetition is small). 6: `build.sh` quotes the linker path; `--no-stack-first` is added when the local wasm-ld lists it (20.1.8 doesn't; 22.1.8 does).

## Third review
1. Fixed: null `player` of a unit in `kill_units` (selfDestruct 1) and `give_unit` (the owner doesn't play); null entries of a condition list are skipped (a victory check counts one as not met); a negative or large count is clamped to 0..16.
2. Answered, not changed: the respawn follows section 4 for any type index and side byte, as the spec says ("for any *t*, 0 included"); the spec defines no guard, and a guard would change the imports the recordings expect. A side of 5 or more in the respawn reads past `sideDefs`; the engine keeps sides below 5.
3. Fixed in these notes (528560).
4. Left: `ld-wrap.sh` adds `--no-stack-first` whenever the linker lists it (22.1.8 does); the local 20.1.8 doesn't and already puts the stack after the data. `/data/tools/wasm_fuel.py` is the kit's path.
5. Shutdown's table read is kept for the table import (ABI 9.1); the source comment says it isn't spec behaviour.
8 changes: 8 additions & 0 deletions players/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
# Builds players.wasm (metered by the data kit's fuel pass) next to this script.
set -e
cd "$(dirname "$0")"
cargo rustc --release --target wasm32-unknown-unknown -- -C linker="$PWD/ld-wrap.sh" -C target-cpu=mvp -C target-feature=+sign-ext,+bulk-memory \
-C link-arg=--import-memory -C link-arg=--import-table -C link-arg=--global-base=524288 -C link-arg=--table-base=368 \
-C link-arg=--no-entry -C link-arg=-zstack-size=4096 -C link-arg=--gc-sections
python3 -I /data/tools/wasm_fuel.py target/wasm32-unknown-unknown/release/players.wasm -o players.wasm
9 changes: 9 additions & 0 deletions players/ld-wrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# rustc passes --stack-first and --allow-undefined; the ABI forbids both.
# ABI 3.1 wants --no-stack-first; a linker whose help doesn't list it already puts the stack after the data.
for a in "$@"; do
shift
case "$a" in --stack-first|--allow-undefined|--export=__heap_base|--export=__data_end) ;; *) set -- "$@" "$a";; esac
done
if wasm-ld --help | grep -q -e '--no-stack-first'; then set -- "$@" --no-stack-first; fi
exec wasm-ld "$@"
Loading
Loading