omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tests / cabi / gate.om
| 1 | note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 2 | note omega-bridge cabi-1 gate, a seeded Omega driver (fork, pipefds, execprog and waitpid through tests/cabi/proc.om). |
| 3 | note Build: cat tests/cabi/proc.om tests/cabi/gate.om | "$OMEGA_SEEDED_OMC" > build/cabi-gate |
| 4 | note Run from the checkout root after tools/build.sh, with OMEGA_SEEDED_OMC set to the e5b32567 omc. |
| 5 | note ORACLE tools, test-only and never shipped: /usr/bin/cc, /usr/bin/nm, /usr/bin/readelf, /usr/bin/sha256sum, tests/cabi/caller.c. |
| 6 | global CbOm uchar 1024 |
| 7 | global CbOn ulong 1 |
| 8 | note CbExp is the exit status the next cb_bridge run must return; unsized views take two of the six parameter slots. |
| 9 | global CbExp ulong 1 |
| 10 | text CbSeedK "OMEGA_SEEDED_OMC=" |
| 11 | text CbNo "NOT_RUN: set OMEGA_SEEDED_OMC (omega-mv e5b32567 omc), run tools/build.sh, and start from the omega-bridge checkout root\n" |
| 12 | text CbFailP "CABI GATE FAIL: " |
| 13 | text CbNl "\n" |
| 14 | text CbPass "OMEGA-BRIDGE CABI GATE PASS\n" |
| 15 | text CbToc "src/toc.om" |
| 16 | text CbBr "build/bridge" |
| 17 | text CbDir "build/cabi" |
| 18 | text CbDa "build/cabi/ma" |
| 19 | text CbDb "build/cabi/mb" |
| 20 | text CbDc "build/cabi/mc" |
| 21 | text CbFix "tests/cabi/fixture.om" |
| 22 | text CbExtS "tests/cabi/ext.om" |
| 23 | text CbCall "tests/cabi/caller.c" |
| 24 | text CbGc "tests/cabi/golden/libombrfx.c" |
| 25 | text CbGh "tests/cabi/golden/ombrfx.h" |
| 26 | text CbGm "tests/cabi/golden/libombrfx.map" |
| 27 | text CbG1 "tests/cabi/golden/nvmlDeviceGetCount_v2.c" |
| 28 | text CbG2 "tests/cabi/golden/nvmlDeviceGetName.c" |
| 29 | text CbG3 "tests/cabi/golden/nvmlErrorString.c" |
| 30 | text CbOutC "build/cabi/libombrfx.c" |
| 31 | text CbOutH "build/cabi/ombrfx.h" |
| 32 | text CbOutM "build/cabi/libombrfx.map" |
| 33 | text CbAgain "build/cabi/again.c" |
| 34 | text CbExtC "build/cabi/ext.c" |
| 35 | text CbExtH "build/cabi/ext.h" |
| 36 | text CbSo "build/cabi/libombrfx.so.1" |
| 37 | text CbNm "build/cabi/nm.txt" |
| 38 | text CbRe "build/cabi/readelf.txt" |
| 39 | text CbHash "build/cabi/hash" |
| 40 | text CbRef "build/cabi/refuse.om" |
| 41 | text CbRefO "build/cabi/refuse.out" |
| 42 | text CbDin "build/cabi/direct.in" |
| 43 | text CbDout "build/cabi/direct.out" |
| 44 | text CbDsrc "build/cabi/direct.om" |
| 45 | text CbImp "build/cabi/imp.om" |
| 46 | text CbImpC "build/cabi/imp.c" |
| 47 | text CbImpO "build/cabi/imp.o" |
| 48 | text CbImpL "build/cabi/imp.log" |
| 49 | text CbSoN "/libombrfx.so.1" |
| 50 | text CbCN "/libombrfx.c" |
| 51 | text CbLogN "/cc.out" |
| 52 | text CbExN "/caller" |
| 53 | text CbOutN "/caller.out" |
| 54 | text CbLc "lib-c" |
| 55 | text CbLh "lib-h" |
| 56 | text CbLm "lib-map" |
| 57 | text CbC "c" |
| 58 | text CbH "h" |
| 59 | text CbEnv "/usr/bin/env" |
| 60 | text CbPath "PATH=/usr/bin:/bin" |
| 61 | text CbSh "/bin/sh" |
| 62 | text CbWrap "tools/bridge-seeded" |
| 63 | text CbSha "/usr/bin/sha256sum" |
| 64 | text CbCc "/usr/bin/cc" |
| 65 | text CbNmT "/usr/bin/nm" |
| 66 | text CbRel "/usr/bin/readelf" |
| 67 | text CbStd "-std=gnu11" |
| 68 | text CbO2 "-O2" |
| 69 | text CbPic "-fPIC" |
| 70 | text CbWall "-Wall" |
| 71 | text CbWext "-Wextra" |
| 72 | text CbWerr "-Werror" |
| 73 | text CbShare "-shared" |
| 74 | text CbCo "-c" |
| 75 | text CbInc "-include" |
| 76 | text CbStdi "stdint.h" |
| 77 | text CbIdir "-Ibuild/cabi" |
| 78 | text CbSoname "-Wl,-soname,libombrfx.so.1" |
| 79 | text CbVers "-Wl,--version-script=build/cabi/libombrfx.map" |
| 80 | text CbDefs "-Wl,-z,defs" |
| 81 | text CbRpath "-Wl,-rpath,$ORIGIN" |
| 82 | text CbDo "-o" |
| 83 | text CbPth "-lpthread" |
| 84 | text CbDyn "-D" |
| 85 | text CbDef "--defined-only" |
| 86 | text CbDd "-d" |
| 87 | text CbPa "/* GENERATED by omega-bridge cabi-1 from src/toc.om SHA256 " |
| 88 | text CbPb "; source SHA256 " |
| 89 | text CbPc ". */\n" |
| 90 | text CbClose "\n}\n" |
| 91 | text CbGen "GENERATED" |
| 92 | text CbErrW "error " |
| 93 | text CbT " T " |
| 94 | text CbOmega "omega_" |
| 95 | text CbSonam "Library soname: [libombrfx.so.1]" |
| 96 | text CbConf "conflicting types for" |
| 97 | text CbFxSum "omega_fx_sum" |
| 98 | text CbCpass "CALLER PASS checks=57 failures=0\n" |
| 99 | text CbCfail "CALLER FAIL checks=" |
| 100 | text CbLost "lost=0\n" |
| 101 | text CbS1 "nvmlDeviceGetCount_v2" |
| 102 | text CbS2 "nvmlDeviceGetHandleByIndex_v2" |
| 103 | text CbS3 "nvmlDeviceGetName" |
| 104 | text CbS4 "nvmlDeviceGetMemoryInfo" |
| 105 | text CbS5 "nvmlDeviceGetComputeRunningProcesses_v2" |
| 106 | text CbS6 "nvmlErrorString" |
| 107 | text CbS7 "ombrFxBump" |
| 108 | text CbS8 "ombrFxSum" |
| 109 | text CbLdet "generation is deterministic" |
| 110 | text CbLprov "provenance line names the toc.om and source digests" |
| 111 | text CbLgold "artifact equals its golden after the provenance line" |
| 112 | text CbLfunc "exported wrapper equals its golden" |
| 113 | text CbLnm "nm -D --defined-only shows exactly the declared exports" |
| 114 | text CbLson "readelf shows the declared soname" |
| 115 | text CbLcall "caller ORACLE passes against the generated library" |
| 116 | text CbLproto "import declaration disagreeing with the external header is refused by cc" |
| 117 | text CbLonce "mutation text occurs exactly once" |
| 118 | text CbLhit "mutation text occurs" |
| 119 | text CbLdiag "refusal names the expected error" |
| 120 | text CbLemit "refusal emits no artifact" |
| 121 | text CbLgood "unmutated direct input generates" |
| 122 | text CbLmut "wrapper mutant is caught by the caller ORACLE" |
| 123 | text CbPgen "PASS generated C, header and version map: deterministic, provenance line and golden bytes\n" |
| 124 | text CbPfunc "PASS golden wrappers: nvmlDeviceGetCount_v2, nvmlDeviceGetName, nvmlErrorString\n" |
| 125 | text CbPnm "PASS ORACLE nm/readelf: 8 exports, no omega_ symbols, soname libombrfx.so.1\n" |
| 126 | text CbPcall "PASS ORACLE caller: 57 checks, nulls, out-params, handles, forged handles, stable strings, 8 threads x 2000 calls lost=0\n" |
| 127 | text CbPproto "PASS ORACLE cc refuses an import declaration that disagrees with the external unit's generated header\n" |
| 128 | text CbPref "PASS refused error " |
| 129 | text CbPsep ": " |
| 130 | text CbPdir "PASS direct build/bridge input: " |
| 131 | text CbPmut "PASS wrapper mutant caught: " |
| 132 | text CbXok "recomputed digests match; output equals the wrapper's (exit 0)\n" |
| 133 | text CbX52 "no provenance trailer refused (error 52)\n" |
| 134 | text CbX52z "all-zero digests refused (error 52)\n" |
| 135 | text CbX52t "zero generator digest refused (error 52)\n" |
| 136 | text CbX52w "wrong generator digest refused (error 52)\n" |
| 137 | text CbX52s "wrong source digest refused (error 52)\n" |
| 138 | text CbX52f "generator source withheld from descriptor 3 refused (error 52)\n" |
| 139 | text CbX51 "Omega global refused (error 51)\n" |
| 140 | text CbX51f "\nfn fx_init " |
| 141 | text CbX51t "\nglobal FxG ulong 1\n\nfn fx_init " |
| 142 | text CbImpF "span v 3 k value k" |
| 143 | text CbImpT "span v 3 k" |
| 144 | text CbAf1 "o_f[2]=deviceCount!=NULL;" |
| 145 | text CbAt1 "o_f[2]=1;" |
| 146 | text CbAf2 "(!deviceCount||" |
| 147 | text CbAt2 "(" |
| 148 | text CbAw "FAIL count null out refused without commit\n" |
| 149 | text CbBf "*deviceCount=(unsigned int)o_f[3];" |
| 150 | text CbBt "(void)0;" |
| 151 | text CbBw "FAIL count published\n" |
| 152 | text CbCf1 "if(pthread_mutex_lock(&FxLock))return (nvmlReturn_t)999;\n o_f[2]=value!=NULL;" |
| 153 | text CbCt1 "o_f[2]=value!=NULL;" |
| 154 | text CbCf2 "*value=(unsigned long long)o_f[3];\n }\n pthread_mutex_unlock(&FxLock);" |
| 155 | text CbCt2 "*value=(unsigned long long)o_f[3];\n }" |
| 156 | text CbCw "FAIL no lost updates under concurrent calls\n" |
| 157 | text CbImpU "span v 2 k value k" |
| 158 | text CbDm "build/cabi/md" |
| 159 | text CbMsrc "build/cabi/md.om" |
| 160 | text CbMout "build/cabi/md.c" |
| 161 | text CbDw "FAIL import through omega_fx_sum with uchar and ulong spans\n" |
| 162 | text R40f " FxLock process mutex" |
| 163 | text R40t " FxLock process spin" |
| 164 | text R40l "malformed lock kind" |
| 165 | text R41f "note cabi export ombrFxBump fx_bump status" |
| 166 | text R41t "note cabi export nvmlDeviceGetName fx_bump status" |
| 167 | text R41l "duplicate export symbol" |
| 168 | text R42af "state FxSum ulong 1 process lock FxLock" |
| 169 | text R42at "state FxSum ulong 1 process lock FxLok" |
| 170 | text R42al "unknown lock" |
| 171 | text R42bf "bind nvmlDeviceGetCount_v2 st FxState" |
| 172 | text R42bt "bind nvmlDeviceGetCount_v2 st FxStat" |
| 173 | text R42bl "undeclared state" |
| 174 | text R42cf "export nvmlDeviceGetCount_v2 fx_count" |
| 175 | text R42ct "export nvmlDeviceGetCount_v2 fx_cnt" |
| 176 | text R42cl "export of a missing function" |
| 177 | text R42df "alias nvmlDeviceGetCount nvmlDeviceGetCount_v2" |
| 178 | text R42dt "alias nvmlDeviceGetCount nvmlDeviceGetCount_v3" |
| 179 | text R42dl "alias of a missing export" |
| 180 | text R43f "deviceCount nullable out uint32" |
| 181 | text R43t "deviceCount out uint32" |
| 182 | text R43l "wrong nullability" |
| 183 | text R44af "field nvmlMemory_t used uint64 16" |
| 184 | text R44at "field nvmlMemory_t used uint64 12" |
| 185 | text R44al "bad record offset" |
| 186 | text R44bf "nvmlMemory_st size 24" |
| 187 | text R44bt "nvmlMemory_st size 32" |
| 188 | text R44bl "bad record size" |
| 189 | text R45af "bind nvmlDeviceGetName b FxBytes" |
| 190 | text R45at "bind nvmlDeviceGetName b FxTexts" |
| 191 | text R45al "bind to state of the wrong extent" |
| 192 | text R45bf "nullable out nvmlProcessInfo_v2_t count infoCount commit 2" |
| 193 | text R45bt "nullable out nvmlProcessInfo_v2_t commit 2" |
| 194 | text R45bl "record array without count no longer matches the frame" |
| 195 | text R46af "export ombrFxBump fx_bump status nvmlReturn_t" |
| 196 | text R46at "export ombrFxBump fx_bump pointer nvmlReturn_t" |
| 197 | text R46al "raw pointer result" |
| 198 | text R46bf "arg ombrFxSum seed uint64" |
| 199 | text R46bt "arg ombrFxSum seed nvmlMemory_t" |
| 200 | text R46bl "raw pointer argument" |
| 201 | text R47f "name nullable out char length length commit 0" |
| 202 | text R47t "name nullable out char commit 0" |
| 203 | text R47l "out span without length" |
| 204 | text R48af "export nvmlErrorString fx_err cstr FxTexts" |
| 205 | text R48at "export nvmlErrorString fx_err cstr FxBytes" |
| 206 | text R48al "non-stable string storage" |
| 207 | text R48bf "cstr FxTexts slots 4 width 32" |
| 208 | text R48bt "cstr FxTexts slots 8 width 32" |
| 209 | text R48bl "cstr outside its storage" |
| 210 | text R49f "v view ulong 6 k ulong to ulong\nret 0" |
| 211 | text R49t "v view ulong 6 k ulong to ulong\nput r 0 1\nret 0" |
| 212 | text R49l "import stub with a body" |
| 213 | text R50f "\nfn fx_init " |
| 214 | text R50t "\nfn main to int\nret 0\nend\n\nfn fx_init " |
| 215 | text R50l "main in a library unit" |
| 216 | |
| 217 | fn cb_say s view uchar * to void |
| 218 | hp_wpart 1 s 0 len s |
| 219 | end |
| 220 | |
| 221 | fn cb_check ok bool label view uchar * to void |
| 222 | if not ok |
| 223 | hp_say CbFailP |
| 224 | hp_say label |
| 225 | hp_say CbNl |
| 226 | exit 1 |
| 227 | end |
| 228 | end |
| 229 | |
| 230 | fn cb_no to void |
| 231 | hp_say CbNo |
| 232 | exit 77 |
| 233 | end |
| 234 | |
| 235 | fn cb_env key view uchar * dst edit uchar * to ulong |
| 236 | b = new uchar 8192 0 |
| 237 | for i ulong ulong envcnt |
| 238 | r = envread i b 0 len b |
| 239 | if ge r long len key |
| 240 | if hp_equal key b len key |
| 241 | n = sub ulong r len key |
| 242 | hp_require le n len dst |
| 243 | for j ulong n |
| 244 | put dst j get b add len key j |
| 245 | end |
| 246 | ret n |
| 247 | end |
| 248 | end |
| 249 | end |
| 250 | ret 0 |
| 251 | end |
| 252 | |
| 253 | fn cb_mkdir p view uchar * to void |
| 254 | r = makedir p 0 len p 493 |
| 255 | if ne r -17 |
| 256 | hp_require eq r 0 |
| 257 | end |
| 258 | end |
| 259 | |
| 260 | fn cb_config to void |
| 261 | b = new uchar 1024 0 |
| 262 | on = cb_env CbSeedK b |
| 263 | if eq on 0 |
| 264 | cb_no |
| 265 | end |
| 266 | if ne faccess b 0 on 1 0 |
| 267 | cb_no |
| 268 | end |
| 269 | if ne faccess CbBr 0 len CbBr 1 0 |
| 270 | cb_no |
| 271 | end |
| 272 | if ne faccess CbToc 0 len CbToc 4 0 |
| 273 | cb_no |
| 274 | end |
| 275 | put CbOn 0 on |
| 276 | for i ulong on |
| 277 | put CbOm i get b i |
| 278 | end |
| 279 | cb_mkdir CbDir |
| 280 | cb_mkdir CbDa |
| 281 | cb_mkdir CbDb |
| 282 | cb_mkdir CbDc |
| 283 | cb_mkdir CbDm |
| 284 | end |
| 285 | |
| 286 | fn cb_exec path view uchar * pn ulong code long to void |
| 287 | fd = hp_open path pn 524865 420 |
| 288 | hp_exec -1 fd code |
| 289 | hp_close fd |
| 290 | end |
| 291 | |
| 292 | note cc (ORACLE) runs under /usr/bin/env PATH=/usr/bin:/bin: execprog passes no environment, and |
| 293 | note collect2 finds ld through PATH. |
| 294 | fn cb_ccst to void |
| 295 | hp_start CbEnv len CbEnv |
| 296 | hp_arg CbPath len CbPath |
| 297 | hp_arg CbCc len CbCc |
| 298 | end |
| 299 | |
| 300 | fn cb_bridge mode view uchar * unit view uchar * dest view uchar * to void |
| 301 | b = new uchar 2048 0 |
| 302 | hp_start CbEnv len CbEnv |
| 303 | hp_arg CbPath len CbPath |
| 304 | for i ulong len CbSeedK |
| 305 | put b i get CbSeedK i |
| 306 | end |
| 307 | n = get CbOn 0 |
| 308 | for i ulong n |
| 309 | put b add len CbSeedK i get CbOm i |
| 310 | end |
| 311 | hp_arg b add len CbSeedK n |
| 312 | hp_arg CbSh len CbSh |
| 313 | hp_arg CbWrap len CbWrap |
| 314 | hp_arg mode len mode |
| 315 | hp_arg unit len unit |
| 316 | cb_exec dest len dest long get CbExp 0 |
| 317 | end |
| 318 | |
| 319 | fn cb_hex v uchar to bool |
| 320 | if and ge v 48 le v 57 |
| 321 | ret true |
| 322 | end |
| 323 | ret and ge v 97 le v 102 |
| 324 | end |
| 325 | |
| 326 | fn cb_hash path view uchar * dst edit uchar 64 to void |
| 327 | b = new uchar 2048 0 |
| 328 | hp_start CbSha len CbSha |
| 329 | hp_arg path len path |
| 330 | cb_exec CbHash len CbHash 0 |
| 331 | k = hp_read CbHash len CbHash b len b |
| 332 | hp_require ge k 65 |
| 333 | for i ulong 64 |
| 334 | v = get b i |
| 335 | hp_require cb_hex v |
| 336 | put dst i v |
| 337 | end |
| 338 | hp_require eq get b 64 32 |
| 339 | end |
| 340 | |
| 341 | fn cb_put dst edit uchar * pos ulong w view uchar * wn ulong to ulong |
| 342 | hp_require le wn len w |
| 343 | hp_require le pos len dst |
| 344 | hp_require le wn sub len dst pos |
| 345 | for i ulong wn |
| 346 | put dst add pos i get w i |
| 347 | end |
| 348 | ret add pos wn |
| 349 | end |
| 350 | |
| 351 | fn cb_join dir view uchar * name view uchar * dst edit uchar 256 to ulong |
| 352 | n = cb_put dst 0 dir len dir |
| 353 | ret cb_put dst n name len name |
| 354 | end |
| 355 | |
| 356 | fn cb_atn a view uchar * p ulong w view uchar * wn ulong to bool |
| 357 | if gt wn len a |
| 358 | ret false |
| 359 | end |
| 360 | if gt p sub len a wn |
| 361 | ret false |
| 362 | end |
| 363 | for i ulong wn |
| 364 | v = get a add p i |
| 365 | if ne v get w i |
| 366 | ret false |
| 367 | end |
| 368 | end |
| 369 | ret true |
| 370 | end |
| 371 | |
| 372 | fn cb_count a view uchar * n ulong w view uchar * wn ulong to ulong |
| 373 | c = ulong 0 |
| 374 | for p ulong n |
| 375 | if cb_atn a p w wn |
| 376 | c = add c 1 |
| 377 | end |
| 378 | end |
| 379 | ret c |
| 380 | end |
| 381 | |
| 382 | fn cb_has a view uchar * n ulong w view uchar * to bool |
| 383 | ret gt cb_count a n w len w 0 |
| 384 | end |
| 385 | |
| 386 | fn cb_find a view uchar * n ulong from ulong w view uchar * to ulong |
| 387 | p = from |
| 388 | while lt p n bound 999999 |
| 389 | if cb_atn a p w len w |
| 390 | ret p |
| 391 | end |
| 392 | p = add p 1 |
| 393 | end |
| 394 | ret n |
| 395 | end |
| 396 | |
| 397 | note Source bytes end at the first NUL; the fixture and generated C hold none. |
| 398 | fn cb_sub a view uchar 131072 f view uchar * t view uchar * d edit uchar 131072 to ulong |
| 399 | o = ulong 0 |
| 400 | p = ulong 0 |
| 401 | hits = ulong 0 |
| 402 | while lt p len a bound 999999 |
| 403 | if eq get a p 0 |
| 404 | break |
| 405 | end |
| 406 | if cb_atn a p f len f |
| 407 | o = cb_put d o t len t |
| 408 | p = add p len f |
| 409 | hits = add hits 1 |
| 410 | else |
| 411 | hp_require lt o len d |
| 412 | put d o get a p |
| 413 | o = add o 1 |
| 414 | p = add p 1 |
| 415 | end |
| 416 | end |
| 417 | cb_check gt hits 0 CbLhit |
| 418 | hp_require lt o len d |
| 419 | ret o |
| 420 | end |
| 421 | |
| 422 | fn cb_prov line edit uchar 256 to ulong |
| 423 | th = new uchar 64 0 |
| 424 | sh = new uchar 64 0 |
| 425 | cb_hash CbToc th |
| 426 | cb_hash CbFix sh |
| 427 | n = cb_put line 0 CbPa len CbPa |
| 428 | n = cb_put line n th 64 |
| 429 | n = cb_put line n CbPb len CbPb |
| 430 | n = cb_put line n sh 64 |
| 431 | ret cb_put line n CbPc len CbPc |
| 432 | end |
| 433 | |
| 434 | fn cb_same a view uchar * off ulong g view uchar * k ulong to bool |
| 435 | hp_require le off len a |
| 436 | hp_require le k sub len a off |
| 437 | hp_require le k len g |
| 438 | for i ulong k |
| 439 | v = get a add off i |
| 440 | if ne v get g i |
| 441 | ret false |
| 442 | end |
| 443 | end |
| 444 | ret true |
| 445 | end |
| 446 | |
| 447 | fn cb_golden path view uchar * line view uchar 256 ln ulong gold view uchar * to void |
| 448 | a = new uchar 131072 0 |
| 449 | g = new uchar 131072 0 |
| 450 | n = hp_read path len path a len a |
| 451 | hp_require lt n len a |
| 452 | cb_check gt n ln CbLprov |
| 453 | cb_check hp_equal a line ln CbLprov |
| 454 | k = hp_read gold len gold g len g |
| 455 | hp_require lt k len g |
| 456 | cb_check eq k sub n ln CbLgold |
| 457 | cb_check cb_same a ln g k CbLgold |
| 458 | end |
| 459 | |
| 460 | fn cb_line a view uchar * p ulong to bool |
| 461 | if eq p 0 |
| 462 | ret true |
| 463 | end |
| 464 | ret eq get a sub p 1 10 |
| 465 | end |
| 466 | |
| 467 | fn cb_func path view uchar * gold view uchar * to void |
| 468 | a = new uchar 131072 0 |
| 469 | g = new uchar 8192 0 |
| 470 | n = hp_read path len path a len a |
| 471 | hp_require lt n len a |
| 472 | k = hp_read gold len gold g len g |
| 473 | hp_require lt k len g |
| 474 | e = cb_find g k 0 CbNl |
| 475 | hp_require lt e k |
| 476 | kl = add e 1 |
| 477 | hits = ulong 0 |
| 478 | pos = ulong 0 |
| 479 | for p ulong n |
| 480 | if cb_line a p |
| 481 | if cb_atn a p g kl |
| 482 | hits = add hits 1 |
| 483 | pos = p |
| 484 | end |
| 485 | end |
| 486 | end |
| 487 | cb_check eq hits 1 CbLfunc |
| 488 | q = cb_find a n pos CbClose |
| 489 | cb_check lt q n CbLfunc |
| 490 | cb_check eq sub add q 3 pos k CbLfunc |
| 491 | cb_check cb_same a pos g k CbLfunc |
| 492 | end |
| 493 | |
| 494 | fn cb_gen to void |
| 495 | line = new uchar 256 0 |
| 496 | cb_bridge CbLc CbFix CbOutC |
| 497 | cb_bridge CbLc CbFix CbAgain |
| 498 | cb_check hp_cmp CbOutC len CbOutC CbAgain len CbAgain CbLdet |
| 499 | cb_bridge CbLh CbFix CbOutH |
| 500 | cb_bridge CbLm CbFix CbOutM |
| 501 | cb_bridge CbC CbExtS CbExtC |
| 502 | cb_bridge CbH CbExtS CbExtH |
| 503 | ln = cb_prov line |
| 504 | cb_golden CbOutC line ln CbGc |
| 505 | cb_golden CbOutH line ln CbGh |
| 506 | cb_golden CbOutM line ln CbGm |
| 507 | cb_say CbPgen |
| 508 | cb_func CbOutC CbG1 |
| 509 | cb_func CbOutC CbG2 |
| 510 | cb_func CbOutC CbG3 |
| 511 | cb_say CbPfunc |
| 512 | end |
| 513 | |
| 514 | fn cb_so dir view uchar * to void |
| 515 | so = new uchar 256 0 |
| 516 | cs = new uchar 256 0 |
| 517 | lg = new uchar 256 0 |
| 518 | sn = cb_join dir CbSoN so |
| 519 | cn = cb_join dir CbCN cs |
| 520 | gn = cb_join dir CbLogN lg |
| 521 | cb_ccst |
| 522 | hp_arg CbStd len CbStd |
| 523 | hp_arg CbO2 len CbO2 |
| 524 | hp_arg CbPic len CbPic |
| 525 | hp_arg CbWall len CbWall |
| 526 | hp_arg CbWext len CbWext |
| 527 | hp_arg CbWerr len CbWerr |
| 528 | hp_arg CbShare len CbShare |
| 529 | hp_arg CbInc len CbInc |
| 530 | hp_arg CbStdi len CbStdi |
| 531 | hp_arg CbInc len CbInc |
| 532 | hp_arg CbExtH len CbExtH |
| 533 | hp_arg CbSoname len CbSoname |
| 534 | hp_arg CbVers len CbVers |
| 535 | hp_arg CbDefs len CbDefs |
| 536 | hp_arg CbDo len CbDo |
| 537 | hp_arg so sn |
| 538 | hp_arg cs cn |
| 539 | hp_arg CbExtC len CbExtC |
| 540 | hp_arg CbPth len CbPth |
| 541 | cb_exec lg gn 0 |
| 542 | end |
| 543 | |
| 544 | fn cb_caller dir view uchar * code long to void |
| 545 | so = new uchar 256 0 |
| 546 | ex = new uchar 256 0 |
| 547 | lg = new uchar 256 0 |
| 548 | ot = new uchar 256 0 |
| 549 | sn = cb_join dir CbSoN so |
| 550 | xn = cb_join dir CbExN ex |
| 551 | gn = cb_join dir CbLogN lg |
| 552 | on = cb_join dir CbOutN ot |
| 553 | cb_ccst |
| 554 | hp_arg CbStd len CbStd |
| 555 | hp_arg CbO2 len CbO2 |
| 556 | hp_arg CbWall len CbWall |
| 557 | hp_arg CbWext len CbWext |
| 558 | hp_arg CbWerr len CbWerr |
| 559 | hp_arg CbIdir len CbIdir |
| 560 | hp_arg CbDo len CbDo |
| 561 | hp_arg ex xn |
| 562 | hp_arg CbCall len CbCall |
| 563 | hp_arg so sn |
| 564 | hp_arg CbRpath len CbRpath |
| 565 | hp_arg CbPth len CbPth |
| 566 | cb_exec lg gn 0 |
| 567 | hp_start ex xn |
| 568 | cb_exec ot on code |
| 569 | end |
| 570 | |
| 571 | fn cb_output dir view uchar * b edit uchar 16384 to ulong |
| 572 | ot = new uchar 256 0 |
| 573 | on = cb_join dir CbOutN ot |
| 574 | n = hp_read ot on b len b |
| 575 | hp_require lt n len b |
| 576 | ret n |
| 577 | end |
| 578 | |
| 579 | fn cb_lib to void |
| 580 | b = new uchar 8192 0 |
| 581 | cb_so CbDir |
| 582 | hp_start CbNmT len CbNmT |
| 583 | hp_arg CbDyn len CbDyn |
| 584 | hp_arg CbDef len CbDef |
| 585 | hp_arg CbSo len CbSo |
| 586 | cb_exec CbNm len CbNm 0 |
| 587 | n = hp_read CbNm len CbNm b len b |
| 588 | hp_require lt n len b |
| 589 | cb_check eq cb_count b n CbNl 1 8 CbLnm |
| 590 | cb_sym b n CbS1 |
| 591 | cb_sym b n CbS2 |
| 592 | cb_sym b n CbS3 |
| 593 | cb_sym b n CbS4 |
| 594 | cb_sym b n CbS5 |
| 595 | cb_sym b n CbS6 |
| 596 | cb_sym b n CbS7 |
| 597 | cb_sym b n CbS8 |
| 598 | cb_check not cb_has b n CbOmega CbLnm |
| 599 | hp_start CbRel len CbRel |
| 600 | hp_arg CbDd len CbDd |
| 601 | hp_arg CbSo len CbSo |
| 602 | cb_exec CbRe len CbRe 0 |
| 603 | k = hp_read CbRe len CbRe b len b |
| 604 | hp_require lt k len b |
| 605 | cb_check cb_has b k CbSonam CbLson |
| 606 | cb_say CbPnm |
| 607 | end |
| 608 | |
| 609 | fn cb_sym b view uchar * n ulong s view uchar * to void |
| 610 | w = new uchar 128 0 |
| 611 | k = cb_put w 0 CbT len CbT |
| 612 | k = cb_put w k s len s |
| 613 | k = cb_put w k CbNl 1 |
| 614 | cb_check eq cb_count b n w k 1 CbLnm |
| 615 | end |
| 616 | |
| 617 | fn cb_ends b view uchar * n ulong w view uchar * to bool |
| 618 | if lt n len w |
| 619 | ret false |
| 620 | end |
| 621 | ret cb_atn b sub n len w w len w |
| 622 | end |
| 623 | |
| 624 | fn cb_call to void |
| 625 | b = new uchar 16384 0 |
| 626 | cb_caller CbDir 0 |
| 627 | n = cb_output CbDir b |
| 628 | cb_check cb_ends b n CbCpass CbLcall |
| 629 | cb_check cb_has b n CbLost CbLcall |
| 630 | cb_say CbPcall |
| 631 | end |
| 632 | |
| 633 | fn cb_fixture a edit uchar 131072 to ulong |
| 634 | n = hp_read CbFix len CbFix a len a |
| 635 | hp_require lt n len a |
| 636 | ret n |
| 637 | end |
| 638 | |
| 639 | fn cb_proto to void |
| 640 | a = new uchar 131072 0 |
| 641 | d = new uchar 131072 0 |
| 642 | b = new uchar 16384 0 |
| 643 | n = cb_fixture a |
| 644 | hp_require gt n 0 |
| 645 | m = cb_sub a CbImpF CbImpT d |
| 646 | hp_write CbImp len CbImp d m |
| 647 | cb_bridge CbLc CbImp CbImpC |
| 648 | cb_ccst |
| 649 | hp_arg CbStd len CbStd |
| 650 | hp_arg CbO2 len CbO2 |
| 651 | hp_arg CbPic len CbPic |
| 652 | hp_arg CbWall len CbWall |
| 653 | hp_arg CbWext len CbWext |
| 654 | hp_arg CbWerr len CbWerr |
| 655 | hp_arg CbCo len CbCo |
| 656 | hp_arg CbInc len CbInc |
| 657 | hp_arg CbStdi len CbStdi |
| 658 | hp_arg CbInc len CbInc |
| 659 | hp_arg CbExtH len CbExtH |
| 660 | hp_arg CbDo len CbDo |
| 661 | hp_arg CbImpO len CbImpO |
| 662 | hp_arg CbImpC len CbImpC |
| 663 | put HMerge 0 1 |
| 664 | cb_exec CbImpL len CbImpL 1 |
| 665 | put HMerge 0 0 |
| 666 | k = hp_read CbImpL len CbImpL b len b |
| 667 | hp_require lt k len b |
| 668 | cb_check cb_has b k CbConf CbLproto |
| 669 | cb_check cb_has b k CbFxSum CbLproto |
| 670 | cb_say CbPproto |
| 671 | end |
| 672 | |
| 673 | fn cb_errw code long w edit uchar 64 to ulong |
| 674 | digits = new uchar 32 0 |
| 675 | k = cb_put w 0 CbErrW len CbErrW |
| 676 | d = hp_num ulong code digits |
| 677 | k = cb_put w k digits d |
| 678 | ret cb_put w k CbNl 1 |
| 679 | end |
| 680 | |
| 681 | fn cb_refused b view uchar * k ulong code long to void |
| 682 | w = new uchar 64 0 |
| 683 | wn = cb_errw code w |
| 684 | cb_check eq cb_count b k w wn 1 CbLdiag |
| 685 | cb_check not cb_has b k CbGen CbLemit |
| 686 | end |
| 687 | |
| 688 | fn cb_refuse f view uchar * t view uchar * code long to void |
| 689 | a = new uchar 131072 0 |
| 690 | d = new uchar 131072 0 |
| 691 | b = new uchar 16384 0 |
| 692 | digits = new uchar 32 0 |
| 693 | n = cb_fixture a |
| 694 | cb_check eq cb_count a n f len f 1 CbLonce |
| 695 | m = cb_sub a f t d |
| 696 | hp_write CbRef len CbRef d m |
| 697 | put CbExp 0 ulong code |
| 698 | put HMerge 0 1 |
| 699 | cb_bridge CbLc CbRef CbRefO |
| 700 | put HMerge 0 0 |
| 701 | put CbExp 0 0 |
| 702 | k = hp_read CbRefO len CbRefO b len b |
| 703 | hp_require lt k len b |
| 704 | cb_refused b k code |
| 705 | cb_say CbPref |
| 706 | dn = hp_num ulong code digits |
| 707 | hp_wpart 1 digits 0 dn |
| 708 | cb_say CbPsep |
| 709 | end |
| 710 | |
| 711 | fn cb_tail label view uchar * to void |
| 712 | cb_say label |
| 713 | cb_say CbNl |
| 714 | end |
| 715 | |
| 716 | fn cb_refusals to void |
| 717 | cb_refuse R40f R40t 40 |
| 718 | cb_tail R40l |
| 719 | cb_refuse R41f R41t 41 |
| 720 | cb_tail R41l |
| 721 | cb_refuse R42af R42at 42 |
| 722 | cb_tail R42al |
| 723 | cb_refuse R42bf R42bt 42 |
| 724 | cb_tail R42bl |
| 725 | cb_refuse R42cf R42ct 42 |
| 726 | cb_tail R42cl |
| 727 | cb_refuse R42df R42dt 42 |
| 728 | cb_tail R42dl |
| 729 | cb_refuse R43f R43t 43 |
| 730 | cb_tail R43l |
| 731 | cb_refuse R44af R44at 44 |
| 732 | cb_tail R44al |
| 733 | cb_refuse R44bf R44bt 44 |
| 734 | cb_tail R44bl |
| 735 | cb_refuse R45af R45at 45 |
| 736 | cb_tail R45al |
| 737 | cb_refuse R45bf R45bt 45 |
| 738 | cb_tail R45bl |
| 739 | cb_refuse R46af R46at 46 |
| 740 | cb_tail R46al |
| 741 | cb_refuse R46bf R46bt 46 |
| 742 | cb_tail R46bl |
| 743 | cb_refuse R47f R47t 47 |
| 744 | cb_tail R47l |
| 745 | cb_refuse R48af R48at 48 |
| 746 | cb_tail R48al |
| 747 | cb_refuse R48bf R48bt 48 |
| 748 | cb_tail R48bl |
| 749 | cb_refuse R49f R49t 49 |
| 750 | cb_tail R49l |
| 751 | cb_refuse R50f R50t 50 |
| 752 | cb_tail R50l |
| 753 | end |
| 754 | |
| 755 | fn cb_nlen s view uchar 131072 to ulong |
| 756 | for i ulong len s |
| 757 | if eq get s i 0 |
| 758 | ret i |
| 759 | end |
| 760 | end |
| 761 | ret len s |
| 762 | end |
| 763 | |
| 764 | note cb_spoil: kind 0 keeps the digest, 1 makes it 64 zeros, 2 changes its first digit. |
| 765 | fn cb_spoil h edit uchar 64 kind ulong to void |
| 766 | if eq kind 1 |
| 767 | for i ulong 64 |
| 768 | put h i uchar 48 |
| 769 | end |
| 770 | end |
| 771 | if eq kind 2 |
| 772 | if eq get h 0 48 |
| 773 | put h 0 uchar 49 |
| 774 | else |
| 775 | put h 0 uchar 48 |
| 776 | end |
| 777 | end |
| 778 | end |
| 779 | |
| 780 | note cb_direct runs build/bridge without the wrapper. mode = toc kind + 3 * source kind (cb_spoil) |
| 781 | note + 9 when descriptor 3 is withheld + 27 when no trailer is appended. Digests come from the |
| 782 | note sha256sum ORACLE; the generator must recompute them itself and accept only exact matches. |
| 783 | fn cb_dfeed s view uchar 131072 mode ulong d edit uchar 140000 to ulong |
| 784 | th = new uchar 64 0 |
| 785 | sh = new uchar 64 0 |
| 786 | n = cb_nlen s |
| 787 | hp_write CbDsrc len CbDsrc s n |
| 788 | cb_hash CbToc th |
| 789 | cb_hash CbDsrc sh |
| 790 | cb_spoil th rem mode 3 |
| 791 | cb_spoil sh rem div mode 3 3 |
| 792 | put d 0 uchar 76 |
| 793 | k = cb_put d 1 s n |
| 794 | if eq div mode 27 0 |
| 795 | put d k uchar 10 |
| 796 | k = cb_put d add k 1 th 64 |
| 797 | put d k uchar 32 |
| 798 | k = cb_put d add k 1 sh 64 |
| 799 | put d k uchar 10 |
| 800 | k = add k 1 |
| 801 | end |
| 802 | ret k |
| 803 | end |
| 804 | |
| 805 | fn cb_drun mode ulong code long to void |
| 806 | infd = hp_open CbDin len CbDin 524288 0 |
| 807 | outfd = hp_open CbDout len CbDout 524865 420 |
| 808 | tf = hp_open CbToc len CbToc 524288 0 |
| 809 | hp_require gt tf 3 |
| 810 | if eq rem div mode 9 3 0 |
| 811 | put HFd3 0 add ulong tf 1 |
| 812 | end |
| 813 | put HMerge 0 1 |
| 814 | hp_start CbBr len CbBr |
| 815 | hp_exec infd outfd code |
| 816 | put HMerge 0 0 |
| 817 | put HFd3 0 0 |
| 818 | hp_close tf |
| 819 | hp_close infd |
| 820 | hp_close outfd |
| 821 | end |
| 822 | |
| 823 | fn cb_direct s view uchar 131072 mode ulong code long label view uchar * to void |
| 824 | d = new uchar 140000 0 |
| 825 | b = new uchar 131072 0 |
| 826 | e = new uchar 131072 0 |
| 827 | k = cb_dfeed s mode d |
| 828 | hp_write CbDin len CbDin d k |
| 829 | cb_drun mode code |
| 830 | m = hp_read CbDout len CbDout b len b |
| 831 | hp_require lt m len b |
| 832 | if eq code 0 |
| 833 | en = cb_base e |
| 834 | cb_check eq m en CbLgood |
| 835 | cb_check hp_equal b e m CbLgood |
| 836 | else |
| 837 | cb_refused b m code |
| 838 | end |
| 839 | cb_say CbPdir |
| 840 | cb_say label |
| 841 | end |
| 842 | |
| 843 | fn cb_dirs to void |
| 844 | a = new uchar 131072 0 |
| 845 | d = new uchar 131072 0 |
| 846 | n = cb_fixture a |
| 847 | hp_require gt n 0 |
| 848 | cb_direct a 0 0 CbXok |
| 849 | cb_direct a 27 52 CbX52 |
| 850 | cb_direct a 4 52 CbX52z |
| 851 | cb_direct a 1 52 CbX52t |
| 852 | cb_direct a 2 52 CbX52w |
| 853 | cb_direct a 6 52 CbX52s |
| 854 | cb_direct a 9 52 CbX52f |
| 855 | m = cb_sub a CbX51f CbX51t d |
| 856 | hp_require gt m n |
| 857 | cb_direct d 0 51 CbX51 |
| 858 | end |
| 859 | |
| 860 | fn cb_mrun dir view uchar * c view uchar 131072 n ulong want view uchar * to void |
| 861 | cs = new uchar 256 0 |
| 862 | b = new uchar 16384 0 |
| 863 | cn = cb_join dir CbCN cs |
| 864 | hp_write cs cn c n |
| 865 | cb_so dir |
| 866 | cb_caller dir 1 |
| 867 | k = cb_output dir b |
| 868 | cb_check cb_has b k want CbLmut |
| 869 | cb_check cb_has b k CbCfail CbLmut |
| 870 | cb_say CbPmut |
| 871 | cb_say want |
| 872 | end |
| 873 | |
| 874 | fn cb_base a edit uchar 131072 to ulong |
| 875 | n = hp_read CbOutC len CbOutC a len a |
| 876 | hp_require lt n len a |
| 877 | ret n |
| 878 | end |
| 879 | |
| 880 | fn cb_muta to void |
| 881 | a = new uchar 131072 0 |
| 882 | d = new uchar 131072 0 |
| 883 | e = new uchar 131072 0 |
| 884 | n = cb_base a |
| 885 | hp_require gt n 0 |
| 886 | m = cb_sub a CbAf1 CbAt1 d |
| 887 | k = cb_sub d CbAf2 CbAt2 e |
| 888 | cb_mrun CbDa e k CbAw |
| 889 | end |
| 890 | |
| 891 | fn cb_mutb to void |
| 892 | a = new uchar 131072 0 |
| 893 | d = new uchar 131072 0 |
| 894 | n = cb_base a |
| 895 | hp_require gt n 0 |
| 896 | m = cb_sub a CbBf CbBt d |
| 897 | cb_mrun CbDb d m CbBw |
| 898 | end |
| 899 | |
| 900 | fn cb_mutc to void |
| 901 | a = new uchar 131072 0 |
| 902 | d = new uchar 131072 0 |
| 903 | e = new uchar 131072 0 |
| 904 | n = cb_base a |
| 905 | hp_require gt n 0 |
| 906 | m = cb_sub a CbCf1 CbCt1 d |
| 907 | k = cb_sub d CbCf2 CbCt2 e |
| 908 | cb_mrun CbDc e k CbCw |
| 909 | end |
| 910 | |
| 911 | note cb_mutd moves the ulong span of the omega_fx_sum import from element 3 to element 2 in the source; |
| 912 | note the bridge accepts it (the offset is in bounds) and only the caller ORACLE can see the wrong element. |
| 913 | fn cb_mutd to void |
| 914 | a = new uchar 131072 0 |
| 915 | d = new uchar 131072 0 |
| 916 | e = new uchar 131072 0 |
| 917 | n = cb_fixture a |
| 918 | hp_require gt n 0 |
| 919 | cb_check eq cb_count a n CbImpF len CbImpF 1 CbLonce |
| 920 | m = cb_sub a CbImpF CbImpU d |
| 921 | hp_write CbMsrc len CbMsrc d m |
| 922 | cb_bridge CbLc CbMsrc CbMout |
| 923 | k = hp_read CbMout len CbMout e len e |
| 924 | hp_require lt k len e |
| 925 | cb_mrun CbDm e k CbDw |
| 926 | end |
| 927 | |
| 928 | fn cb_mutants to void |
| 929 | cb_muta |
| 930 | cb_mutb |
| 931 | cb_mutc |
| 932 | cb_mutd |
| 933 | end |
| 934 | |
| 935 | fn main to int |
| 936 | cb_config |
| 937 | cb_gen |
| 938 | cb_lib |
| 939 | cb_call |
| 940 | cb_proto |
| 941 | cb_refusals |
| 942 | cb_dirs |
| 943 | cb_mutants |
| 944 | cb_say CbPass |
| 945 | ret 0 |
| 946 | end |