upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorNotRexed <therealnothingfn@gmail.com>2026-11-28 20:19:25 -0500
committerNotRexed <therealnothingfn@gmail.com>2026-11-28 20:19:25 -0500
commit0a325350e4a9e58ca83ae43e886f4e6caa9955b5 (patch)
treed01b9a2addf39805658ade89d4e978b44139795d /scripts
parent504ea0e418064d28ad33275f6e3c8eac5b37a9a8 (diff)
parent5825b02ff89bca1a2d1331d982818e3dbb74d597 (diff)
Merge origin/main into next
Diffstat (limited to 'scripts')
-rw-r--r--scripts/compute_workers_win.py44
-rw-r--r--scripts/first_look.ps127
2 files changed, 54 insertions, 17 deletions
diff --git a/scripts/compute_workers_win.py b/scripts/compute_workers_win.py
index 1ab6915ca..9fd974e0a 100644
--- a/scripts/compute_workers_win.py
+++ b/scripts/compute_workers_win.py
@@ -73,7 +73,7 @@ def verify(job, process, mib, worker):
73 73
74@contextlib.contextmanager 74@contextlib.contextmanager
75def job(mib, worker): 75def job(mib, worker):
76 if not 0 < mib <= ((1 << (c.sizeof(Z)*8))-1) >> 20: 76 if type(mib) is not int or not 0 < mib <= ((1 << (c.sizeof(Z)*8))-1) >> 20:
77 raise ValueError("invalid --memory-mib for Windows job") 77 raise ValueError("invalid --memory-mib for Windows job")
78 h = check(create_job(None, None)) # unnamed, never inherited; no breakaway 78 h = check(create_job(None, None)) # unnamed, never inherited; no breakaway
79 try: 79 try:
@@ -98,7 +98,7 @@ def output_lock(path):
98 # One nonblocking, no-share open; duplicated into workers so an interrupted parent cannot 98 # One nonblocking, no-share open; duplicated into workers so an interrupted parent cannot
99 # release exclusivity before the last worker has actually left. Never delete/recreate the lock. 99 # release exclusivity before the last worker has actually left. Never delete/recreate the lock.
100 h = create_file(str(path), 0xc0000000, 0, None, 4, 0x80, None) 100 h = create_file(str(path), 0xc0000000, 0, None, 4, 0x80, None)
101 if h == H(-1).value: 101 if not h or h == H(-1).value:
102 raise c.WinError(c.get_last_error()) 102 raise c.WinError(c.get_last_error())
103 try: 103 try:
104 yield h 104 yield h
@@ -121,6 +121,14 @@ def drain(h):
121 121
122@contextlib.contextmanager 122@contextlib.contextmanager
123def start(request, mib, lock): 123def start(request, mib, lock):
124 if type(lock) is not int or lock <= 0:
125 raise ValueError("invalid Windows lock handle")
126 if type(mib) is not int or not 0 < mib <= ((1 << (c.sizeof(Z)*8))-1) >> 20:
127 raise ValueError("invalid --memory-mib for Windows job")
128 # A single framed gate validated before creating a job object or spawning a child.
129 gate = (json.dumps([str(request), mib, lock]) + "\n").encode("ascii")
130 if len(gate) > 65536:
131 raise ValueError("compute worker gate too large")
124 with job(mib, True) as h: 132 with job(mib, True) as h:
125 si = subprocess.STARTUPINFO(lpAttributeList={"handle_list": [lock]}) 133 si = subprocess.STARTUPINFO(lpAttributeList={"handle_list": [lock]})
126 os.set_handle_inheritable(lock, True) 134 os.set_handle_inheritable(lock, True)
@@ -134,10 +142,7 @@ def start(request, mib, lock):
134 check(assign(h, int(p._handle))) 142 check(assign(h, int(p._handle)))
135 attached = True 143 attached = True
136 verify(h, int(p._handle), mib, True) 144 verify(h, int(p._handle), mib, True)
137 # A single framed gate. EOF, even after a short write, is not permission to start. 145 # EOF, even after a short write, is not permission to start.
138 gate = (json.dumps([str(request), mib, lock])+"\n").encode("ascii")
139 if len(gate)>65536:
140 raise ValueError("compute worker gate too large")
141 p.stdin.write(gate) 146 p.stdin.write(gate)
142 p.stdin.close() 147 p.stdin.close()
143 yield p 148 yield p
@@ -169,14 +174,29 @@ def run(requests, mib, lock):
169 174
170def child(): 175def child():
171 line = sys.stdin.buffer.readline(65537) 176 line = sys.stdin.buffer.readline(65537)
172 if not line.endswith(b"\n") or len(line)>65536: 177 if not line.endswith(b"\n") or len(line) > 65536:
173 raise ValueError("no complete Windows compute gate") 178 raise ValueError("no complete Windows compute gate")
174 request, mib, lock = json.loads(line)
175 # NULL queries this worker's immediate job. No job handle in a worker can keep it alive after
176 # coordinator death. No library/source inputs touched before membership and effective limits.
177 verify(None, current(), mib, True)
178 os.set_handle_inheritable(lock, False)
179 try: 179 try:
180 payload = json.loads(line.decode("ascii"))
181 except (UnicodeDecodeError, ValueError, RecursionError):
182 raise ValueError("invalid Windows compute gate") from None
183 if not isinstance(payload, list) or len(payload) != 3:
184 raise ValueError("invalid Windows compute gate")
185 request, mib, lock = payload
186 if (
187 not isinstance(request, str)
188 or not request
189 or type(mib) is not int
190 or mib <= 0
191 or type(lock) is not int
192 or lock <= 0
193 ):
194 raise ValueError("invalid Windows compute gate")
195 try:
196 # NULL queries this worker's immediate job. No job handle in a worker can keep it alive after
197 # coordinator death. No library/source inputs touched before membership and effective limits.
198 verify(None, current(), mib, True)
199 os.set_handle_inheritable(lock, False)
180 sys.path.insert(0, str(Path(__file__).resolve().parent)) 200 sys.path.insert(0, str(Path(__file__).resolve().parent))
181 from translate_pipeline_compute import run_request 201 from translate_pipeline_compute import run_request
182 run_request(Path(request)) 202 run_request(Path(request))
diff --git a/scripts/first_look.ps1 b/scripts/first_look.ps1
index f302d5701..78ebc758b 100644
--- a/scripts/first_look.ps1
+++ b/scripts/first_look.ps1
@@ -9,13 +9,25 @@ $root = Split-Path $PSScriptRoot -Parent
9$Exe = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Exe) 9$Exe = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Exe)
10if (-not (Test-Path -LiteralPath $Exe -PathType Leaf)) { throw "$Exe not found" } 10if (-not (Test-Path -LiteralPath $Exe -PathType Leaf)) { throw "$Exe not found" }
11$image = Get-Item -LiteralPath $Exe 11$image = Get-Item -LiteralPath $Exe
12if (-not $GameDir) { $GameDir = $image.DirectoryName } 12if ($GameDir) {
13 $GameDir = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($GameDir)
14 if (-not (Test-Path -LiteralPath $GameDir -PathType Container)) { throw "$GameDir not found or not a directory" }
15} else {
16 $GameDir = $image.DirectoryName
17}
13$name = [IO.Path]::GetFileNameWithoutExtension($Exe) 18$name = [IO.Path]::GetFileNameWithoutExtension($Exe)
14$out = Join-Path $root "reports\exe\$name" 19$out = Join-Path $root "reports\exe\$name"
15New-Item -ItemType Directory -Force $out | Out-Null 20if (Test-Path -LiteralPath $out -PathType Leaf) { throw "$out is a file, not a directory" }
21[void][IO.Directory]::CreateDirectory($out)
16 22
17$fs = [IO.File]::OpenRead($Exe); $mz = New-Object byte[] 2; [void]$fs.Read($mz, 0, 2); $fs.Close() 23$fs = [IO.File]::OpenRead($Exe)
18if ([Text.Encoding]::ASCII.GetString($mz) -ne "MZ") { 24try {
25 $mz = New-Object byte[] 2
26 $read = $fs.Read($mz, 0, 2)
27} finally {
28 $fs.Dispose()
29}
30if ($read -ne 2 -or [Text.Encoding]::ASCII.GetString($mz) -ne "MZ") {
19 throw "$Exe doesn't start with an MZ header. It's still packaged or encrypted, so there's nothing to inspect." 31 throw "$Exe doesn't start with an MZ header. It's still packaged or encrypted, so there's nothing to inspect."
20} 32}
21 33
@@ -24,6 +36,8 @@ $hash = (Get-FileHash -LiteralPath $Exe -Algorithm SHA256).Hash.ToLower()
24"sha256 $hash size $size" | Tee-Object -LiteralPath (Join-Path $out "hash.txt") 36"sha256 $hash size $size" | Tee-Object -LiteralPath (Join-Path $out "hash.txt")
25 37
26Write-Host "`n== PE inspection" 38Write-Host "`n== PE inspection"
39$reportPath = Join-Path $out "$([IO.Path]::GetFileName($Exe)).json"
40if (Test-Path -LiteralPath $reportPath -PathType Leaf) { Remove-Item -LiteralPath $reportPath -Force }
27python -I (Join-Path $root "tools\pe_inspect.py") $Exe --game-dir $GameDir --out $out 41python -I (Join-Path $root "tools\pe_inspect.py") $Exe --game-dir $GameDir --out $out
28if ($LASTEXITCODE -ne 0) { throw "pe_inspect failed" } 42if ($LASTEXITCODE -ne 0) { throw "pe_inspect failed" }
29 43
@@ -85,7 +99,9 @@ if (-not $hasTls -or $stale) {
85 & $cmake --build $build --target gta6rt @configArgs 99 & $cmake --build $build --target gta6rt @configArgs
86 if ($LASTEXITCODE -ne 0) { throw "Building gta6rt in $build failed ($LASTEXITCODE)" } 100 if ($LASTEXITCODE -ne 0) { throw "Building gta6rt in $build failed ($LASTEXITCODE)" }
87 } else { 101 } else {
102 $global:LASTEXITCODE = 0
88 & (Join-Path $PSScriptRoot "build_runtime.ps1") 103 & (Join-Path $PSScriptRoot "build_runtime.ps1")
104 if ($LASTEXITCODE -ne 0) { throw "build_runtime.ps1 failed ($LASTEXITCODE)" }
89 } 105 }
90 $rt = Find-RuntimeLoader $build $folders 106 $rt = Find-RuntimeLoader $build $folders
91 if (-not $rt) { throw "runtime build did not produce gta6rt.exe in $build" } 107 if (-not $rt) { throw "runtime build did not produce gta6rt.exe in $build" }
@@ -102,7 +118,8 @@ Write-Host "`n== Loader dry run (map, relocate, bind imports; nothing executes)"
102$dryRunExitCode = $LASTEXITCODE 118$dryRunExitCode = $LASTEXITCODE
103 119
104# Shim to-do list, grouped by DLL, most functions first. 120# Shim to-do list, grouped by DLL, most functions first.
105$report = Get-Content -LiteralPath (Join-Path $out "$([IO.Path]::GetFileName($Exe)).json") -Raw | ConvertFrom-Json 121if (-not (Test-Path -LiteralPath $reportPath -PathType Leaf)) { throw "pe_inspect did not write $reportPath" }
122$report = Get-Content -LiteralPath $reportPath -Raw | ConvertFrom-Json
106$todo = $report.imports | Where-Object { $_.where -eq "shim" } | Sort-Object { -$_.functions.Count } 123$todo = $report.imports | Where-Object { $_.where -eq "shim" } | Sort-Object { -$_.functions.Count }
107$lines = foreach ($t in $todo) { "{0,-40} {1,5}" -f $t.dll, $t.functions.Count } 124$lines = foreach ($t in $todo) { "{0,-40} {1,5}" -f $t.dll, $t.functions.Count }
108# "unverified" only comes from a host that isn't Windows and has no Wine prefix (pe_inspect.py, classify_dll): most 125# "unverified" only comes from a host that isn't Windows and has no Wine prefix (pe_inspect.py, classify_dll): most