interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / bridge / shlib / gate.om

2365 lines · 54820 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note bridge/shlib/gate.om: OMEGA-SHLIB, the gate of bridge/shlib (shared libraries written by Omega alone), in
3note seeded Omega (Linux AArch64). Build from the repository root (OM-2 program mode; seed/ng/sha256.om supplies
4note sh_dat, sh_all, sh_dig, sh_hexd):
5note { printf 'om2\n'; cat seed/ng/sha256.om bridge/shlib/gate.om; } | seed/out/omc > shlib-gate
6note seed/out/omc < bridge/shlib/shlib.om > shlib
7note Run from the repository root: shlib-gate OMC SHLIB SCRATCH
8note OMC the compiler; its sha256 must equal the first word of seed/out/omc.sha256, or nothing runs (exit 69)
9note SHLIB the generator built from bridge/shlib/shlib.om
10note SCRATCH a new directory (created 0700); an existing one is refused (exit 2), and so is a path too long to hold
11note its files within Linux's 4096-byte PATH_MAX
12note Checks, each an exact exit status: OMC compiles, in object mode (0), bridge/shlib/test.om, dep.om and imp.om,
13note the test transport (rmfake.om then nvrmfake.om), libnvidia-ml.so.1's unit (gpu/nvidia/native/nvml's
14note nvml.om, query.om, step.om and errstr.om, then bridge/shlib/nvml.om; errstr.om in its OM-2 view: the
15note whole-word token "at", a reserved word of OM-2 and a parameter name there, becomes "at_" outside note lines)
16note and libomega-ampere-qmd.so.1's unit (gpu/nvidia/om/encoder/amp_runtime.om and amp_qmd.om, then
17note bridge/shlib/ampqmd.om); SHLIB writes each library (test, nvrmfake, nvml, dep, imp, ampqmd) and its probe
18note (0); each probe, run by the system's
19note dynamic loader from the scratch directory (so nvml finds the transport and imp finds dep through $ORIGIN),
20note makes every call row of its table and gets the expected results with x19..x27, x29, d8..d15 and sp
21note preserved (0);
22note /usr/bin/readelf -W -S -d --dyn-syms reads each library through its section headers without a warning,
23note shows the table's soname, every needed library of its table and lists every export of its table (0; readelf
24note is a read-only verification
25note oracle); the test library's wrappers hold four stack probes covering 3, 5, 1 and 2 pages, each fully formed
26note with the wrapper's BL after it (0); each wrapper holds the 10 STP words that save x19..x30 and d8..d15, and
27note the matching LDPs appear outside the wrappers (0); a second build of the test library from the same object holds the
28note same bytes.
29note Controls, each must be caught with its exact status (and, where named, its text in stderr):
30note row a malformed call row (EXPECT 7x) appended to test.tsv: SHLIB refuses it (1, "malformed number")
31note float the export row of omega_shlib_fl (an f64 export in test.om, not in test.tsv) appended to test.tsv:
32note SHLIB refuses it (1, "a float parameter or result")
33note export omega_shlib_div's export row and its call rows removed from the library's table, the probe
34note (built from the full table) still needs it: the loader refuses the probe
35note (127, "undefined symbol: omega_shlib_div")
36note hash every .hash bucket of the test library zeroed: no symbol resolves (127, "undefined symbol: ")
37note expect the first call's EXPECT changed from 7 to 8: the probe reports call 0 (1)
38note stack the shared return's ADD SP, SP, #192 turned into ADD SP, SP, #208, so every call returns with
39note sp 16 bytes high: the probe's stack check reports it (250)
40note extend the wrappers' SXTW X0, W0 and SXTW X1, W1 turned into NOP: omc's int add finds the sum of -3 (zero
41note upper half) and 10 outside int and traps, so call 1 answers 999 for 7 (2)
42note uextend every UXTW (UBFX X, X, #0, #32) turned into NOP: call 9 (a uint with a dirty upper half) fails (10)
43note nextend every UXTB, UXTH, SXTB and SXTH turned into NOP: call 12 (a uchar with dirty upper bits) fails (13)
44note restore the shared return's LDP X19, X20, [SP, #32] turned into [SP, #48]: x19 and x20 come back wrong (250)
45note runtime one trap-entry load LDR X16, [X7, #16] in test.obj turned into [X7, #0], a runtime entry the
46note library does not provide: SHLIB refuses the object (1, "runtime entry")
47note need the private function deep's frame in test.obj made 32 bytes smaller: the export's settled need
48note drops from 16400 to 16368 bytes, so its probe covers 4 pages, not 5: the stack probe check reports
49note it (1); the generator must accept the object
50note address omega_shlib_seven's address in test.obj moved by 2 bytes: SHLIB refuses the object
51note (1, "a function address is outside the code")
52note frestore the shared return's LDP D8, D9, [SP, #128] turned into [SP, #144]: d8 and d9 come back wrong (250)
53note callrec the last call record (edge's) dropped from test.obj: SHLIB refuses it (1, "a BL word has no call
54note record")
55note callto the last call record's destination made omega_shlib_seven: SHLIB refuses it (1, "a call record's
56note destination is not its BL's target")
57note nosave the first wrapper's STP X19, X20, [SP, #32] turned into NOP: the save check reports it (1)
58note readwarn .dynsym's section header sh_entsize made 25: readelf warns and still exits 0 (300)
59note readname omega_shlib_seven renamed omega_shlib_seveN in .dynstr: an export readelf does not list (301)
60note readsoname the soname's first byte in .dynstr made 'L': readelf shows another soname (302)
61note differ a copy of the test library with its last byte changed: the same-bytes check finds a difference (1)
62note x7use omega_shlib_seven's first word in test.obj made STR Q0, [X7]: SHLIB refuses the object
63note (1, "through the per-call context (x7)")
64note slot the first entry slot's B in test.obj one word further: SHLIB refuses the object (1, "an export's
65note entry slot does not branch to its function")
66note map imp.tsv's import row for omega_dep_sub without its swap (s0 s1): the dependency computes 3 - 5, so
67note call 7 fails (8)
68note noneed imp.tsv without its needed row for libomshdep.so.1, the file still beside it: nothing loads it
69note (127, "undefined symbol: omega_dep_")
70note unlock the import library's shared return without its UNLOCK call (its BLR X16 made NOP): the lock stays
71note held, pthread_mutex_trylock refuses call 1, which answers its TRAP value 999 (2)
72note improw an import row for omega_nope appended to imp.tsv: SHLIB refuses it (1, "an import row names no
73note import")
74note frame omega_imp_count's state ImpS dropped from its frame row (1, "a frame export's parameters do not
75note match its row")
76note lockexp omega_imp_live exported without frame in the locked imp.tsv (1, "an export of a locked library is
77note not a frame export")
78note transport libnvidia-ml.so.1 and its probe in a directory without libomega-nvrm.so.1 (127,
79note "libomega-nvrm.so.1")
80note nvinit the composed NVML source with nvmlInit_v2's body made nvmlShutdown's: nvmlInit_v2 (row 3)
81note answers NVML_ERROR_UNINITIALIZED for 0 (4)
82note readneed the import library's needed name in .dynstr made Libomshdep.so.1: readelf shows another needed
83note library (303)
84note stackarg the Ampere QMD library's frame word for the caller's stack arguments pointed at the frame instead
85note (ADD X16, SP, #288 made #96): the accepted build's QMD differs at buf+64 (30)
86note nvcopy the composed NVML source copying text answers from the step state instead of the step buffer:
87note the name's first word differs (10)
88note The extend, uextend, nextend and nosave controls change only the wrappers' words, found through .dynsym.
89note Output: one line per check and control, then OMEGA-SHLIB PASS|FAIL checks=N controls=C caught=K.
90note Exit 0 PASS, 1 FAIL, 2 bad usage or setup, 69 compiler digest refused.
91global g_pin uchar 64
92global g_hx uchar 64
93global g_stb uchar 4
94global g_n ulong 32
95global g_pa uchar 4096
96global g_scr uchar 4096
97global g_omc uchar 4096
98global g_gen uchar 4096
99global g_av uchar 16384
100global g_o uchar 8192
101global g_b uchar *
102global g_c uchar *
103note g_n: 0 path length, 1 omc length, 2 scratch length (with '/'), 3 argv bytes, 4 argc, 5 output length,
104note 6 buffer length, 7 generator length, 8 checks, 11 failures, 12 controls, 13 caught, 14 and 15 the
105note wrappers' range, 16 probe loops found, 17 a probe loop with the wrong page count, 18 wrappers (.dynsym
106note symbols), 19 the composed source's length in g_c
107text t_pin "seed/out/omc.sha256"
108text t_null "/dev/null"
109text t_ttab "bridge/shlib/test.tsv"
110text t_tunit "bridge/shlib/test.om"
111text t_ntab "bridge/shlib/nvml.tsv"
112text t_nunit "bridge/shlib/nvml.om"
113text t_obj "object\n"
114text t_tsrc "test.src"
115text t_tobj "test.obj"
116text t_nsrc "nvml.src"
117text t_nobj "nvml.obj"
118text t_tlib "libomshlib.so.1"
119text t_nlib "libnvidia-ml.so.1"
120text t_tprb "probe"
121text t_nprb "nvprobe"
122text t_again "again.so"
123text t_c1 "c1.tsv"
124text t_c1so "c1.so"
125text t_c2 "c2.tsv"
126text t_d2 "c2"
127text t_c2lib "c2/libomshlib.so.1"
128text t_c2prb "c2/probe"
129text t_d3 "c3"
130text t_c3lib "c3/libomshlib.so.1"
131text t_c3prb "c3/probe"
132text t_c4 "c4.tsv"
133text t_c4prb "probe4"
134text t_d5 "c5"
135text t_c5lib "c5/libomshlib.so.1"
136text t_c5prb "c5/probe"
137text t_d6 "c6"
138text t_c6lib "c6/libomshlib.so.1"
139text t_c6prb "c6/probe"
140text t_d8 "c8"
141text t_c8lib "c8/libomshlib.so.1"
142text t_c8prb "c8/probe"
143text t_d9 "c9"
144text t_c9lib "c9/libomshlib.so.1"
145text t_c9prb "c9/probe"
146text t_c7obj "c7.obj"
147text t_c7so "c7.so"
148text t_relf "/usr/bin/readelf"
149text t_aw "-W"
150text t_as "-S"
151text t_ad "--dyn-syms"
152text t_add "-d"
153text t_exp "export\t"
154text t_son "soname\t"
155text t_lsn "Library soname: ["
156text t_mnum "malformed number"
157text t_udiv "undefined symbol: omega_shlib_div"
158text t_usym "undefined symbol: "
159text t_mrt "runtime entry"
160text t_mobj "not an OMOBJ001"
161text t_maddr "a function address is outside the code"
162text t_mbl "a BL word has no call record"
163text t_mcdst "a call record's destination is not its BL's target"
164text t_mrtw "through the per-call context (x7)"
165text t_mslot "an export's entry slot does not branch to its function"
166text t_tn7 "omega_shlib_seven"
167text t_c14obj "c14.obj"
168text t_c14so "c14.so"
169text t_c15obj "c15.obj"
170text t_c15so "c15.so"
171text t_d16 "c16"
172text t_c16lib "c16/libomshlib.so.1"
173text t_c17so "c17.so"
174text t_c18so "c18.so"
175text t_c19so "c19.so"
176text t_c20so "c20.so"
177text t_c21obj "c21.obj"
178text t_c21so "c21.so"
179text t_c22obj "c22.obj"
180text t_c22so "c22.so"
181text t_c23 "c23.tsv"
182text t_c23so "c23.so"
183text t_flrow "export\tomega_shlib_fl\t0\n"
184text t_mflt "a float parameter or result"
185text t_fgl "FUNC GLOBAL DEFAULT"
186text t_c10obj "c10.obj"
187text t_c10so "c10.so"
188text t_c11obj "c11.obj"
189text t_c11so "c11.so"
190text t_d12 "c12"
191text t_c12lib "c12/libomshlib.so.1"
192text t_c12prb "c12/probe"
193text t_d13 "c13"
194text t_c13lib "c13/libomshlib.so.1"
195text t_c13prb "c13/probe"
196text t_lout "log.out"
197text t_lerr "log.err"
198text t_lib "lib"
199text t_call "call"
200text t_bad "call\tomega_shlib_seven\t7x\n"
201text t_div "export\tomega_shlib_div\t999\n"
202text t_divc "call\tomega_shlib_div\t"
203text t_seven "call\tomega_shlib_seven\t7\n"
204text t_k1 "compile test.om"
205text t_k2 "compile nvml.om"
206text t_k3 "lib test"
207text t_k4 "probe test"
208text t_k5 "run test probe"
209text t_k6 "lib nvml"
210text t_k7 "probe nvml"
211text t_k8 "run nvml probe"
212text t_k9 "lib test again"
213text t_k10 "same bytes"
214text t_k11 "readelf test"
215text t_k12 "readelf nvml"
216text t_k13 "stack probe words"
217text t_k14 "save words"
218text t_x1 "row"
219text t_x2 "export"
220text t_x3 "hash"
221text t_x4 "expect"
222text t_x5 "stack"
223text t_x6 "extend"
224text t_x7 "runtime"
225text t_x8 "uextend"
226text t_x9 "restore"
227text t_x10 "need"
228text t_x11 "address"
229text t_x12 "frestore"
230text t_x13 "nextend"
231text t_x14 "callrec"
232text t_x15 "callto"
233text t_x16 "nosave"
234text t_x17 "readwarn"
235text t_x18 "readname"
236text t_x19 "readsoname"
237text t_x20 "differ"
238text t_x21 "x7use"
239text t_x22 "slot"
240text t_x23 "float"
241text t_x24 "map"
242text t_x25 "noneed"
243text t_x26 "unlock"
244text t_x27 "improw"
245text t_x28 "frame"
246text t_x29 "lockexp"
247text t_x30 "transport"
248text t_x31 "nvinit"
249text t_x32 "readneed"
250text t_c32so "c32.so"
251text t_x33 "stackarg"
252text t_d33 "c33"
253text t_c33lib "c33/libomega-ampere-qmd.so.1"
254text t_c33prb "c33/aqprobe"
255text t_x34 "nvcopy"
256text t_mcr "z = memcpy p add get fr 9 OO n\n"
257text t_c34src "c34.src"
258text t_c34obj "c34.obj"
259text t_d34 "c34"
260text t_c34lib "c34/libnvidia-ml.so.1"
261text t_c34tr "c34/libomega-nvrm.so.1"
262text t_c34prb "c34/nvprobe"
263text t_om2 "om2\n"
264text t_note "note"
265text t_atu "at_"
266text t_nv1 "gpu/nvidia/native/nvml/nvml.om"
267text t_nv2 "gpu/nvidia/native/nvml/query.om"
268text t_nv3 "gpu/nvidia/native/nvml/step.om"
269text t_nv4 "gpu/nvidia/native/nvml/errstr.om"
270text t_fk1 "bridge/shlib/rmfake.om"
271text t_fk2 "bridge/shlib/nvrmfake.om"
272text t_ftab "bridge/shlib/nvrmfake.tsv"
273text t_fsrc "fake.src"
274text t_fobj "fake.obj"
275text t_flib "libomega-nvrm.so.1"
276text t_fprb "fprobe"
277text t_dunit "bridge/shlib/dep.om"
278text t_dtab "bridge/shlib/dep.tsv"
279text t_dsrc "dep.src"
280text t_dobj "dep.obj"
281text t_dlib "libomshdep.so.1"
282text t_dprb "dprobe"
283text t_iunit "bridge/shlib/imp.om"
284text t_itab "bridge/shlib/imp.tsv"
285text t_isrc "imp.src"
286text t_iobj "imp.obj"
287text t_ilib "libomshimp.so.1"
288text t_iprb "iprobe"
289text t_need "needed\t"
290text t_lsl "Shared library: ["
291text t_k15 "compile nvrmfake"
292text t_k16 "compile dep.om"
293text t_k17 "compile imp.om"
294text t_k18 "lib nvrmfake"
295text t_k19 "probe nvrmfake"
296text t_k20 "run nvrmfake probe"
297text t_k21 "lib dep"
298text t_k22 "probe dep"
299text t_k23 "run dep probe"
300text t_k24 "lib imp"
301text t_k25 "probe imp"
302text t_k26 "run imp probe"
303text t_k27 "readelf nvrmfake"
304text t_k28 "readelf dep"
305text t_k29 "readelf imp"
306text t_k30 "compile ampqmd"
307text t_k31 "lib ampqmd"
308text t_k32 "probe ampqmd"
309text t_k33 "run ampqmd probe"
310text t_k34 "readelf ampqmd"
311text t_aq1 "gpu/nvidia/om/encoder/amp_runtime.om"
312text t_aq2 "gpu/nvidia/om/encoder/amp_qmd.om"
313text t_aunit "bridge/shlib/ampqmd.om"
314text t_atab "bridge/shlib/ampqmd.tsv"
315text t_asrc "ampqmd.src"
316text t_aobj "ampqmd.obj"
317text t_alib "libomega-ampere-qmd.so.1"
318text t_aprb "aqprobe"
319text t_mapr "import\tomega_dep_sub\ts1\ts0\n"
320text t_mapw "import\tomega_dep_sub\ts0\ts1\n"
321text t_needr "needed\tlibomshdep.so.1\n"
322text t_nope "import\tomega_nope\ts0\n"
323text t_cntr "export\tomega_imp_count\t999\tframe\tImpS\n"
324text t_cntw "export\tomega_imp_count\t999\tframe\n"
325text t_liver "export\tomega_imp_live\t999\tframe\n"
326text t_livew "export\tomega_imp_live\t999\n"
327text t_initr "ret ap_bare s b r fr 1\n"
328text t_mimp "an import row names no import"
329text t_mfrm "a frame export's parameters do not match its row"
330text t_mlck "an export of a locked library is not a frame export"
331text t_udep "undefined symbol: omega_dep_"
332text t_c24 "c24.tsv"
333text t_d24 "c24"
334text t_c24lib "c24/libomshimp.so.1"
335text t_c24dep "c24/libomshdep.so.1"
336text t_c24prb "c24/iprobe"
337text t_c25 "c25.tsv"
338text t_d25 "c25"
339text t_c25lib "c25/libomshimp.so.1"
340text t_c25dep "c25/libomshdep.so.1"
341text t_c25prb "c25/iprobe"
342text t_d26 "c26"
343text t_c26lib "c26/libomshimp.so.1"
344text t_c26dep "c26/libomshdep.so.1"
345text t_c26prb "c26/iprobe"
346text t_c27 "c27.tsv"
347text t_c27so "c27.so"
348text t_c28 "c28.tsv"
349text t_c28so "c28.so"
350text t_c29 "c29.tsv"
351text t_c29so "c29.so"
352text t_d30 "c30"
353text t_c30lib "c30/libnvidia-ml.so.1"
354text t_c30prb "c30/nvprobe"
355text t_c31src "c31.src"
356text t_c31obj "c31.obj"
357text t_d31 "c31"
358text t_c31lib "c31/libnvidia-ml.so.1"
359text t_c31tr "c31/libomega-nvrm.so.1"
360text t_c31prb "c31/nvprobe"
361text t_ok "ok "
362text t_fail "FAIL "
363text t_ctl "control "
364text t_exit " exit="
365text t_want " expected="
366text t_caught " caught"
367text t_esc " ESCAPED"
368text t_setup " setup failed"
369text t_sum "OMEGA-SHLIB "
370text t_pass "PASS"
371text t_fl "FAIL"
372text t_sk " checks="
373text t_sc " controls="
374text t_scc " caught="
375text t_usage "usage: shlib-gate OMC SHLIB SCRATCH (run from the omega-mv repository root)\n"
376text t_refd "OMEGA-SHLIB REFUSED: compiler digest differs from seed/out/omc.sha256 (exit 69)\n"
377text t_nopin "OMEGA-SHLIB INVALID: cannot read a 64-hex digest from seed/out/omc.sha256\n"
378text t_noscr "OMEGA-SHLIB INVALID: SCRATCH exists or cannot be made\n"
379text t_long "OMEGA-SHLIB INVALID: SCRATCH path too long for its files within PATH_MAX (4096 bytes)\n"
380note ---- output
381fn oc c ulong to void
382n = get g_n 5
383if ge n len g_o
384r = write 1 g_o 0 n
385n = 0
386end
387put g_o n uchar c
388put g_n 5 add n 1
389end
390fn ot t view uchar * to void
391for i ulong len t bound 4096
392oc ulong get t i
393end
394end
395fn onum v ulong to void
396if ge v 10
397onum div v 10
398end
399oc add 48 rem v 10
400end
401fn oflush to void
402r = write 1 g_o 0 get g_n 5
403put g_n 5 0
404end
405note ---- paths: g_pa[0, g_n 0)
406fn pclr to void
407put g_n 0 0
408end
409fn pc c ulong to void
410n = get g_n 0
411put g_pa n uchar c
412put g_n 0 add n 1
413end
414fn pt t view uchar * to void
415for i ulong len t bound 4096
416pc ulong get t i
417end
418end
419note a file in SCRATCH
420fn psc t view uchar * to void
421pclr
422for j ulong get g_n 2 bound 4096
423pc ulong get g_scr j
424end
425pt t
426end
427note a path relative to the repository root
428fn prp t view uchar * to void
429pclr
430pt t
431end
432note ---- files
433fn fopn fl ulong mode ulong to int
434r = fopen g_pa 0 get g_n 0 int fl int mode
435if lt r 0
436ret -1
437end
438ret int r
439end
440fn frd to int
441ret fopn 524288 0
442end
443fn fwr to int
444ret fopn 524865 420
445end
446fn fexe to int
447r = unlink g_pa 0 get g_n 0
448ret fopn 524865 448
449end
450fn fclo fd int to void
451if ge fd 0
452r = fclose fd
453end
454end
455note g_b holds at least n bytes; false when the host refuses the growth
456fn bgrow n ulong to bool
457if le n len g_b
458ret true
459end
460m = mul len g_b 2
461if lt m n
462m = n
463end
464r = enlarge g_b m
465ret ge r 0
466end
467note append the file at g_pa to g_b; false when unreadable or the buffer cannot grow
468fn bload to bool
469fd = frd
470if lt fd 0
471ret false
472end
473n = get g_n 6
474ok = true
475while true bound 9223372036854775807
476if not bgrow add n 65536
477ok = false
478break
479end
480x = read fd g_b n sub len g_b n
481if lt x 0
482ok = false
483break
484end
485if eq x 0
486break
487end
488n = add n ulong x
489end
490fclo fd
491put g_n 6 n
492ret ok
493end
494note write g_b[0, g_n 6) to the file at g_pa (0644, or 0700 when exe)
495fn bsave exe bool to bool
496fd = int -1
497if exe
498fd = fexe
499else
500fd = fwr
501end
502if lt fd 0
503ret false
504end
505n = get g_n 6
506o = ulong 0
507ok = true
508while lt o n bound 9223372036854775807
509x = write fd g_b o sub n o
510if le x 0
511ok = false
512break
513end
514o = add o ulong x
515end
516fclo fd
517ret ok
518end
519note append text t to g_b
520fn bapp t view uchar * to bool
521n = get g_n 6
522if not bgrow add n len t
523ret false
524end
525for i ulong len t bound 4096
526put g_b add n i get t i
527end
528put g_n 6 add n len t
529ret true
530end
531note the first offset of text t in g_b[0, g_n 6), or 2^63 when absent
532fn bfind t view uchar * to ulong
533n = get g_n 6
534if lt n len t
535ret shl ulong 1 63
536end
537for o ulong add sub n len t 1 bound 9223372036854775807
538if bat o t
539ret o
540end
541end
542ret shl ulong 1 63
543end
544fn bat o ulong t view uchar * to bool
545for i ulong len t bound 4096
546if ne get g_b add o i get t i
547ret false
548end
549end
550ret true
551end
552note remove g_b[o, o + k)
553fn bcut o ulong k ulong to void
554n = get g_n 6
555for i ulong sub sub n o k bound 9223372036854775807
556put g_b add o i get g_b add add o k i
557end
558put g_n 6 sub n k
559end
560note the offset just past the newline at or after o in g_b (the buffer's end when there is none)
561fn bnl o ulong to ulong
562n = get g_n 6
563for i ulong sub n o bound 9223372036854775807
564if eq get g_b add o i 10
565ret add add o i 1
566end
567end
568ret n
569end
570note load the file named by the scratch text t into g_b alone; false when unreadable
571fn sload t view uchar * to bool
572put g_n 6 0
573psc t
574ret bload
575end
576fn rload t view uchar * to bool
577put g_n 6 0
578prp t
579ret bload
580end
581note ---- the compiler digest
582fn pinread to bool
583if not rload t_pin
584ret false
585end
586if lt get g_n 6 64
587ret false
588end
589for j ulong 64
590c = get g_b j
591ok = or and ge c 48 le c 57 and ge c 97 le c 102
592if not ok
593ret false
594end
595put g_pin j c
596end
597ret true
598end
599note the sha256 of the file at g_pa, streamed through sh_dat in whole 64-byte blocks (no size limit), equals g_pin
600fn pinok to bool
601fd = frd
602if lt fd 0
603ret false
604end
605sh_init
606for j ulong 8
607put sh_h j get sh_k add j 64
608end
609t = ulong 0
610r = ulong 0
611ok = true
612while true bound 9223372036854775807
613x = read fd sh_dat r sub len sh_dat r
614if lt x 0
615ok = false
616break
617end
618if eq x 0
619break
620end
621t = add t ulong x
622r = gblks add r ulong x
623end
624fclo fd
625if not ok
626ret false
627end
628gfin t r
629for j ulong 32
630b = get sh_dig j
631if ne get g_pin mul j 2 sh_hexd uint shr b 4
632ret false
633end
634if ne get g_pin add mul j 2 1 sh_hexd uint and b 15
635ret false
636end
637end
638ret true
639end
640note hash the whole blocks of sh_dat[0, m), move the rest to the front; its length
641fn gblks m ulong to ulong
642nb = div m 64
643for b ulong nb bound 262144
644sh_blk 0 mul b 64
645end
646r = rem m 64
647o = mul nb 64
648for j ulong r bound 64
649put sh_dat j get sh_dat add o j
650end
651ret r
652end
653note the padding of FIPS 180-4 for a message of n bytes whose last r bytes are sh_dat[0, r); digest into sh_dig
654fn gfin n ulong r ulong to void
655for j ulong 128
656put sh_pad j 0
657end
658for j ulong r bound 64
659put sh_pad j get sh_dat j
660end
661put sh_pad r 128
662e = ulong 64
663if ge r 56
664e = 128
665end
666bits = mul n 8
667for j ulong 8
668put sh_pad sub sub e 1 j uchar and shr bits mul j 8 255
669end
670sh_blk 1 0
671if eq e 128
672sh_blk 1 64
673end
674sh_out
675end
676note ---- processes
677fn aclr to void
678put g_n 3 2
679put g_n 4 0
680put g_av 0 0
681put g_av 1 0
682end
683note append g_pa as one argument
684fn apa to void
685p = get g_n 3
686n = get g_n 0
687for j ulong n bound 4096
688put g_av add add p 2 j get g_pa j
689end
690put g_av p uchar and n 255
691put g_av add p 1 uchar shr n 8
692put g_n 3 add p add n 2
693c = add get g_n 4 1
694put g_n 4 c
695put g_av 0 uchar and c 255
696put g_av 1 uchar shr c 8
697end
698fn atx t view uchar * to void
699prp t
700apa
701end
702fn asc t view uchar * to void
703psc t
704apa
705end
706fn agen to void
707pclr
708for j ulong get g_n 7 bound 4096
709pc ulong get g_gen j
710end
711apa
712end
713fn redir s int d int to void
714if ne dupfd s d 0 long d
715exit 127
716end
717end
718note run the argument list with stdin fi and stdout, stderr in SCRATCH/log.out, log.err: the exit code,
719note 256 + the signal, 512 when a file could not be opened, 1000 when the child passed the 600 s deadline
720fn spawn fi int to ulong
721psc t_lout
722fo = fwr
723psc t_lerr
724fe = fwr
725if or lt fi 0 or lt fo 0 lt fe 0
726fclo fi
727fclo fo
728fclo fe
729ret 512
730end
731pid = fork
732if lt pid 0
733exit 2
734end
735if eq pid 0
736redir fi 0
737redir fo 1
738redir fe 2
739r = execprog g_av 0 get g_n 3
740exit 127
741end
742fclo fi
743fclo fo
744fclo fe
745ret reap pid
746end
747note wait for the child pid: its exit code, 256 + the signal, or 1000 after the 600 s deadline (killed)
748fn reap pid long to ulong
749t0 = monons
750while true bound 1000000000
751r = waitpid int pid g_stb 0 len g_stb 1
752if eq r pid
753x = ulong get g_stb 0
754if ne x 0
755ret add 256 x
756end
757ret ulong get g_stb 1
758end
759if lt r 0
760exit 2
761end
762if gt sub monons t0 600000000000
763r = killpid int pid 9
764r = waitpid int pid g_stb 0 len g_stb 0
765ret 1000
766end
767q = sleepns 200000
768end
769exit 2
770end
771fn run to ulong
772prp t_null
773ret spawn frd
774end
775note OMC < SCRATCH/src > SCRATCH/obj, src being "object" then the unit u
776fn mkobj u view uchar * src view uchar * obj view uchar * to ulong
777put g_n 6 0
778if not bapp t_obj
779ret 512
780end
781prp u
782if not bload
783ret 512
784end
785psc src
786if not bsave false
787ret 512
788end
789ret omcsrc src obj
790end
791note OMC < SCRATCH/src > SCRATCH/obj
792fn omcsrc src view uchar * obj view uchar * to ulong
793psc src
794fi = frd
795aclr
796pclr
797for j ulong get g_n 1 bound 4096
798pc ulong get g_omc j
799end
800apa
801ret spawnto fi obj
802end
803note ---- composed units: g_c[0, g_n 19) is "object", "om2", then each unit in order
804fn cstart to bool
805put g_n 19 0
806ok = cput t_obj
807ret and ok cput t_om2
808end
809fn cbyte c ulong to bool
810n = get g_n 19
811if ge n len g_c
812m = mul len g_c 2
813if lt m 65536
814m = 65536
815end
816r = enlarge g_c m
817if lt r 0
818ret false
819end
820end
821put g_c n uchar c
822put g_n 19 add n 1
823ret true
824end
825fn cput t view uchar * to bool
826for i ulong len t bound 4096
827if not cbyte ulong get t i
828ret false
829end
830end
831ret true
832end
833note append the repository file u; with ren, its om2 view: in each line that is not a note, the whole-word token
834note "at" (a parameter name in errstr.om, a reserved word of OM-2) becomes "at_"
835fn cfile u view uchar * ren bool to bool
836put g_n 6 0
837prp u
838if not bload
839ret false
840end
841n = get g_n 6
842i = ulong 0
843isn = false
844bol = true
845while lt i n bound 9223372036854775807
846if bol
847isn = and le add i len t_note n bat i t_note
848bol = false
849end
850c = ulong get g_b i
851if and not isn attok i n
852if not cput t_atu
853ret false
854end
855i = add i 2
856else
857if not cbyte c
858ret false
859end
860bol = eq c 10
861i = add i 1
862end
863end
864ret true
865end
866note g_b[i, i + 2) is "at" with a space, a newline or the buffer's edge on each side
867fn attok i ulong n ulong to bool
868if or ge add i 1 n or ne get g_b i 97 ne get g_b add i 1 116
869ret false
870end
871if gt i 0
872p = get g_b sub i 1
873if and ne p 32 ne p 10
874ret false
875end
876end
877if lt add i 2 n
878q = get g_b add i 2
879if and ne q 32 ne q 10
880ret false
881end
882end
883ret true
884end
885note g_c saved as the scratch file src, then OMC < src > obj
886fn cdone src view uchar * obj view uchar * to ulong
887n = get g_n 19
888if not bgrow n
889ret 512
890end
891for i ulong n bound 9223372036854775807
892put g_b i get g_c i
893end
894put g_n 6 n
895psc src
896if not bsave false
897ret 512
898end
899ret omcsrc src obj
900end
901note libnvidia-ml.so.1's object: native/nvml's nvml.om, query.om, step.om, errstr.om (its om2 view) and
902note bridge/shlib/nvml.om
903fn mknvml to ulong
904ok = cstart
905ok = and ok cfile t_nv1 false
906ok = and ok cfile t_nv2 false
907ok = and ok cfile t_nv3 false
908ok = and ok cfile t_nv4 true
909ok = and ok cfile t_nunit false
910if not ok
911ret 512
912end
913ret cdone t_nsrc t_nobj
914end
915note the test transport's object: rmfake.om and nvrmfake.om
916fn mkfake to ulong
917ok = cstart
918ok = and ok cfile t_fk1 false
919ok = and ok cfile t_fk2 false
920if not ok
921ret 512
922end
923ret cdone t_fsrc t_fobj
924end
925note the Ampere QMD library's object: amp_runtime.om, amp_qmd.om and bridge/shlib/ampqmd.om
926fn mkampq to ulong
927ok = cstart
928ok = and ok cfile t_aq1 false
929ok = and ok cfile t_aq2 false
930ok = and ok cfile t_aunit false
931if not ok
932ret 512
933end
934ret cdone t_asrc t_aobj
935end
936note as spawn, but stdout into the scratch file obj
937fn spawnto fi int obj view uchar * to ulong
938psc obj
939fo = fwr
940psc t_lerr
941fe = fwr
942if or lt fi 0 or lt fo 0 lt fe 0
943fclo fi
944fclo fo
945fclo fe
946ret 512
947end
948pid = fork
949if lt pid 0
950exit 2
951end
952if eq pid 0
953redir fi 0
954redir fo 1
955redir fe 2
956r = execprog g_av 0 get g_n 3
957exit 127
958end
959fclo fi
960fclo fo
961fclo fe
962ret reap pid
963end
964note SHLIB lib TABLE OBJ OUT; tr is TABLE relative to the repository root, else to SCRATCH; OBJ is test.obj
965note when ob is 0, nvml.obj when 1, the controls' c7.obj (runtime), c10.obj (need) or c11.obj (address) for 2..4
966fn genlib tab view uchar * tr bool ob ulong dst view uchar * to ulong
967aclr
968agen
969atx t_lib
970if tr
971atx tab
972else
973asc tab
974end
975obsel ob
976asc dst
977ret run
978end
979note the object genlib names: test.obj for 0, nvml.obj for 1, the controls' c7, c10, c11, c14, c15 for 2..6
980fn obsel ob ulong to void
981if eq ob 1
982asc t_nobj
983ret
984end
985if eq ob 2
986asc t_c7obj
987ret
988end
989if eq ob 3
990asc t_c10obj
991ret
992end
993if eq ob 4
994asc t_c11obj
995ret
996end
997if eq ob 5
998asc t_c14obj
999ret
1000end
1001if eq ob 6
1002asc t_c15obj
1003ret
1004end
1005if eq ob 7
1006asc t_c21obj
1007ret
1008end
1009if eq ob 8
1010asc t_c22obj
1011ret
1012end
1013if eq ob 9
1014asc t_fobj
1015ret
1016end
1017if eq ob 10
1018asc t_dobj
1019ret
1020end
1021if eq ob 11
1022asc t_iobj
1023ret
1024end
1025if eq ob 12
1026asc t_c31obj
1027ret
1028end
1029if eq ob 13
1030asc t_aobj
1031ret
1032end
1033if eq ob 14
1034asc t_c34obj
1035ret
1036end
1037asc t_tobj
1038end
1039fn gencall tab view uchar * tr bool dst view uchar * to ulong
1040aclr
1041agen
1042atx t_call
1043if tr
1044atx tab
1045else
1046asc tab
1047end
1048asc dst
1049ret run
1050end
1051fn runprb prb view uchar * to ulong
1052aclr
1053asc prb
1054ret run
1055end
1056note ---- results
1057fn check what view uchar * got ulong want ulong to void
1058put g_n 8 add get g_n 8 1
1059if eq got want
1060ot t_ok
1061else
1062put g_n 11 add get g_n 11 1
1063ot t_fail
1064end
1065ot what
1066ot t_exit
1067onum got
1068if ne got want
1069ot t_want
1070onum want
1071end
1072oc 10
1073end
1074fn ctl what view uchar * got ulong want ulong to void
1075ctlx what got want eq got want
1076end
1077note a control caught when its status is want and the scratch log.err holds t
1078fn ctle what view uchar * got ulong want ulong t view uchar * to void
1079ok = and eq got want errhas t
1080ctlx what got want ok
1081end
1082fn errhas t view uchar * to bool
1083if not sload t_lerr
1084ret false
1085end
1086ret lt bfind t shl ulong 1 63
1087end
1088fn ctlx what view uchar * got ulong want ulong ok bool to void
1089put g_n 12 add get g_n 12 1
1090ot t_ctl
1091ot what
1092if ok
1093put g_n 13 add get g_n 13 1
1094ot t_caught
1095else
1096ot t_esc
1097end
1098ot t_exit
1099onum got
1100if ne got want
1101ot t_want
1102onum want
1103end
1104oc 10
1105end
1106note a control whose setup failed: counted, never caught
1107fn csetup what view uchar * to void
1108put g_n 12 add get g_n 12 1
1109ot t_ctl
1110ot what
1111ot t_setup
1112oc 10
1113end
1114fn mkd t view uchar * to bool
1115psc t
1116ret eq makedir g_pa 0 get g_n 0 448 0
1117end
1118note copy the scratch file a to the scratch file b (0700)
1119fn cpexe a view uchar * b view uchar * to bool
1120if not sload a
1121ret false
1122end
1123psc b
1124ret bsave true
1125end
1126note ---- the checks
1127fn checks to void
1128check t_k1 mkobj t_tunit t_tsrc t_tobj 0
1129check t_k2 mknvml 0
1130check t_k15 mkfake 0
1131check t_k16 mkobj t_dunit t_dsrc t_dobj 0
1132check t_k17 mkobj t_iunit t_isrc t_iobj 0
1133check t_k30 mkampq 0
1134check t_k3 genlib t_ttab true 0 t_tlib 0
1135check t_k4 gencall t_ttab true t_tprb 0
1136check t_k5 runprb t_tprb 0
1137check t_k18 genlib t_ftab true 9 t_flib 0
1138check t_k19 gencall t_ftab true t_fprb 0
1139check t_k20 runprb t_fprb 0
1140check t_k6 genlib t_ntab true 1 t_nlib 0
1141check t_k7 gencall t_ntab true t_nprb 0
1142check t_k8 runprb t_nprb 0
1143check t_k21 genlib t_dtab true 10 t_dlib 0
1144check t_k22 gencall t_dtab true t_dprb 0
1145check t_k23 runprb t_dprb 0
1146check t_k24 genlib t_itab true 11 t_ilib 0
1147check t_k25 gencall t_itab true t_iprb 0
1148check t_k26 runprb t_iprb 0
1149check t_k31 genlib t_atab true 13 t_alib 0
1150check t_k32 gencall t_atab true t_aprb 0
1151check t_k33 runprb t_aprb 0
1152check t_k11 relf t_ttab t_tlib 0
1153check t_k12 relf t_ntab t_nlib 0
1154check t_k27 relf t_ftab t_flib 0
1155check t_k28 relf t_dtab t_dlib 0
1156check t_k29 relf t_itab t_ilib 0
1157check t_k34 relf t_atab t_alib 0
1158check t_k13 pchk t_tlib 0
1159check t_k14 schk t_tlib 0
1160check t_k9 genlib t_ttab true 0 t_again 0
1161s = ulong 1
1162if same2 t_tlib t_again
1163s = 0
1164end
1165check t_k10 s 0
1166end
1167note readelf -W -S -d --dyn-syms on the scratch library lib: 0 when it exits 0 with nothing on stderr, lists
1168note every export of the table tab (at least one), shows its soname and every needed library; else its status,
1169note 300 (stderr not empty), 301 (an export not listed), 302 (soname) or 303 (a needed library)
1170fn relf tab view uchar * lib view uchar * to ulong
1171aclr
1172prp t_relf
1173apa
1174prp t_aw
1175apa
1176prp t_as
1177apa
1178prp t_ad
1179apa
1180prp t_add
1181apa
1182asc lib
1183r = run
1184if ne r 0
1185ret r
1186end
1187if not sload t_lerr
1188ret 300
1189end
1190if ne get g_n 6 0
1191ret 300
1192end
1193if not sload t_lout
1194ret 301
1195end
1196m = get g_n 6
1197prp tab
1198if not bload
1199ret 301
1200end
1201if not allexp m
1202ret 301
1203end
1204if not sonok m
1205ret 302
1206end
1207if not needok m
1208ret 303
1209end
1210ret 0
1211end
1212note the table in g_b[m, g_n 6) has a "soname\tNAME" line and g_b[0, m) has "Library soname: [NAME]"
1213fn sonok m ulong to bool
1214o = m
1215while lt o get g_n 6 bound 9223372036854775807
1216e = bnl o
1217if bat o t_son
1218s = add o len t_son
1219l = ulong 0
1220while gt get g_b add s l 32 bound 9223372036854775807
1221l = add l 1
1222end
1223ret sfind s l m t_lsn
1224end
1225o = e
1226end
1227ret false
1228end
1229fn sfind s ulong l ulong m ulong p view uchar * to bool
1230for i ulong m bound 9223372036854775807
1231if bat i p
1232a = add i len p
1233if and bsame a s l eq get g_b add a l 93
1234ret true
1235end
1236end
1237end
1238ret false
1239end
1240note every "needed\tNAME" line of the table in g_b[m, g_n 6) has "Shared library: [NAME]" in g_b[0, m)
1241fn needok m ulong to bool
1242o = m
1243while lt o get g_n 6 bound 9223372036854775807
1244e = bnl o
1245if and le add o len t_need get g_n 6 bat o t_need
1246s = add o len t_need
1247l = ulong 0
1248while gt get g_b add s l 32 bound 9223372036854775807
1249l = add l 1
1250end
1251if not sfind s l m t_lsl
1252ret false
1253end
1254end
1255o = e
1256end
1257ret true
1258end
1259note every "export\tNAME\t" line of the table in g_b[m, g_n 6) has NAME then a newline in g_b[0, m), and there
1260note is at least one such line
1261fn allexp m ulong to bool
1262o = m
1263n = ulong 0
1264while lt o get g_n 6 bound 9223372036854775807
1265e = bnl o
1266if expat o
1267s = add o len t_exp
1268l = ulong 0
1269while ne get g_b add s l 9 bound 9223372036854775807
1270l = add l 1
1271end
1272if not bline s l m
1273ret false
1274end
1275n = add n 1
1276end
1277o = e
1278end
1279ret gt n 0
1280end
1281fn expat o ulong to bool
1282if gt add o len t_exp get g_n 6
1283ret false
1284end
1285ret bat o t_exp
1286end
1287note g_b[s, s + l) occurs in g_b[0, m) as a whole readelf symbol line's name: a space before it, a newline after
1288note it, and "FUNC GLOBAL DEFAULT" earlier on its line
1289fn bline s ulong l ulong m ulong to bool
1290if lt m add l 2
1291ret false
1292end
1293for i ulong sub sub m l 1 bound 9223372036854775807
1294o = add i 1
1295if and bsame o s l eq get g_b add o l 10
1296if and eq get g_b i 32 fglob o
1297ret true
1298end
1299end
1300end
1301ret false
1302end
1303note the line holding g_b[o] has "FUNC GLOBAL DEFAULT" before o
1304fn fglob o ulong to bool
1305a = o
1306while and gt a 0 ne get g_b sub a 1 10 bound 9223372036854775807
1307a = sub a 1
1308end
1309if lt sub o a len t_fgl
1310ret false
1311end
1312for i ulong add sub sub o a len t_fgl 1 bound 9223372036854775807
1313if bat add a i t_fgl
1314ret true
1315end
1316end
1317ret false
1318end
1319fn bsame a ulong s ulong l ulong to bool
1320for i ulong l bound 9223372036854775807
1321if ne get g_b add a i get g_b add s i
1322ret false
1323end
1324end
1325ret true
1326end
1327note the scratch files a and b hold the same bytes
1328fn same2 a view uchar * b view uchar * to bool
1329if not sload a
1330ret false
1331end
1332n = get g_n 6
1333psc b
1334if not bload
1335ret false
1336end
1337if ne sub get g_n 6 n n
1338ret false
1339end
1340for i ulong n bound 9223372036854775807
1341if ne get g_b i get g_b add n i
1342ret false
1343end
1344end
1345ret true
1346end
1347note ---- the controls
1348fn crow to void
1349if not rload t_ttab
1350csetup t_x1
1351ret
1352end
1353if not bapp t_bad
1354csetup t_x1
1355ret
1356end
1357psc t_c1
1358if not bsave false
1359csetup t_x1
1360ret
1361end
1362r = genlib t_c1 false 0 t_c1so
1363ctle t_x1 r 1 t_mnum
1364end
1365note the table with the float export omega_shlib_fl (in test.om, not in test.tsv) appended: SHLIB refuses it
1366fn cfloat to void
1367if not rload t_ttab
1368csetup t_x23
1369ret
1370end
1371if not bapp t_flrow
1372csetup t_x23
1373ret
1374end
1375psc t_c23
1376if not bsave false
1377csetup t_x23
1378ret
1379end
1380r = genlib t_c23 false 0 t_c23so
1381ctle t_x23 r 1 t_mflt
1382end
1383fn cexport to void
1384if not rload t_ttab
1385csetup t_x2
1386ret
1387end
1388o = bfind t_div
1389if ge o shl ulong 1 63
1390csetup t_x2
1391ret
1392end
1393bcut o len t_div
1394o = bfind t_divc
1395while lt o shl ulong 1 63 bound 4096
1396bcut o sub bnl o o
1397o = bfind t_divc
1398end
1399psc t_c2
1400ok = bsave false
1401ok = and ok mkd t_d2
1402ok = and ok eq genlib t_c2 false 0 t_c2lib 0
1403ok = and ok eq gencall t_ttab true t_c2prb 0
1404if not ok
1405csetup t_x2
1406ret
1407end
1408r = runprb t_c2prb
1409ctle t_x2 r 127 t_udiv
1410end
1411fn chash to void
1412ok = mkd t_d3
1413ok = and ok sload t_tlib
1414if not ok
1415csetup t_x3
1416ret
1417end
1418note SysV .hash at 288: nbucket (u32), nchain (u32), then the buckets
1419nb = or ulong get g_b 288 shl ulong get g_b 289 8
1420for i ulong mul nb 4 bound 65536
1421put g_b add 296 i 0
1422end
1423psc t_c3lib
1424ok = bsave false
1425ok = and ok cpexe t_tprb t_c3prb
1426if not ok
1427csetup t_x3
1428ret
1429end
1430r = runprb t_c3prb
1431ctle t_x3 r 127 t_usym
1432end
1433fn cexpect to void
1434if not rload t_ttab
1435csetup t_x4
1436ret
1437end
1438o = bfind t_seven
1439if ge o shl ulong 1 63
1440csetup t_x4
1441ret
1442end
1443put g_b sub add o len t_seven 2 56
1444psc t_c4
1445ok = bsave false
1446ok = and ok eq gencall t_c4 false t_c4prb 0
1447if not ok
1448csetup t_x4
1449ret
1450end
1451ctl t_x4 runprb t_c4prb 1
1452end
1453fn cstack to void
1454ok = mkd t_d5
1455ok = and ok sload t_tlib
1456if not ok
1457csetup t_x5
1458ret
1459end
1460note the first ADD SP, SP, #192 (0x910303ff, bytes ff 03 03 91) is the shared return's; byte 1 0x43 makes
1461note the immediate 208
1462o = bfind4 255 3 3 145
1463if ge o shl ulong 1 63
1464csetup t_x5
1465ret
1466end
1467put g_b add o 1 67
1468psc t_c5lib
1469ok = bsave false
1470ok = and ok cpexe t_tprb t_c5prb
1471if not ok
1472csetup t_x5
1473ret
1474end
1475ctl t_x5 runprb t_c5prb 250
1476end
1477note make the scratch directory dir and load the test library into g_b
1478fn tload dir view uchar * to bool
1479ok = mkd dir
1480ret and ok sload t_tlib
1481end
1482note the wrappers' range of the library in g_b, from its .dynsym (the lowest symbol value, the highest value plus
1483note size) into g_n 14 and 15; false when there is no .dynsym
1484fn wrange to bool
1485so = bq 40
1486put g_n 14 shl ulong 1 63
1487put g_n 15 0
1488put g_n 18 0
1489for i ulong bh 60 bound 65536
1490h = add so mul i 64
1491if eq bh add h 4 11
1492symr bq add h 24 bq add h 32
1493end
1494end
1495ret and gt get g_n 15 0 le get g_n 15 get g_n 6
1496end
1497fn symr o ulong n ulong to void
1498for k ulong div n 24 bound 9223372036854775807
1499e = add o mul k 24
1500v = bq add e 8
1501if ne v 0
1502put g_n 18 add get g_n 18 1
1503if lt v get g_n 14
1504put g_n 14 v
1505end
1506if gt add v bq add e 16 get g_n 15
1507put g_n 15 add v bq add e 16
1508end
1509end
1510end
1511end
1512note the u64 and the u16 of g_b at o; 0 when they reach past the loaded bytes (g_n 6), so a damaged or missing
1513note library makes a check fail instead of reading stale bytes or past the buffer
1514fn bq o ulong to ulong
1515if or gt o get g_n 6 gt add o 8 get g_n 6
1516ret 0
1517end
1518v = ulong 0
1519for i ulong 8
1520v = or v shl ulong get g_b add o i mul i 8
1521end
1522ret v
1523end
1524fn bh o ulong to ulong
1525if or gt o get g_n 6 gt add o 2 get g_n 6
1526ret 0
1527end
1528ret or ulong get g_b o shl ulong get g_b add o 1 8
1529end
1530note turn every 4-aligned word w inside the wrappers into NOP (0xd503201f); how many
1531fn nopw w ulong to ulong
1532k = ulong 0
1533if not wrange
1534ret 0
1535end
1536for i ulong div sub get g_n 15 get g_n 14 4 bound 9223372036854775807
1537o = add get g_n 14 mul i 4
1538if eq bw o w
1539put g_b o 31
1540put g_b add o 1 32
1541put g_b add o 2 3
1542put g_b add o 3 213
1543k = add k 1
1544end
1545end
1546ret k
1547end
1548note save g_b as the scratch library lib, copy the probe to prb and run it: its status, or 512 on a setup failure
1549fn tsave lib view uchar * prb view uchar * to ulong
1550psc lib
1551ok = bsave false
1552ok = and ok cpexe t_tprb prb
1553if not ok
1554ret 512
1555end
1556ret runprb prb
1557end
1558fn cext to void
1559note SXTW X0, W0 is 0x93407c00 (bytes 00 7c 40 93) and SXTW X1, W1 0x93407c21: add's and div's arguments
1560ok = tload t_d6
1561k = nopw 2470476800
1562k = add k nopw 2470476833
1563if or not ok eq k 0
1564csetup t_x6
1565ret
1566end
1567ctl t_x6 tsave t_c6lib t_c6prb 2
1568end
1569fn cuext to void
1570note UXTW X0, W0 (UBFX X0, X0, #0, #32) is 0xd3407c00 (bytes 00 7c 40 d3): hi's argument
1571ok = tload t_d8
1572k = nopw 3544218624
1573if or not ok eq k 0
1574csetup t_x8
1575ret
1576end
1577ctl t_x8 tsave t_c8lib t_c8prb 10
1578end
1579fn cnext to void
1580note UXTB X0 0xd3401c00, UXTH X0 0xd3403c00, SXTB X0 0x93401c00, SXTH X0 0x93403c00: the narrow calls' arguments
1581ok = tload t_d13
1582k = nopw 3544194048
1583k = add k nopw 3544202240
1584k = add k nopw 2470452224
1585k = add k nopw 2470460416
1586if or not ok ne k 4
1587csetup t_x13
1588ret
1589end
1590ctl t_x13 tsave t_c13lib t_c13prb 13
1591end
1592fn cnosave to void
1593note STP X19, X20, [SP, #32] is 0xa90253f3 (bytes f3 53 02 a9); its first occurrence (the first wrapper's) turned
1594note into NOP: the save check reports it
1595ok = tload t_d16
1596o = bfind4 243 83 2 169
1597if or not ok ge o shl ulong 1 63
1598csetup t_x16
1599ret
1600end
1601put g_b o 31
1602put g_b add o 1 32
1603put g_b add o 2 3
1604put g_b add o 3 213
1605psc t_c16lib
1606if not bsave false
1607csetup t_x16
1608ret
1609end
1610ctl t_x16 schk t_c16lib 1
1611end
1612fn crestore to void
1613ok = mkd t_d9
1614ok = and ok sload t_tlib
1615if not ok
1616csetup t_x9
1617ret
1618end
1619note LDP X19, X20, [SP, #32] is 0xa94253f3 (bytes f3 53 42 a9), first in the shared return; byte 2 0x43
1620note makes the offset 48
1621o = bfind4 243 83 66 169
1622if ge o shl ulong 1 63
1623csetup t_x9
1624ret
1625end
1626put g_b add o 2 67
1627psc t_c9lib
1628ok = bsave false
1629ok = and ok cpexe t_tprb t_c9prb
1630if not ok
1631csetup t_x9
1632ret
1633end
1634ctl t_x9 runprb t_c9prb 250
1635end
1636fn cruntime to void
1637if not sload t_tobj
1638csetup t_x7
1639ret
1640end
1641note LDR X16, [X7, #16] is 0xf94008f0 (bytes f0 08 40 f9); byte 1 0 makes it [X7, #0]
1642o = bfind4 240 8 64 249
1643if ge o shl ulong 1 63
1644csetup t_x7
1645ret
1646end
1647put g_b add o 1 0
1648psc t_c7obj
1649if not bsave false
1650csetup t_x7
1651ret
1652end
1653r = genlib t_ttab true 2 t_c7so
1654ctle t_x7 r 1 t_mrt
1655end
1656note the stack probe check on the scratch library lib: 0 when its wrappers hold exactly four probes, each
1657note ADD X16, SP, #16; MOVZ X17, #pages; MOVK X17, #0, LSL #16; MOVK X17, #0, LSL #32; the loop, with the
1658note wrapper's BL after it, covering 3, 5, 1 and 2 pages in that order (sum, deep, pdiv, edge: edge's 2 holds
1659note only with the call cost counted); 1 otherwise, 512 unreadable
1660fn pchk lib view uchar * to ulong
1661if not sload lib
1662ret 512
1663end
1664if not wrange
1665ret 512
1666end
1667put g_n 16 0
1668put g_n 17 0
1669for i ulong div sub get g_n 15 get g_n 14 4 bound 9223372036854775807
1670pone add get g_n 14 mul i 4
1671end
1672if and eq get g_n 17 0 eq get g_n 16 4
1673ret 0
1674end
1675ret 1
1676end
1677note one word of the wrappers: a probe loop at o counts in g_n 16; a wrong probe around it sets g_n 17
1678fn pone o ulong to void
1679if not ploop o
1680ret
1681end
1682k = add get g_n 16 1
1683put g_n 16 k
1684if not pfix o k
1685put g_n 17 1
1686end
1687end
1688note the four words before the loop at o and a BL after it, for the k-th probe
1689fn pfix o ulong k ulong to bool
1690ok = and eq bw sub o 16 2432713712 eq bw sub o 12 pwant k
1691ok = and ok and eq bw sub o 8 4070572049 eq bw sub o 4 4072669201
1692ret and ok blafter add o 16
1693end
1694note a BL comes at or after o before the next wrapper (its SUB SP, SP, #192) or the wrappers' end
1695fn blafter o ulong to bool
1696for i ulong div sub get g_n 15 o 4 bound 9223372036854775807
1697w = bw add o mul i 4
1698if eq shr w 26 37
1699ret true
1700end
1701if eq w 3506635775
1702ret false
1703end
1704end
1705ret false
1706end
1707note the MOVZ X17 the k-th probe must hold: #3, #5, #1, then #2
1708fn pwant k ulong to ulong
1709if eq k 1
1710ret 3531604081
1711end
1712if eq k 2
1713ret 3531604145
1714end
1715if eq k 3
1716ret 3531604017
1717end
1718ret 3531604049
1719end
1720note g_b at o holds the probe loop SUB X16, X16, #1, LSL #12; LDR XZR, [X16]; SUBS X17, X17, #1; B.NE loop
1721fn ploop o ulong to bool
1722if gt add o 16 get g_n 6
1723ret false
1724end
1725ok = and eq bw o 3510634000 eq bw add o 4 4181721631
1726ret and ok and eq bw add o 8 4043310641 eq bw add o 12 1426063265
1727end
1728note the u32 of g_b at o
1729fn bw o ulong to ulong
1730ret or bh o shl bh add o 2 16
1731end
1732note the save check on the scratch library lib: each of the 10 STP words that save x19..x30 and d8..d15 at
1733note [sp, #32..176] occurs once per wrapper inside the wrappers, and each matching LDP occurs outside them
1734note (the shared return); 0, 1 otherwise, 512 when unreadable
1735fn schk lib view uchar * to ulong
1736if not sload lib
1737ret 512
1738end
1739if not wrange
1740ret 512
1741end
1742for i ulong 10
1743s = svw i
1744if ne wcnt s get g_n 14 get g_n 15 get g_n 18
1745ret 1
1746end
1747l = add s 4194304
1748if eq sub wcnt l 0 get g_n 6 wcnt l get g_n 14 get g_n 15 0
1749ret 1
1750end
1751end
1752ret 0
1753end
1754note STP X(19+2i), X(20+2i), [SP, #32+16i] for i 0..5, then STP D(8+2j), D(9+2j), [SP, #128+16j]
1755fn svw i ulong to ulong
1756if lt i 6
1757ret add 2835502067 mul i 67586
1758end
1759ret add 1829251048 mul sub i 6 67586
1760end
1761note how many 4-aligned words in g_b[a, b) equal w
1762fn wcnt w ulong a ulong b ulong to ulong
1763n = ulong 0
1764for i ulong div sub b a 4 bound 9223372036854775807
1765if eq bw add a mul i 4 w
1766n = add n 1
1767end
1768end
1769ret n
1770end
1771note write the u64 v at g_b[a]
1772fn bput8 a ulong v ulong to void
1773for i ulong 8
1774put g_b add a i uchar and shr v mul i 8 255
1775end
1776end
1777fn cneed to void
1778if not sload t_tobj
1779csetup t_x10
1780ret
1781end
1782o = privf
1783if ge o shl ulong 1 63
1784csetup t_x10
1785ret
1786end
1787a = add o 32
1788bput8 a sub bq a 32
1789psc t_c10obj
1790if not bsave false
1791csetup t_x10
1792ret
1793end
1794if ne genlib t_ttab true 3 t_c10so 0
1795csetup t_x10
1796ret
1797end
1798ctl t_x10 pchk t_c10so 1
1799end
1800note the object offset of test.obj's one private function record (flags 0), or 2^63; a record is flags,
1801note address, result, parameter count, stack, name length (u64 each), the name padded to 8 bytes, then 40 bytes
1802note per parameter
1803fn privf to ulong
1804o = bq 40
1805for i ulong bq 48 bound 65536
1806if eq bq o 0
1807ret o
1808end
1809o = add add o 48 add and add bq add o 40 7 not ulong 7 mul bq add o 24 40
1810end
1811ret shl ulong 1 63
1812end
1813fn caddr to void
1814note the first function record sits at the code end C (object offset 40); its address is 8 bytes in
1815if not sload t_tobj
1816csetup t_x11
1817ret
1818end
1819a = add bq 40 8
1820put g_b a uchar add get g_b a 2
1821psc t_c11obj
1822if not bsave false
1823csetup t_x11
1824ret
1825end
1826r = genlib t_ttab true 4 t_c11so
1827ctle t_x11 r 1 t_maddr
1828end
1829fn ccrec to void
1830note the last call record (edge's) dropped: header word 56 one less, the object 32 bytes shorter
1831if not sload t_tobj
1832csetup t_x14
1833ret
1834end
1835bput8 56 sub bq 56 1
1836put g_n 6 sub get g_n 6 32
1837psc t_c14obj
1838if not bsave false
1839csetup t_x14
1840ret
1841end
1842r = genlib t_ttab true 5 t_c14so
1843ctle t_x14 r 1 t_mbl
1844end
1845fn ccto to void
1846note the last call record's destination (16 bytes before the end) made function 0, omega_shlib_seven
1847if not sload t_tobj
1848csetup t_x15
1849ret
1850end
1851bput8 sub get g_n 6 16 0
1852psc t_c15obj
1853if not bsave false
1854csetup t_x15
1855ret
1856end
1857r = genlib t_ttab true 6 t_c15so
1858ctle t_x15 r 1 t_mcdst
1859end
1860note readelf's three refusals, each from one change to the test library: .dynsym's sh_entsize made 25 (readelf
1861note warns on stderr and still exits 0: 300), omega_shlib_seven renamed omega_shlib_seveN in .dynstr (an export
1862note not listed: 301), the soname's first byte made 'L' (302)
1863fn crelf to void
1864ok = sload t_tlib
1865so = bq 40
1866h = ulong 0
1867for i ulong bh 60 bound 65536
1868if eq bh add add so mul i 64 4 11
1869h = add so mul i 64
1870end
1871end
1872if or not ok eq h 0
1873csetup t_x17
1874else
1875put g_b add h 56 25
1876psc t_c17so
1877if bsave false
1878ctl t_x17 relf t_ttab t_c17so 300
1879else
1880csetup t_x17
1881end
1882end
1883cname
1884csoname
1885end
1886fn cname to void
1887o = rfind t_tn7
1888if ge o shl ulong 1 63
1889csetup t_x18
1890ret
1891end
1892put g_b add o 16 78
1893ctl t_x18 rsave t_c18so 301
1894end
1895fn csoname to void
1896o = rfind t_tlib
1897if ge o shl ulong 1 63
1898csetup t_x19
1899ret
1900end
1901put g_b o 76
1902ctl t_x19 rsave t_c19so 302
1903end
1904note the import library with its needed name libomshdep.so.1 in .dynstr made Libomshdep.so.1: readelf shows
1905note another needed library (303)
1906fn cneedname to void
1907o = shl ulong 1 63
1908if sload t_ilib
1909o = bfindt t_dlib
1910end
1911if ge o shl ulong 1 63
1912csetup t_x32
1913ret
1914end
1915put g_b o 76
1916psc t_c32so
1917if not bsave false
1918csetup t_x32
1919ret
1920end
1921ctl t_x32 relf t_itab t_c32so 303
1922end
1923note the test library loaded into g_b, then the first offset holding text t (2^63 when unreadable or absent)
1924fn rfind t view uchar * to ulong
1925if not sload t_tlib
1926ret shl ulong 1 63
1927end
1928ret bfindt t
1929end
1930note g_b saved as the scratch file so, then readelf's answer on it (513 when it cannot be saved)
1931fn rsave so view uchar * to ulong
1932psc so
1933if not bsave false
1934ret 513
1935end
1936ret relf t_ttab so
1937end
1938note the first offset of g_b holding text t, or 2^63
1939fn bfindt t view uchar * to ulong
1940if lt get g_n 6 len t
1941ret shl ulong 1 63
1942end
1943for i ulong add sub get g_n 6 len t 1 bound 9223372036854775807
1944if bat i t
1945ret i
1946end
1947end
1948ret shl ulong 1 63
1949end
1950note the same-bytes check against a copy of the test library with its last byte changed: it must differ
1951fn cdiffer to void
1952if not sload t_tlib
1953csetup t_x20
1954ret
1955end
1956n = sub get g_n 6 1
1957put g_b n uchar and add get g_b n 1 255
1958psc t_c20so
1959if not bsave false
1960csetup t_x20
1961ret
1962end
1963s = ulong 1
1964if same2 t_tlib t_c20so
1965s = 0
1966end
1967ctl t_x20 s 1
1968end
1969note test.obj with omega_shlib_seven's first word made STR Q0, [X7] (0x3d8000e0, bytes e0 00 80 3d): the
1970note generator refuses a base-register use of x7
1971fn cx7use to void
1972if not sload t_tobj
1973csetup t_x21
1974ret
1975end
1976a = bq add bq 40 8
1977put g_b a 224
1978put g_b add a 1 0
1979put g_b add a 2 128
1980put g_b add a 3 61
1981ctle t_x21 osave t_c21obj 7 t_c21so 1 t_mrtw
1982end
1983note test.obj with the first entry slot's B one word further: its slot no longer branches to its function
1984fn cslot to void
1985if not sload t_tobj
1986csetup t_x22
1987ret
1988end
1989put g_b 176 uchar add get g_b 176 1
1990ctle t_x22 osave t_c22obj 8 t_c22so 1 t_mslot
1991end
1992note g_b saved as the scratch object obj, then the generator's status on it (object k of genlib) into so; 513
1993note when it cannot be saved
1994fn osave obj view uchar * k ulong so view uchar * to ulong
1995psc obj
1996if not bsave false
1997ret 513
1998end
1999ret genlib t_ttab true k so
2000end
2001fn cfrest to void
2002note LDP D8, D9, [SP, #128] is 0x6d4827e8 (bytes e8 27 48 6d), first in the shared return; byte 2 0x49
2003note makes the offset 144
2004ok = tload t_d12
2005o = bfind4 232 39 72 109
2006if or not ok ge o shl ulong 1 63
2007csetup t_x12
2008ret
2009end
2010put g_b add o 2 73
2011ctl t_x12 tsave t_c12lib t_c12prb 250
2012end
2013note g_b[o] is v
2014fn bis o ulong v ulong to bool
2015ret eq ulong get g_b o v
2016end
2017note the first 4-aligned offset of the bytes a b c d in g_b, or 2^63
2018fn bfind4 a ulong b ulong c ulong d ulong to ulong
2019n = div get g_n 6 4
2020for i ulong n bound 9223372036854775807
2021o = mul i 4
2022ok = and bis o a bis add o 1 b
2023ok = and ok and bis add o 2 c bis add o 3 d
2024if ok
2025ret o
2026end
2027end
2028ret shl ulong 1 63
2029end
2030note ---- import, lock and NVML controls
2031note insert text t at g_b[o]
2032fn bins o ulong t view uchar * to bool
2033n = get g_n 6
2034if not bgrow add n len t
2035ret false
2036end
2037k = len t
2038for i ulong sub n o bound 9223372036854775807
2039s = sub sub n i 1
2040put g_b add s k get g_b s
2041end
2042for i ulong len t bound 4096
2043put g_b add o i get t i
2044end
2045put g_n 6 add n len t
2046ret true
2047end
2048note imp.tsv with the line a cut, saved as the scratch file f; false when a is absent
2049fn tcut a view uchar * f view uchar * to bool
2050if not rload t_itab
2051ret false
2052end
2053o = bfind a
2054if ge o shl ulong 1 63
2055ret false
2056end
2057bcut o len a
2058psc f
2059ret bsave false
2060end
2061note imp.tsv with the line a replaced by b, saved as the scratch file f; false when a is absent
2062fn tmut a view uchar * b view uchar * f view uchar * to bool
2063if not rload t_itab
2064ret false
2065end
2066o = bfind a
2067if ge o shl ulong 1 63
2068ret false
2069end
2070bcut o len a
2071if not bins o b
2072ret false
2073end
2074psc f
2075ret bsave false
2076end
2077note the directory d with the import library from the scratch table tab and copies of the dependency library
2078note and the import probe: the c24 set for k 24, else the c25 set
2079fn ilay k ulong to bool
2080if eq k 24
2081ok = mkd t_d24
2082ok = and ok eq genlib t_c24 false 11 t_c24lib 0
2083ok = and ok cpexe t_dlib t_c24dep
2084ret and ok cpexe t_iprb t_c24prb
2085end
2086ok = mkd t_d25
2087ok = and ok eq genlib t_c25 false 11 t_c25lib 0
2088ok = and ok cpexe t_dlib t_c25dep
2089ret and ok cpexe t_iprb t_c25prb
2090end
2091note the import row of omega_dep_sub without its swap: the dependency computes 3 - 5, call 7 fails (8)
2092fn cmap to void
2093ok = tmut t_mapr t_mapw t_c24
2094ok = and ok ilay 24
2095if not ok
2096csetup t_x24
2097ret
2098end
2099ctl t_x24 runprb t_c24prb 8
2100end
2101note imp.tsv without its needed row for libomshdep.so.1 (the file still beside it): nothing loads it, the
2102note loader refuses the import library's symbols (127, "undefined symbol: omega_dep_")
2103fn cnoneed to void
2104ok = tcut t_needr t_c25
2105ok = and ok ilay 25
2106if not ok
2107csetup t_x25
2108ret
2109end
2110ctle t_x25 runprb t_c25prb 127 t_udep
2111end
2112note the import library's shared return without its UNLOCK call (the BLR X16 24 bytes after the first
2113note CBZ X16, +32, bytes 10 01 00 b4, made NOP, bytes 1f 20 03 d5): the lock stays held after call 0, so
2114note pthread_mutex_trylock refuses call 1, which answers its TRAP value 999 (2)
2115fn cunlock to void
2116ok = mkd t_d26
2117ok = and ok sload t_ilib
2118o = bfind4 16 1 0 180
2119if or not ok ge o shl ulong 1 63
2120csetup t_x26
2121ret
2122end
2123b = add o 24
2124put g_b b 31
2125put g_b add b 1 32
2126put g_b add b 2 3
2127put g_b add b 3 213
2128psc t_c26lib
2129ok = bsave false
2130ok = and ok cpexe t_dlib t_c26dep
2131ok = and ok cpexe t_iprb t_c26prb
2132if not ok
2133csetup t_x26
2134ret
2135end
2136ctl t_x26 runprb t_c26prb 2
2137end
2138note imp.tsv with an import row for a name the object does not import: SHLIB refuses it (1)
2139fn cimprow to void
2140if not rload t_itab
2141csetup t_x27
2142ret
2143end
2144ok = bapp t_nope
2145psc t_c27
2146ok = and ok bsave false
2147if not ok
2148csetup t_x27
2149ret
2150end
2151ctle t_x27 genlib t_c27 false 11 t_c27so 1 t_mimp
2152end
2153note imp.tsv with omega_imp_count's state ImpS dropped from its frame row: its parameters no longer match (1)
2154fn cframe to void
2155if not tmut t_cntr t_cntw t_c28
2156csetup t_x28
2157ret
2158end
2159ctle t_x28 genlib t_c28 false 11 t_c28so 1 t_mfrm
2160end
2161note imp.tsv with omega_imp_live exported without frame: a locked library refuses it (1)
2162fn clockexp to void
2163if not tmut t_liver t_livew t_c29
2164csetup t_x29
2165ret
2166end
2167ctle t_x29 genlib t_c29 false 11 t_c29so 1 t_mlck
2168end
2169note libnvidia-ml.so.1 and its probe without the transport library: the loader refuses (127)
2170fn ctransport to void
2171ok = mkd t_d30
2172ok = and ok cpexe t_nlib t_c30lib
2173ok = and ok cpexe t_nprb t_c30prb
2174if not ok
2175csetup t_x30
2176ret
2177end
2178ctle t_x30 runprb t_c30prb 127 t_flib
2179end
2180note the composed NVML source with nvmlInit_v2's body made nvmlShutdown's: nvmlInit_v2 (row 3) answers
2181note NVML_ERROR_UNINITIALIZED, not 0 (4)
2182fn cnvinit to void
2183if not sload t_nsrc
2184csetup t_x31
2185ret
2186end
2187o = bfind t_initr
2188if ge o shl ulong 1 63
2189csetup t_x31
2190ret
2191end
2192put g_b add o sub len t_initr 2 50
2193psc t_c31src
2194ok = bsave false
2195ok = and ok eq omcsrc t_c31src t_c31obj 0
2196ok = and ok mkd t_d31
2197ok = and ok eq genlib t_ntab true 12 t_c31lib 0
2198ok = and ok cpexe t_flib t_c31tr
2199ok = and ok cpexe t_nprb t_c31prb
2200if not ok
2201csetup t_x31
2202ret
2203end
2204ctl t_x31 runprb t_c31prb 4
2205end
2206note the Ampere QMD library with each frame wrapper's ADD X16, SP, #288 (its frame of 96 bytes + 192: the
2207note caller's stack arguments, bytes f0 83 04 91) made ADD X16, SP, #96 (bytes f0 83 01 91): the accepted build
2208note (call row 3) reads registers and shared_bytes from the wrapper's saved registers, still in range, so it is
2209note accepted with other QMD words, and the bufeq of buf+64 (row 29) fails (30)
2210fn cstkarg to void
2211ok = mkd t_d33
2212ok = and ok sload t_alib
2213if not ok
2214csetup t_x33
2215ret
2216end
2217c = ulong 0
2218n = div get g_n 6 4
2219for i ulong n bound 9223372036854775807
2220o = mul i 4
2221ok = and bis o 240 bis add o 1 131
2222ok = and ok and bis add o 2 4 bis add o 3 145
2223if ok
2224put g_b add o 2 1
2225c = add c 1
2226end
2227end
2228psc t_c33lib
2229ok = and eq c 2 bsave false
2230ok = and ok cpexe t_aprb t_c33prb
2231if not ok
2232csetup t_x33
2233ret
2234end
2235ctl t_x33 runprb t_c33prb 30
2236end
2237note the composed NVML source with the output copy of name, UUID and the other text answers reading from the
2238note step state (frame word 8) instead of the step buffer (word 9): the name's first word differs (bufeq row 9, 10)
2239fn cnvcopy to void
2240if not sload t_nsrc
2241csetup t_x34
2242ret
2243end
2244o = bfind t_mcr
2245if ge o shl ulong 1 63
2246csetup t_x34
2247ret
2248end
2249put g_b add o 24 56
2250psc t_c34src
2251ok = bsave false
2252ok = and ok eq omcsrc t_c34src t_c34obj 0
2253ok = and ok mkd t_d34
2254ok = and ok eq genlib t_ntab true 14 t_c34lib 0
2255ok = and ok cpexe t_flib t_c34tr
2256ok = and ok cpexe t_nprb t_c34prb
2257if not ok
2258csetup t_x34
2259ret
2260end
2261ctl t_x34 runprb t_c34prb 10
2262end
2263note ---- main
2264fn ausage to int
2265r = write 2 t_usage 0 len t_usage
2266ret 2
2267end
2268fn main to int
2269if ne argcnt 4
2270ret ausage
2271end
2272r = argread 1 g_omc 0 4095
2273if lt r 1
2274ret ausage
2275end
2276put g_n 1 ulong r
2277if not pinread
2278r = write 2 t_nopin 0 len t_nopin
2279ret 2
2280end
2281pclr
2282for j ulong get g_n 1 bound 4096
2283pc ulong get g_omc j
2284end
2285if not pinok
2286r = write 2 t_refd 0 len t_refd
2287ret 69
2288end
2289r = argread 2 g_gen 0 4095
2290if lt r 1
2291ret ausage
2292end
2293put g_n 7 ulong r
2294r = argread 3 g_scr 0 4094
2295if lt r 1
2296ret ausage
2297end
2298if gt r 4000
2299r = write 2 t_long 0 len t_long
2300ret 2
2301end
2302n = ulong r
2303x = makedir g_scr 0 n 448
2304if ne x 0
2305r = write 2 t_noscr 0 len t_noscr
2306ret 2
2307end
2308put g_scr n 47
2309put g_n 2 add n 1
2310checks
2311crow
2312cfloat
2313cexport
2314chash
2315cexpect
2316cstack
2317cext
2318cuext
2319crestore
2320cruntime
2321cneed
2322caddr
2323cfrest
2324cnext
2325ccrec
2326ccto
2327cnosave
2328crelf
2329cdiffer
2330cx7use
2331cslot
2332cmap
2333cnoneed
2334cunlock
2335cimprow
2336cframe
2337clockexp
2338ctransport
2339cnvinit
2340cneedname
2341cstkarg
2342cnvcopy
2343f = get g_n 11
2344ot t_sum
2345if and eq f 0 eq get g_n 12 get g_n 13
2346ot t_pass
2347else
2348ot t_fl
2349end
2350ot t_sk
2351onum get g_n 8
2352ot t_sc
2353onum get g_n 12
2354ot t_scc
2355onum get g_n 13
2356oc 10
2357oflush
2358if ne f 0
2359ret 1
2360end
2361if ne get g_n 12 get g_n 13
2362ret 1
2363end
2364ret 0
2365end