code wiki / _hdl_build / nx_profile_fit_provenance_t319.nx

nx_profile_fit_provenance_t319.nx source

↩ module page · 813 lines · 42557 B

1// nx_profile_fit.nx -- cross-section shape priors derived from a supplied mesh. 2// Triangle-plane segments are grouped by X projection, then fitted to an ellipse 3// and dimensionless angular radial ratios. This is not full contour segmentation. 4// The procedural emitter controls final dimensions; the ratios remain derived 5// from the source mesh and retain its provenance and applicable obligations. 6// Extraction alone establishes neither anatomical fidelity nor permission to reuse. 7// Infinigen reference-profile lofting is a related research approach, not a claim 8// of implementation equivalence or validated physical accuracy. 9// 10// nx_profile_fit <oracle.nxmesh> <out.dat> [step_permil] [canon_out.dat] [part_id] 11// Optional part_id declares a single-part oracle and bypasses body band grouping. 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_syscalls.nx" 14import "nx_section_projection.nx" 15 16const PF_Q14: i64 = 16384 17const PF_BIG: i64 = 2000000000 18const PF_M8388607: i64 = 8388607 19const PF_M8388608: i64 = 8388608 20const PF_POSQ0: i64 = 4096 21const PF_TARGET: i64 = 200000 22const PF_MAGIC_40500: i64 = 40500 23// ★ANGULAR RESOLUTION OF THE PRIOR. 24 bins (15 deg) proved too coarse to be worth anything: it smoothed 24// the back instead of carrying the scapular ridges, and measured WORSE than no prior. The prior can only 25// carry structure the emitter's ring can represent, so keep bins <= the emitter's radial segment count. 26const PF_NB: i64 = 48 27const PF_MAXST: i64 = 256 // station slices 28const PF_MAXPT: i64 = 4096 // section points held per station 29const PF_XBINS: i64 = 128 // x-histogram bins used to separate torso from limbs 30const PF_GAP: i64 = 2 // empty x-bins that separate two clusters 31const PF_MAXRUN: i64 = 8 32const PF_MAXPARTS: i64 = 8 33const PF_MAXK: i64 = 12 // control rings kept per part after factorisation 34// ★262144 -> 1048576: emitting a row under N canon parts multiplies the output by N. 139 rows x ~223B is 35// 31KB for one part, but x7 for the skull canon is ~217KB -- 83 percent of the old cap, with NO bounds check 36// in pf_puts/pf_putint, so a slightly finer STEP would have silently corrupted memory instead of erroring. 37const PF_OUTCAP: i64 = 1048576 // output text buffer 38// part indices must match the canon: 0 torso, 1 arm, 2 leg, 4 head 39const PF_PTORSO: i64 = 0 40const PF_PARM: i64 = 1 41const PF_PLEG: i64 = 2 42const PF_PHEAD: i64 = 4 43// anatomical band limits, per-mille of stature (canon ring extents, not tuned constants) 44const PF_TORSO_LO: i64 = 430 45const PF_TORSO_HI: i64 = 908 46// ★BAND FLOORS ARE ANATOMY, NOT TUNING: below the wrist the outer cluster is the HAND and below the ankle 47// it is the FOOT (a forward-running part in the canon, so its section is not the leg tube's section). 48// Profiling those heights would feed hand/foot outlines into the arm/leg tubes. 49const PF_ARM_LO: i64 = 470 50const PF_ARM_HI: i64 = 838 51const PF_LEG_LO: i64 = 60 52const PF_LEG_HI: i64 = 452 53const PF_HEAD_LO: i64 = 852 54 55func pf_hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n+1 } sys_write(1, s, n); return 0 } 56func pf_pn(v: i64) -> i64 { 57 let b: *u8 = sys_mmap(32); var x: i64 = v; var ng: i64 = 0 58 if x < 0 { ng = 1; x = 0-x } 59 var i: i64 = 31 60 if x == 0 { b[i] = 48 as u8; i = i-1 } 61 while x > 0 { b[i] = (48 + x%10) as u8; x = x/10; i = i-1 } 62 if ng == 1 { b[i] = 45 as u8; i = i-1 } 63 sys_write(1, (b as i64 + i + 1) as *u8, 31-i); return 0 64} 65func pf_satoi(s: *u8) -> i64 { 66 var i: i64 = 0; var n: i64 = 0 67 while s[i] != (0 as u8) { let c: i64 = s[i] as i64; if c >= 48 { if c <= 57 { n = n*10 + (c-48) } } i = i+1 } 68 return n 69} 70func pf_rdbits(b: *u8, o: i64) -> i64 { 71 return (b[o] as i64) | ((b[o+1] as i64)<<8) | ((b[o+2] as i64)<<16) | ((b[o+3] as i64)<<24) 72} 73func pf_f32mul(b: *u8, o: i64, mul: i64) -> i64 { 74 let bits: i64 = pf_rdbits(b, o) 75 let sign: i64 = (bits>>31) & 1 76 let exp: i64 = (bits>>23) & 255 77 let mant: i64 = bits & PF_M8388607 78 if exp == 0 { return 0 } 79 let m: i64 = (mant | PF_M8388608) * mul 80 var e: i64 = exp - 127 - 23 81 var v: i64 = 0 82 if e >= 0 { v = m << e } else { let sh: i64 = 0-e; v = (m + (1 << (sh-1))) >> sh } 83 if sign == 1 { v = 0-v } 84 return v 85} 86func pf_isqrt(v: i64) -> i64 { if v <= 0 { return 0 } var x: i64 = v; var y: i64 = (x+1)/2; while y < x { x = y; y = (x + v/x)/2 } return x } 87func pf_wrap(d: i64) -> i64 { var x: i64 = d % 360; if x < 0 { x = x + 360 } return x } 88// Bhaskara-I degree sine in Q14 -- our own integer trig, exact at 0/30/90/150/180 89func pf_sin_fill(t: *i64) -> i64 { 90 var d: i64 = 0 91 while d < 180 { let P: i64 = d*(180-d); t[d] = PF_Q14*4*P/(PF_MAGIC_40500-P); t[d+180] = 0-t[d]; d = d+1 } 92 return 0 93} 94// append a decimal integer plus one separator byte to the output buffer 95func pf_putint(buf: *u8, pos: *i64, v: i64, sep: i64) -> i64 { 96 var p: i64 = pos[0] 97 var x: i64 = v 98 if x < 0 { buf[p] = 45 as u8; p = p+1; x = 0-x } 99 let tmp: *u8 = sys_mmap(32) 100 var i: i64 = 31 101 if x == 0 { tmp[i] = 48 as u8; i = i-1 } 102 while x > 0 { tmp[i] = (48 + x%10) as u8; x = x/10; i = i-1 } 103 var k: i64 = i+1 104 while k < 32 { buf[p] = tmp[k]; p = p+1; k = k+1 } 105 buf[p] = sep as u8; p = p+1 106 pos[0] = p 107 return 0 108} 109func pf_puts(buf: *u8, pos: *i64, s: *u8) -> i64 { 110 var p: i64 = pos[0] 111 var i: i64 = 0 112 while s[i] != (0 as u8) { buf[p] = s[i]; p = p+1; i = i+1 } 113 pos[0] = p 114 return 0 115} 116 117// ============================ SECTION FIT ============================ 118// Fit one clustered slice: bounding ellipse (centre + semi-axes from the section's own extent), then the 119// per-angle support radius measured along the ELLIPSE PARAMETER directions the emitter actually uses -- 120// the emitter places a vertex at (ra*cos t, rb*sin t), so the ratio must be measured along that same ray or 121// it would not compose with the emitter's parameterisation. 122// Writes ra,rb into fit[0..1] and PF_NB ratios into rat[]; returns 1 on success, 0 if the section is degenerate. 123// ★NB IS A RUNTIME PARAMETER, NOT A COMPILE-TIME CEILING (2026-08-23). PF_NB=48 was a PICKED constant 124// and it was THE high-frequency detail ceiling of the entire human generator: the oracle holds up to 125// PF_MAXPT=4096 points per section, the consumer (nx_body_gen BG_NBMAX) can hold 96 bins, and we were 126// binning to 48 and discarding the rest of the measured resolution. Measured consequence: with HF on, 127// mesh radial 24 UNDER-samples the 48-bin prior, radial 48 matches it (best head detail 208), and 128// radial 96 OVERSAMPLES a band-limited signal -- shape DEGRADES 923->900 because Catmull-Rom through 129// the same 48 bins invents form between them. So detail was never bounded by triangles; it was bounded 130// by how finely we measured. Threading nb makes that bound DATA-DERIVED and liftable. 131// ⚠Default stays PF_NB so every existing caller is BYTE-IDENTICAL by construction -- the neutrality 132// proof is `same args -> same output`, not an assertion. 133func pf_fit_section(px: *i64, pz: *i64, idx: *i64, cnt: i64, sinT: *i64, fit: *i64, rat: *i64, nb: i64) -> i64 { 134 if cnt < nb { return 0 } 135 var xmn: i64 = PF_BIG; var xmx: i64 = 0-PF_BIG; var zmn: i64 = PF_BIG; var zmx: i64 = 0-PF_BIG 136 var k: i64 = 0 137 while k < cnt { 138 let j: i64 = idx[k] 139 let x: i64 = px[j]; let z: i64 = pz[j] 140 if x < xmn { xmn = x } 141 if x > xmx { xmx = x } 142 if z < zmn { zmn = z } 143 if z > zmx { zmx = z } 144 k = k+1 145 } 146 let xc: i64 = (xmn+xmx)/2; let zc: i64 = (zmn+zmx)/2 147 var ra: i64 = (xmx-xmn)/2; var rb: i64 = (zmx-zmn)/2 148 if ra < 1 { return 0 } 149 if rb < 1 { return 0 } 150 fit[0] = ra; fit[1] = rb; fit[2] = xc; fit[3] = zc 151 // ellipse-parameter directions, unit (Q14) plus their true length 152 let ux: *i64 = sys_mmap(nb*8) as *i64 153 let uz: *i64 = sys_mmap(nb*8) as *i64 154 let ul: *i64 = sys_mmap(nb*8) as *i64 155 let best: *i64 = sys_mmap(nb*8) as *i64 156 var i: i64 = 0 157 while i < nb { 158 let dg: i64 = pf_wrap(i*360/nb) 159 let dx: i64 = ra*sinT[pf_wrap(dg+90)]/PF_Q14 160 let dz: i64 = rb*sinT[dg]/PF_Q14 161 var l: i64 = pf_isqrt(dx*dx + dz*dz) 162 if l < 1 { l = 1 } 163 ux[i] = dx*PF_Q14/l; uz[i] = dz*PF_Q14/l; ul[i] = l 164 best[i] = 0-PF_BIG 165 i = i+1 166 } 167 // ★MEAN RADIUS PER BIN, NOT THE MAXIMUM. Taking the max projection in each direction is the section's 168 // SUPPORT FUNCTION, and a support function describes the CONVEX HULL -- every concavity (the spinal 169 // furrow, the groove between the erector columns, the armpit, the popliteal hollow) is erased by 170 // construction. Measured consequence: the convexified prior transferred fine on the mostly-convex FRONT 171 // (detail 348->372) and wrecked the BACK (374->281), because it flattened our back without carrying the 172 // structure that makes a real back busy. Averaging the points that fall in a bin keeps concavities. 173 let bsum: *i64 = sys_mmap(nb*8) as *i64 174 let bcnt: *i64 = sys_mmap(nb*8) as *i64 175 i = 0 176 while i < nb { bsum[i] = 0; bcnt[i] = 0; i = i+1 } 177 k = 0 178 while k < cnt { 179 let j: i64 = idx[k] 180 let vx: i64 = px[j]-xc; let vz: i64 = pz[j]-zc 181 var bi: i64 = 0; var bd: i64 = 0-PF_BIG 182 i = 0 183 while i < nb { 184 let d: i64 = (vx*ux[i] + vz*uz[i])/PF_Q14 185 if d > bd { bd = d; bi = i } 186 i = i+1 187 } 188 bsum[bi] = bsum[bi] + bd; bcnt[bi] = bcnt[bi] + 1 189 if bd > best[bi] { best[bi] = bd } 190 k = k+1 191 } 192 // dimensionless ratio vs the fitted ellipse; empty bins filled from the nearest occupied neighbour 193 i = 0 194 while i < nb { 195 if bcnt[i] < 1 { rat[i] = 0 } else { rat[i] = (bsum[i]/bcnt[i])*1000/ul[i] } 196 i = i+1 197 } 198 var filled: i64 = 0 199 i = 0 200 while i < nb { if rat[i] > 0 { filled = filled+1 } i = i+1 } 201 if filled < nb/2 { return 0 } 202 var pass: i64 = 0 203 while pass < nb { 204 i = 0 205 while i < nb { 206 if rat[i] == 0 { 207 let a: i64 = rat[(i+1)%nb] 208 let b: i64 = rat[(i+nb-1)%nb] 209 if a > 0 { if b > 0 { rat[i] = (a+b)/2 } else { rat[i] = a } } else { if b > 0 { rat[i] = b } } 210 } 211 i = i+1 212 } 213 pass = pass+1 214 } 215 return 1 216} 217 218// ★SAGITTAL SYMMETRISATION for the midline parts (torso, head). A cadaver is not perfectly symmetric and a 219// slice picks up scan noise; a GENERATED body is mirrored about x=0, so an asymmetric prior would apply one 220// side's noise to both. Averaging theta with 180-theta keeps the anatomy (flat back, sternal hollow) and 221// cancels the asymmetry we could not honestly reproduce anyway. Limb profiles are left as measured: their 222// asymmetry (medial vs lateral) is real and the emitter flips the angle for the mirrored side. 223func pf_symmetrize(rat: *i64, nb: i64) -> i64 { 224 let tmp: *i64 = sys_mmap(nb*8) as *i64 225 var i: i64 = 0 226 while i < nb { tmp[i] = rat[i]; i = i+1 } 227 i = 0 228 while i < nb { 229 let m: i64 = (nb/2 - i + nb) % nb 230 rat[i] = (tmp[i] + tmp[m])/2 231 i = i+1 232 } 233 return 0 234} 235 236 237// ★FACTORISE MEASURED STATIONS INTO CONTROL HANDLES -- the Infinigen step we had been skipping. Their part 238// templates carry handles factorised from real reference data; ours were TYPED. Given every measured station 239// of a part, choose the K stations that reconstruct the whole run best: start from the two ends and greedily 240// insert whichever station deviates most from the straight line between its selected neighbours. 241// ★THE POINT: ring density then follows WHERE THE SHAPE CHANGES, instead of being uniform. GX-34 proved a 242// uniform-linear generator scores WORSE than the typed table precisely because the table encoded dense rings 243// at the shoulder and sparse ones down the forearm. Here that density is measured, not authored. 244func pf_factorise(cY: *i64, cRA: *i64, cRB: *i64, cXC: *i64, cZC: *i64, base: i64, n: i64, K: i64, sel: *i64) -> i64 { 245 var i: i64 = 0 246 while i < n { sel[i] = 0; i = i+1 } 247 if n < 2 { if n == 1 { sel[0] = 1 } return n } 248 sel[0] = 1; sel[n-1] = 1 249 var have: i64 = 2 250 while have < K { 251 var bi: i64 = 0-1 252 var be: i64 = 0-1 253 var a: i64 = 0 254 while a < n-1 { 255 if sel[a] == 1 { 256 var b: i64 = a+1 257 var go: i64 = 1 258 while go == 1 { if b >= n-1 { go = 0 } else { if sel[b] == 1 { go = 0 } else { b = b+1 } } } 259 // every unselected station between the selected pair (a,b): error vs the linear reconstruction 260 var m: i64 = a+1 261 while m < b { 262 var w: i64 = 0 263 if cY[base+b] != cY[base+a] { w = (cY[base+m]-cY[base+a])*1000/(cY[base+b]-cY[base+a]) } 264 var e: i64 = 0 265 var d1: i64 = cRA[base+m] - (cRA[base+a] + (cRA[base+b]-cRA[base+a])*w/1000) 266 if d1 < 0 { d1 = 0-d1 } 267 var d2: i64 = cRB[base+m] - (cRB[base+a] + (cRB[base+b]-cRB[base+a])*w/1000) 268 if d2 < 0 { d2 = 0-d2 } 269 var d3: i64 = cXC[base+m] - (cXC[base+a] + (cXC[base+b]-cXC[base+a])*w/1000) 270 if d3 < 0 { d3 = 0-d3 } 271 var d4: i64 = cZC[base+m] - (cZC[base+a] + (cZC[base+b]-cZC[base+a])*w/1000) 272 if d4 < 0 { d4 = 0-d4 } 273 e = d1+d2+d3+d4 274 if e > be { be = e; bi = m } 275 m = m+1 276 } 277 a = b 278 } else { a = a+1 } 279 } 280 if bi < 0 { have = K } else { sel[bi] = 1; have = have+1 } 281 } 282 return have 283} 284// emit one factorised part as canon P/R rows. Midline parts force xoff 0 (a generated body is bilaterally 285// symmetric; the cadaver's own asymmetry is not something we could honestly reproduce anyway). 286func pf_emit_part(buf: *u8, pos: *i64, cY: *i64, cRA: *i64, cRB: *i64, cXC: *i64, cZC: *i64, 287 base: i64, n: i64, sel: *i64, mir: i64, mat: i64, zref: i64) -> i64 { 288 pf_puts(buf, pos, "P " as *u8) 289 pf_putint(buf, pos, mir, 32); pf_putint(buf, pos, 0, 32); pf_putint(buf, pos, 0, 32) 290 pf_putint(buf, pos, 0, 32); pf_putint(buf, pos, 0, 32); pf_putint(buf, pos, mat, 10) 291 var i: i64 = 0 292 while i < n { 293 if sel[i] == 1 { 294 var xo: i64 = cXC[base+i] 295 if mir == 0 { xo = 0 } 296 pf_puts(buf, pos, "R " as *u8) 297 pf_putint(buf, pos, cY[base+i], 32) 298 pf_putint(buf, pos, xo, 32) 299 // ★z is measured ABSOLUTE to the oracle's own origin, so every part came out fitted at its own 300 // depth and the parts stopped agreeing with each other -- measured as the side silhouette 301 // collapsing 813 -> 678 while the front hit its best ever 886. One global reference subtracted 302 // keeps the RELATIVE depths (arms behind the chest plane is real anatomy) and removes the shift. 303 pf_putint(buf, pos, cZC[base+i]-zref, 32) 304 pf_putint(buf, pos, cRA[base+i], 32) 305 pf_putint(buf, pos, cRB[base+i], 10) 306 } 307 i = i+1 308 } 309 return 0 310} 311 312// ANATOMICAL LANDMARKS -- the registration primitive. kind 1 = height of MAX radius in the band, 0 = MIN. 313func pf_landmark(cY: *i64, cR: *i64, base: i64, n: i64, lo: i64, hi: i64, kind: i64) -> i64 { 314 var bi: i64 = 0-1 315 var bv: i64 = 0 316 var i: i64 = 0 317 while i < n { 318 let y: i64 = cY[base+i] 319 if y >= lo { if y <= hi { 320 let v: i64 = cR[base+i] 321 if bi < 0 { bi = i; bv = v } else { 322 if kind == 1 { if v > bv { bv = v; bi = i } } else { if v < bv { bv = v; bi = i } } 323 } 324 }} 325 i = i+1 326 } 327 if bi < 0 { return 0 } 328 return cY[base+bi] 329} 330 331func pf_provenance_run(argc: i64, argv: *i64) -> i64 { 332 if argc < 3 { pf_hw("{\x22error\x22:\x22usage: nx_profile_fit <oracle.nxmesh> <out.dat> [step_permil]\x22}\n" as *u8); return 2 } 333 let orap: *u8 = argv[1] as *u8 334 // Source paths are emitted inside comment rows; reject controls before any file read or output. 335 var sourceByte: i64 = 0 336 while orap[sourceByte] != (0 as u8) { 337 let ch: i64 = orap[sourceByte] as i64 338 if ch < 32 { pf_hw("source path contains control bytes\n" as *u8); return 2 } 339 if ch == 127 { pf_hw("source path contains control bytes\n" as *u8); return 2 } 340 sourceByte = sourceByte + 1 341 } 342 let outp: *u8 = argv[2] as *u8 343 var STEP: i64 = 6 344 if argc > 3 { STEP = pf_satoi(argv[3] as *u8) } 345 if STEP < 2 { STEP = 2 } 346 // ★ORGAN MODE (argv[5]). The band table is BODY anatomy expressed in per-mille of the oracle's OWN AABB 347 // height, so aiming this organ at a SINGLE-ORGAN oracle silently misclassifies it: for a skull the 348 // mandible and maxilla fall in the LEG band, the midface in TORSO, and only the top 148 permil reads as 349 // HEAD. Worse, the two-fused-legs recovery fires whenever nrun==1 inside the leg band and SAWS THE SKULL 350 // DOWN ITS MIDLINE to fit the +x half as a limb. That is measured, not feared: debt 1785438981 records 351 // that the 156 rows in profile_human.dat are body sections, and feeding them to a skull lifted the front 352 // (+5 headline) while DEGRADING side_iou 559->531 and quarter_iou 665->627 -- right mechanism, wrong data. 353 // Declaring the part makes every station belong to it. ORGANON==0 leaves the body path byte-identical. 354 var ORGAN: i64 = 0-1 355 var ORGANON: i64 = 0 356 // ★ORGANON KEYED ON THE VALUE, NOT ON argc (2026-08-23). It was `if argc > 5 { ORGANON = 1; ... }`, 357 // so ANY later positional argument -- PIDHI at argv[8], and the new NB at argv[9] -- SILENTLY forced 358 // single-organ mode: every station collapsed into one part, limb detection was disabled, and the 359 // landmark table came back with wrist/elbow/trochanter/knee/calf/ankle ALL ZERO. Measured the first 360 // time NB was passed, and it would have mis-measured the prior while looking like it worked. 361 // ★A POSITIONAL CONTRACT THAT BREAKS WHEN IT IS EXTENDED IS A TRAP FOR EVERY FUTURE ARGUMENT -- 362 // keying on the VALUE makes it extensible by construction. -1 (the default) = whole-body mode. 363 if argc > 5 { ORGAN = pf_satoi(argv[5] as *u8); if ORGAN >= 0 { ORGANON = 1 } } 364 // the head band spills a duplicate torso row where the two overlap; one organ has no such overlap 365 var spillHi: i64 = PF_TORSO_HI 366 if ORGANON == 1 { spillHi = 0-1 } 367 // ★TARGET Y-BAND (argv[6],argv[7], per-mille of STATURE). Identity by default, so nothing changes for a 368 // whole-body oracle. See the frame-mapping note in the station loop for why a single-organ oracle needs it. 369 var YLO: i64 = 0 370 var YHI: i64 = 1000 371 if argc > 7 { YLO = pf_satoi(argv[6] as *u8); YHI = pf_satoi(argv[7] as *u8) } 372 if YHI <= YLO { YLO = 0; YHI = 1000 } 373 // ★HIGHEST CANON PART ID to also emit each row under (argv[8]). Default -1 = emit for `part` only, so every 374 // existing caller is byte-identical. See the emission site for the measured reason this exists. 375 var PIDHI: i64 = 0-1 376 if argc > 8 { PIDHI = pf_satoi(argv[8] as *u8) } 377 // ★ANGULAR BIN COUNT (argv[9]) -- THE HIGH-FREQUENCY DETAIL CEILING OF THE HUMAN GENERATOR, made 378 // liftable. It was PF_NB=48, a PICKED constant with no override, while the oracle holds up to 379 // PF_MAXPT=4096 points per section and the consumer (nx_body_gen BG_NBMAX) can already hold 96. 380 // We were binning measured anatomy to 48 and discarding the rest. Default is PF_NB so every existing 381 // caller is BYTE-IDENTICAL by construction; raising it is a DATA decision, not a taste decision. 382 // ⚠The honest upper bound is the DATA's own support: a bin whose points are fewer than ~1 is a hole 383 // the neighbour-fill has to invent, so nb must not exceed the smallest admitted section's point count. 384 // That floor is MEASURED and ANNOUNCED below as nb_supported rather than assumed here. 385 var NB: i64 = PF_NB 386 if argc > 9 { NB = pf_satoi(argv[9] as *u8) } 387 if NB < 4 { NB = 4 } 388 let sinT: *i64 = sys_mmap(400*8) as *i64 389 pf_sin_fill(sinT) 390 391 let ln: *i64 = sys_mmap(16) as *i64 392 let mb: *u8 = sys_read_file(orap, ln) 393 if (mb as i64) == 0 { pf_hw("{\x22error\x22:\x22cannot read oracle mesh\x22}\n" as *u8); return 3 } 394 let nl: i64 = pf_rdbits(mb, 8) 395 let nt: i64 = pf_rdbits(mb, 12) 396 let tb: i64 = 16 + nl*24 397 398 // pass 0: scale-invariant working precision (a metre-authored mesh must not collapse to zero) 399 var q0mn: i64 = PF_BIG; var q0mx: i64 = 0-PF_BIG 400 var t: i64 = 0 401 while t < nt { 402 let o0: i64 = tb + t*84 403 var c0: i64 = 0 404 while c0 < 3 { let vq: i64 = pf_f32mul(mb, o0 + c0*4, PF_POSQ0); if vq < q0mn { q0mn = vq } if vq > q0mx { q0mx = vq } c0 = c0+1 } 405 t = t+1 406 } 407 var span0: i64 = q0mx - q0mn 408 if span0 < 1 { span0 = 1 } 409 var posq: i64 = PF_POSQ0 * PF_TARGET / span0 410 if posq < 1 { posq = 1 } 411 412 // pass 1: AABB -> stature and body midline 413 var mnx: i64 = PF_BIG; var mny: i64 = PF_BIG; var mnz: i64 = PF_BIG 414 var mxx: i64 = 0-PF_BIG; var mxy: i64 = 0-PF_BIG; var mxz: i64 = 0-PF_BIG 415 t = 0 416 while t < nt { 417 var v: i64 = 0 418 while v < 3 { 419 let o: i64 = tb + t*84 + v*12 420 let x: i64 = pf_f32mul(mb,o,posq); let y: i64 = pf_f32mul(mb,o+4,posq); let z: i64 = pf_f32mul(mb,o+8,posq) 421 if x<mnx {mnx=x} if x>mxx {mxx=x} if y<mny {mny=y} if y>mxy {mxy=y} if z<mnz {mnz=z} if z>mxz {mxz=z} 422 v = v+1 423 } 424 t = t+1 425 } 426 var stature: i64 = mxy - mny 427 if stature < 1 { stature = 1 } 428 let cxmid: i64 = (mnx+mxx)/2 429 let nst: i64 = 1000/STEP + 1 430 if nst > PF_MAXST { pf_hw("{\x22error\x22:\x22step too small for station table\x22}\n" as *u8); return 4 } 431 432 // pass 2: slice. ONE pass over triangles; each triangle contributes to the few stations it spans. 433 let spx: *i64 = sys_mmap(PF_MAXST*PF_MAXPT*8) as *i64 434 let spz: *i64 = sys_mmap(PF_MAXST*PF_MAXPT*8) as *i64 435 let scn: *i64 = sys_mmap(PF_MAXST*8) as *i64 436 var s: i64 = 0 437 while s < nst { scn[s] = 0; s = s+1 } 438 let vx: *i64 = sys_mmap(3*8) as *i64 439 let vy: *i64 = sys_mmap(3*8) as *i64 440 let vz: *i64 = sys_mmap(3*8) as *i64 441 t = 0 442 while t < nt { 443 var v: i64 = 0 444 var ymn: i64 = PF_BIG; var ymx: i64 = 0-PF_BIG 445 while v < 3 { 446 let o: i64 = tb + t*84 + v*12 447 vx[v] = pf_f32mul(mb,o,posq); vy[v] = pf_f32mul(mb,o+4,posq); vz[v] = pf_f32mul(mb,o+8,posq) 448 if vy[v] < ymn { ymn = vy[v] } 449 if vy[v] > ymx { ymx = vy[v] } 450 v = v+1 451 } 452 var s0: i64 = (ymn - mny)*1000/stature/STEP 453 var s1: i64 = (ymx - mny)*1000/stature/STEP + 1 454 if s0 < 0 { s0 = 0 } 455 if s1 > nst-1 { s1 = nst-1 } 456 var st: i64 = s0 457 while st <= s1 { 458 let Y: i64 = mny + st*STEP*stature/1000 459 var e: i64 = 0 460 while e < 3 { 461 let a: i64 = e; let b: i64 = (e+1)%3 462 var lo: i64 = a; var hi: i64 = b 463 if vy[a] > vy[b] { lo = b; hi = a } 464 if vy[lo] <= Y { if vy[hi] > Y { 465 var den: i64 = vy[hi]-vy[lo] 466 if den < 1 { den = 1 } 467 let f: i64 = (Y - vy[lo])*1000/den 468 let ix: i64 = vx[lo] + (vx[hi]-vx[lo])*f/1000 469 let iz: i64 = vz[lo] + (vz[hi]-vz[lo])*f/1000 470 let c: i64 = scn[st] 471 if c < PF_MAXPT { spx[st*PF_MAXPT+c] = ix; spz[st*PF_MAXPT+c] = iz; scn[st] = c+1 } 472 }} 473 e = e+1 474 } 475 st = st+1 476 } 477 t = t+1 478 } 479 480 // pass 3: per station, cluster on x, assign clusters to canon parts, fit each section 481 let obuf: *u8 = sys_mmap(PF_OUTCAP) 482 let opos: *i64 = sys_mmap(16) as *i64 483 opos[0] = 0 484 pf_puts(obuf, opos, "; Nishi measured cross-section profiles; dimensionless ellipse residuals. 485" as *u8) 486 pf_puts(obuf, opos, "; Source mesh: " as *u8); pf_puts(obuf, opos, orap) 487 pf_puts(obuf, opos, " 488; Preserve the source asset provenance and rights receipt; no anatomical or licensing identity inferred. 489" as *u8) 490 pf_puts(obuf, opos, "; S <part> <ymil> <ra_permil> <rb_permil> <ratio x N, theta 0=+X lateral, 90=+Z front>\n" as *u8) 491 pf_puts(obuf, opos, "V 2\n; Requires profile-contract-v2-aware consumer for qualification; S rows are retained measurements.\n; Q y part_a part_b reason runs points; reason1=projected-union; next=semantic region mapping.\n" as *u8) 492 // the bin count travels WITH the data, so the consumer can never assume a different resolution 493 pf_puts(obuf, opos, "N " as *u8) 494 pf_putint(obuf, opos, NB, 10) 495 496 let hist: *i64 = sys_mmap(PF_XBINS*8) as *i64 497 let runLo: *i64 = sys_mmap(PF_MAXRUN*8) as *i64 498 let runHi: *i64 = sys_mmap(PF_MAXRUN*8) as *i64 499 let sel: *i64 = sys_mmap(PF_MAXPT*8) as *i64 500 let fit: *i64 = sys_mmap(8*8) as *i64 501 let rat: *i64 = sys_mmap(NB*8) as *i64 502 var rows: i64 = 0 503 var devsum: i64 = 0; var devcnt: i64 = 0 504 // measured control-handle tables, per part (the raw material the canon is factorised from) 505 let cN: *i64 = sys_mmap(PF_MAXPARTS*8) as *i64 506 let cY: *i64 = sys_mmap(PF_MAXPARTS*PF_MAXST*8) as *i64 507 let cRA: *i64 = sys_mmap(PF_MAXPARTS*PF_MAXST*8) as *i64 508 let cRB: *i64 = sys_mmap(PF_MAXPARTS*PF_MAXST*8) as *i64 509 let cXC: *i64 = sys_mmap(PF_MAXPARTS*PF_MAXST*8) as *i64 510 let cZC: *i64 = sys_mmap(PF_MAXPARTS*PF_MAXST*8) as *i64 511 var pz0: i64 = 0 512 while pz0 < PF_MAXPARTS { cN[pz0] = 0; pz0 = pz0+1 } 513 s = 0 514 while s < nst { 515 let ymil: i64 = s*STEP 516 // ★FRAME MAPPING. ymil is per-mille of the ORACLE'S OWN height, but the consumer looks the prior up in 517 // per-mille of STATURE (nx_body_gen: ymq = yri/1000, the canon's own R-row units). For a whole-body 518 // oracle those two frames coincide, which is why nothing needed this before. For a SINGLE-ORGAN oracle 519 // they do NOT: nx_skullgen emits R rows spanning y 872..1000, so a skull profile written at 0..1000 520 // would be queried ONLY over its top 128 per-mille -- every part of the skull modulated by the CROWN's 521 // cross-section, and silently, because the rows exist and the lookup succeeds. Map the oracle's own 522 // extent onto the band the canon actually occupies. 523 var yout: i64 = ymil 524 if ORGANON == 1 { yout = YLO + ymil*(YHI-YLO)/1000 } 525 let cnt: i64 = scn[s] 526 if cnt >= NB { 527 var xmn: i64 = PF_BIG; var xmx: i64 = 0-PF_BIG 528 var k: i64 = 0 529 while k < cnt { 530 let x: i64 = spx[s*PF_MAXPT+k] 531 if x < xmn { xmn = x } 532 if x > xmx { xmx = x } 533 k = k+1 534 } 535 var xsp: i64 = xmx - xmn 536 if xsp < 1 { xsp = 1 } 537 var h: i64 = 0 538 while h < PF_XBINS { hist[h] = 0; h = h+1 } 539 if section_project_x_pairs(spx, s*PF_MAXPT, cnt, xmn, xsp, hist, PF_XBINS) != 0 { 540 pf_hw("{\x22error\x22:\x22incomplete cross-section segment\x22}\n" as *u8) 541 return 5 542 } 543 // contiguous runs of occupied bins, split where PF_GAP or more bins are empty 544 var nrun: i64 = 0 545 var inrun: i64 = 0 546 var gap: i64 = 0 547 h = 0 548 while h < PF_XBINS { 549 if hist[h] > 0 { 550 if inrun == 0 { if nrun < PF_MAXRUN { runLo[nrun] = h; runHi[nrun] = h; nrun = nrun+1; inrun = 1 } } 551 else { runHi[nrun-1] = h } 552 gap = 0 553 } else { 554 if inrun == 1 { gap = gap+1; if gap >= PF_GAP { inrun = 0 } else { runHi[nrun-1] = h } } 555 } 556 h = h+1 557 } 558 // Record ambiguous assignment while retaining every measured S row. 559 // These are existing body bands, not a station-specific exception. 560 if ORGANON == 0 { if nrun < 2 { if ymil >= PF_ARM_LO { if ymil <= PF_ARM_HI { 561 pf_puts(obuf, opos, "Q " as *u8) 562 pf_putint(obuf, opos, yout, 32) 563 pf_putint(obuf, opos, PF_PTORSO, 32) 564 pf_putint(obuf, opos, PF_PARM, 32) 565 pf_putint(obuf, opos, 1, 32) 566 pf_putint(obuf, opos, nrun, 32) 567 pf_putint(obuf, opos, cnt, 10) 568 }}}} 569 // Assign the centre and outer projected runs; Q records qualify that assignment. 570 var ic: i64 = 0-1; var io: i64 = 0-1 571 var bestc: i64 = PF_BIG; var besto: i64 = 0-1 572 var r: i64 = 0 573 while r < nrun { 574 let rc: i64 = xmn + (runLo[r]+runHi[r])*xsp/(2*(PF_XBINS-1)) 575 var dc: i64 = rc - cxmid 576 if dc < 0 { dc = 0-dc } 577 if dc < bestc { bestc = dc; ic = r } 578 if rc > besto { besto = rc; io = r } 579 r = r+1 580 } 581 // ---- centre run -> torso and/or head ---- 582 if ic >= 0 { 583 let lo: i64 = xmn + runLo[ic]*xsp/(PF_XBINS-1) - 1 584 let hi: i64 = xmn + runHi[ic]*xsp/(PF_XBINS-1) + 1 585 var nsel: i64 = 0 586 k = 0 587 while k < cnt { 588 let x: i64 = spx[s*PF_MAXPT+k] 589 if x >= lo { if x <= hi { if nsel < PF_MAXPT { sel[nsel] = s*PF_MAXPT+k; nsel = nsel+1 } } } 590 k = k+1 591 } 592 if pf_fit_section(spx, spz, sel, nsel, sinT, fit, rat, NB) == 1 { 593 pf_symmetrize(rat, NB) 594 var part: i64 = 0-1 595 if ymil >= PF_TORSO_LO { if ymil <= PF_TORSO_HI { part = PF_PTORSO } } 596 if ymil >= PF_HEAD_LO { part = PF_PHEAD } 597 if ORGANON == 1 { part = ORGAN } 598 if part >= 0 { 599 // ★DO NOT RECORD A HANDLE WHERE THE SECTION IS NOT MEASURABLE. Through the arm band the 600 // arms touch the torso, so the x-clustering returns ONE run and the "torso" section 601 // silently includes both arms -- measured as ra jumping 88 -> 148 at shoulder height. 602 // A handle fitted there is an artifact, and the greedy factoriser will faithfully 603 // select it BECAUSE it is the largest change. Skip it and let the spline interpolate 604 // across the gap: an honest hole beats a confident wrong number. 605 var meas: i64 = 1 606 if nrun < 2 { if ymil >= PF_ARM_LO { if ymil <= PF_ARM_HI { meas = 0 } } } 607 if ORGANON == 1 { meas = 1 } 608 if meas == 1 { if cN[part] < PF_MAXST { 609 let ci: i64 = part*PF_MAXST + cN[part] 610 cY[ci]=yout; cRA[ci]=fit[0]*1000/stature; cRB[ci]=fit[1]*1000/stature 611 cXC[ci]=fit[2]*1000/stature; cZC[ci]=fit[3]*1000/stature 612 cN[part] = cN[part]+1 613 }} 614 // ★★★EMIT UNDER EVERY CANON PART THAT SPANS THIS HEIGHT. MEASURED 2026-07-30: with rows for 615 // part 0 ONLY, the vault moved at full strength while supraorbital and zygomatic -- which 616 // both span canon y958 -- had no rows for their id, returned 1000, and STOOD STILL. 617 // nx_meshprofile caught it as a NEW radius jump at station 671 that PROF=0 and PROF=250 618 // do not have. A per-part EDGE feather cannot fix that: y958 is the vault's INTERIOR, 619 // exactly where an edge rule is designed not to act. LAW: a prior on ONE part but not the 620 // parts it OVERLAPS steps worst in that part's interior. Correspondence stays honest -- 621 // the rows span the whole canon band, so part p reads the section measured at p's own y. 622 var pend: i64 = part 623 if PIDHI > part { pend = PIDHI } 624 var pid: i64 = part 625 while pid <= pend { 626 pf_puts(obuf, opos, "S " as *u8) 627 pf_putint(obuf, opos, pid, 32) 628 pf_putint(obuf, opos, yout, 32) 629 pf_putint(obuf, opos, fit[0]*1000/stature, 32) 630 pf_putint(obuf, opos, fit[1]*1000/stature, 32) 631 var i2: i64 = 0 632 while i2 < NB { 633 var sepc: i64 = 32 634 if i2 == NB-1 { sepc = 10 } 635 pf_putint(obuf, opos, rat[i2], sepc) 636 var d2: i64 = rat[i2]-1000 637 if d2 < 0 { d2 = 0-d2 } 638 devsum = devsum + d2; devcnt = devcnt + 1 639 i2 = i2+1 640 } 641 rows = rows+1 642 // the head band also feeds the torso tube where they overlap, so the neck keeps a profile 643 if part == PF_PHEAD { if ymil <= spillHi { 644 pf_puts(obuf, opos, "S " as *u8) 645 pf_putint(obuf, opos, PF_PTORSO, 32) 646 pf_putint(obuf, opos, ymil, 32) 647 pf_putint(obuf, opos, fit[0]*1000/stature, 32) 648 pf_putint(obuf, opos, fit[1]*1000/stature, 32) 649 i2 = 0 650 while i2 < NB { 651 var sepd: i64 = 32 652 if i2 == NB-1 { sepd = 10 } 653 pf_putint(obuf, opos, rat[i2], sepd) 654 i2 = i2+1 655 } 656 rows = rows+1 657 }} 658 pid = pid + 1 659 } 660 } 661 } 662 } 663 // ---- outermost run -> arm (above the crotch) or leg (below it) ---- 664 // TWO FUSED LEGS ARE A KNOWN GEOMETRY, NOT AN UNMEASURABLE ONE. Below mid-thigh the legs 665 // converge, the x-clustering returns ONE run, and the not-measurable guard refused to record 666 // anything -- which is why leg stations stopped at 282 permil and calf/ankle landmarks read 667 // zero. An arm fused to a torso is genuinely unrecoverable; two legs are not, because we know 668 // the seam is the midline. Split the single run at its x-midpoint and take the +x half. 669 var io2: i64 = io 670 var forceLo: i64 = 0 671 var forceHi: i64 = 0 672 var forced: i64 = 0 673 if nrun == 1 { if ymil <= PF_LEG_HI { if ymil >= PF_LEG_LO { 674 let rlo: i64 = xmn + runLo[0]*xsp/(PF_XBINS-1) 675 let rhi: i64 = xmn + runHi[0]*xsp/(PF_XBINS-1) 676 forceLo = (rlo+rhi)/2 677 forceHi = rhi + 1 678 forced = 1 679 io2 = 0 680 }}} 681 if forced == 1 { io = io2 } 682 if io >= 0 { if io != ic { forced = forced } else { if forced == 0 { io = 0-1 } } 683 if io >= 0 { 684 var lo2: i64 = xmn + runLo[io]*xsp/(PF_XBINS-1) - 1 685 var hi2: i64 = xmn + runHi[io]*xsp/(PF_XBINS-1) + 1 686 if forced == 1 { lo2 = forceLo; hi2 = forceHi } 687 var nsel2: i64 = 0 688 k = 0 689 while k < cnt { 690 let x: i64 = spx[s*PF_MAXPT+k] 691 if x >= lo2 { if x <= hi2 { if nsel2 < PF_MAXPT { sel[nsel2] = s*PF_MAXPT+k; nsel2 = nsel2+1 } } } 692 k = k+1 693 } 694 if pf_fit_section(spx, spz, sel, nsel2, sinT, fit, rat, NB) == 1 { 695 var part2: i64 = 0-1 696 if ymil >= PF_ARM_LO { if ymil <= PF_ARM_HI { part2 = PF_PARM } } 697 if ymil <= PF_LEG_HI { if ymil >= PF_LEG_LO { part2 = PF_PLEG } else { part2 = 0-1 } } 698 // a single-organ oracle has no limbs: the outer run IS the organ, already taken above 699 if ORGANON == 1 { part2 = 0-1 } 700 if part2 >= 0 { 701 if cN[part2] < PF_MAXST { 702 let c2: i64 = part2*PF_MAXST + cN[part2] 703 cY[c2]=ymil; cRA[c2]=fit[0]*1000/stature; cRB[c2]=fit[1]*1000/stature 704 cXC[c2]=fit[2]*1000/stature; cZC[c2]=fit[3]*1000/stature 705 cN[part2] = cN[part2]+1 706 } 707 pf_puts(obuf, opos, "S " as *u8) 708 pf_putint(obuf, opos, part2, 32) 709 pf_putint(obuf, opos, ymil, 32) 710 pf_putint(obuf, opos, fit[0]*1000/stature, 32) 711 pf_putint(obuf, opos, fit[1]*1000/stature, 32) 712 var i3: i64 = 0 713 while i3 < NB { 714 var sepe: i64 = 32 715 if i3 == NB-1 { sepe = 10 } 716 pf_putint(obuf, opos, rat[i3], sepe) 717 var d3: i64 = rat[i3]-1000 718 if d3 < 0 { d3 = 0-d3 } 719 devsum = devsum + d3; devcnt = devcnt + 1 720 i3 = i3+1 721 } 722 rows = rows+1 723 } 724 } 725 }} 726 } 727 s = s+1 728 } 729 730 let fd: i64 = sys_openat_wr(outp, MODE_0644) 731 sys_write(fd, obuf, opos[0]) 732 sys_close(fd) 733 734 // ★FACTORISED CANON (argv[4]): control handles derived from the reference, not typed. This is the 735 // Infinigen construction end to end -- measure a real reference, factorise it into a small set of 736 // handles, and let the genome scale them. The emitter is UNCHANGED: these are ordinary canon rows. 737 var kept: i64 = 0 738 if argc > 4 { 739 let kbuf: *u8 = sys_mmap(PF_OUTCAP) 740 let kpos: *i64 = sys_mmap(16) as *i64 741 kpos[0] = 0 742 pf_puts(kbuf, kpos, "# Canon factorised from measured reference sections by nx_profile_fit. 743# Source mesh: " as *u8) 744 pf_puts(kbuf, kpos, orap) 745 pf_puts(kbuf, kpos, " 746# Preserve the source asset provenance and rights receipt; no anatomical or licensing identity inferred. 747" as *u8) 748 let sel: *i64 = sys_mmap(PF_MAXST*8) as *i64 749 // global depth reference = the torso's middle handle 750 var zref: i64 = 0 751 if cN[PF_PTORSO] > 0 { zref = cZC[PF_PTORSO*PF_MAXST + cN[PF_PTORSO]/2] } 752 var pp: i64 = 0 753 while pp < PF_MAXPARTS { 754 if cN[pp] > 2 { 755 var mir: i64 = 0 756 var mat: i64 = 0 757 if pp == PF_PARM { mir = 1 } 758 if pp == PF_PLEG { mir = 1 } 759 if pp == PF_PHEAD { mat = 5 } 760 let hv: i64 = pf_factorise(cY,cRA,cRB,cXC,cZC, pp*PF_MAXST, cN[pp], PF_MAXK, sel) 761 pf_emit_part(kbuf,kpos, cY,cRA,cRB,cXC,cZC, pp*PF_MAXST, cN[pp], sel, mir, mat, zref) 762 kept = kept + hv 763 } 764 pp = pp+1 765 } 766 let kfd: i64 = sys_openat_wr(argv[4] as *u8, 420) 767 sys_write(kfd, kbuf, kpos[0]) 768 sys_close(kfd) 769 } 770 771 if devcnt < 1 { devcnt = 1 } 772 pf_hw("{\x22organ\x22:\x22nx_profile_fit\x22,\x22tris\x22:" as *u8); pf_pn(nt) 773 pf_hw(",\x22stations\x22:" as *u8); pf_pn(nst) 774 pf_hw(",\x22rows\x22:" as *u8); pf_pn(rows) 775 pf_hw(",\x22bytes\x22:" as *u8); pf_pn(opos[0]) 776 // ★NON-VACUITY: how far a real human section actually is from the ellipse the emitter used to assume. 777 // Near zero here would mean the whole rung is pointless -- publish it either way. 778 pf_hw(",\x22mean_abs_dev_permil\x22:" as *u8); pf_pn(devsum/devcnt) 779 // landmark block: measured on THIS mesh in per-mille of its OWN stature, so two meshes become comparable. 780 // Five measured-transfer attempts failed because the reference anatomy at a coordinate is not OUR anatomy 781 // at that coordinate; these points ARE that correspondence, and every one is an extremum of the per-station 782 // series this organ already measured and was discarding. 783 pf_hw(" lm_acromion=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PTORSO*PF_MAXST, cN[PF_PTORSO], 760, 908, 1)) 784 pf_hw(" lm_waist=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PTORSO*PF_MAXST, cN[PF_PTORSO], 500, 660, 0)) 785 pf_hw(" lm_iliac=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PTORSO*PF_MAXST, cN[PF_PTORSO], 430, 520, 1)) 786 pf_hw(" lm_neck=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PTORSO*PF_MAXST, cN[PF_PTORSO], 860, 940, 0)) 787 pf_hw(" lm_wrist=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PARM*PF_MAXST, cN[PF_PARM], 470, 560, 0)) 788 pf_hw(" lm_elbow=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PARM*PF_MAXST, cN[PF_PARM], 580, 700, 0)) 789 pf_hw(" lm_trochanter=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PLEG*PF_MAXST, cN[PF_PLEG], 380, 452, 1)) 790 pf_hw(" lm_knee=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PLEG*PF_MAXST, cN[PF_PLEG], 170, 300, 0)) 791 pf_hw(" lm_calf=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PLEG*PF_MAXST, cN[PF_PLEG], 110, 220, 1)) 792 pf_hw(" lm_ankle=" as *u8); pf_pn(pf_landmark(cY,cRA, PF_PLEG*PF_MAXST, cN[PF_PLEG], 60, 120, 0)) 793 pf_hw(",\x22note\x22:\x22dimensionless shape prior only; sizes stay procedural\x22}\n" as *u8) 794 return 0 795} 796 797// Candidate-only native harness. The canonical delta excludes this wrapper and function rename. 798func main(argc: i64, argv: *i64) -> i64 { 799 if argc != 1 { return pf_provenance_run(argc, argv) } 800 let args: *i64 = sys_mmap(3*8) as *i64 801 args[0] = "nx_profile_fit_provenance_t319" as i64 802 args[2] = "/tmp/nx_profile_path_guard_must_not_write.dat" as i64 803 args[1] = "source\nN 8\nS 0 1 1 1" as i64 804 if pf_provenance_run(3, args) != 2 { return 21 } 805 args[1] = "source\rN 8" as i64 806 if pf_provenance_run(3, args) != 2 { return 22 } 807 args[1] = "source\tN 8" as i64 808 if pf_provenance_run(3, args) != 2 { return 23 } 809 args[1] = "source\x7fN 8" as i64 810 if pf_provenance_run(3, args) != 2 { return 24 } 811 pf_hw("native provenance guard PASS 4/4: LF CR TAB DEL rejected by fitter before file read\n" as *u8) 812 return 0 813}