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
omega-mv / bridge / shlib / nvrmfake.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note bridge/shlib/nvrmfake.om: the test transport libomega-nvrm.so.1 (nvrmfake.tsv) behind the gate's |
| 3 | note libnvidia-ml.so.1: the three omega2_nvrm_* entry points of native/nvrm/transport.om, answered by the RM fake |
| 4 | note nvml_fake (bridge/shlib/rmfake.om, CUDApp's tests/nvml/rmfake.om unchanged) instead of /dev/nvidia*, plus |
| 5 | note fake_reset, fake_get and fake_trapped; the same functions and answers as CUDApp's tests/nvml/transport.c. |
| 6 | note Composed after rmfake.om. No device file is opened. |
| 7 | note States (frame words 8..11): FkS the fake's 64 words, FkH the request header, FkP the payload, FkT the |
| 8 | note violation count (0) and the result word copied out (1). |
| 9 | note A trap inside nvml_fake returns the TRAP value 1 (a transport refusal) at once, without the C's count of |
| 10 | note it as a violation: a path that is a bug in the fake. |
| 11 | |
| 12 | const UMAX ulong 4294967295 |
| 13 | |
| 14 | extern fn memcpy d ulong s ulong n ulong to ulong |
| 15 | |
| 16 | note fk_step: one fake step; a refusal (nonzero) counts as a violation and answers status 1; otherwise the |
| 17 | note fake's result goes to the caller's result word |
| 18 | fn fk_step st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 fr view ulong 12 to uint |
| 19 | v = nvml_fake st h p |
| 20 | if ne v 0 |
| 21 | put t 0 add get t 0 1 |
| 22 | put st 13 add get st 13 1 |
| 23 | ret 1 |
| 24 | end |
| 25 | put t 1 get st 6 |
| 26 | z = memcpy get fr 0 add get fr 11 8 8 |
| 27 | ret 0 |
| 28 | end |
| 29 | |
| 30 | export fn omega2_nvrm_open_file fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint |
| 31 | n = get fr 2 |
| 32 | if or eq n 0 gt n PN |
| 33 | ret 32 |
| 34 | end |
| 35 | z = memcpy get fr 10 get fr 1 n |
| 36 | put st 0 2 |
| 37 | put st 7 n |
| 38 | ret fk_step st h p t fr |
| 39 | end |
| 40 | |
| 41 | export fn omega2_nvrm_close_file fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint |
| 42 | put st 0 3 |
| 43 | put st 1 get fr 1 |
| 44 | ret fk_step st h p t fr |
| 45 | end |
| 46 | |
| 47 | note fault S: the transport itself refuses the GPU name control 0x20800110 (status 1) |
| 48 | fn fk_srefuse st view ulong 64 h view uchar HN fr view ulong 12 to bool |
| 49 | if or ne get st 5 83 ne get fr 2 42 |
| 50 | ret false |
| 51 | end |
| 52 | if lt get fr 4 12 |
| 53 | ret false |
| 54 | end |
| 55 | c = or or ulong get h 8 shl ulong get h 9 8 or shl ulong get h 10 16 shl ulong get h 11 24 |
| 56 | ret eq c 545259792 |
| 57 | end |
| 58 | |
| 59 | export fn omega2_nvrm_ioctl fr view ulong 12 st edit ulong 64 h edit uchar HN p edit uchar PN t edit ulong 8 to uint |
| 60 | hl = get fr 4 |
| 61 | pl = get fr 6 |
| 62 | if or gt hl HN gt pl PN |
| 63 | ret 32 |
| 64 | end |
| 65 | z = memcpy get fr 9 get fr 3 hl |
| 66 | if fk_srefuse st h fr |
| 67 | ret 1 |
| 68 | end |
| 69 | z = memcpy get fr 10 get fr 5 pl |
| 70 | put st 0 1 |
| 71 | put st 1 get fr 1 |
| 72 | put st 2 get fr 2 |
| 73 | put st 3 hl |
| 74 | put st 4 pl |
| 75 | r = fk_step st h p t fr |
| 76 | z = memcpy get fr 3 get fr 9 hl |
| 77 | z = memcpy get fr 5 get fr 10 pl |
| 78 | ret r |
| 79 | end |
| 80 | |
| 81 | export fn fake_reset fr view ulong 12 st edit ulong 64 t edit ulong 8 to ulong |
| 82 | for i ulong 64 |
| 83 | put st i 0 |
| 84 | end |
| 85 | put st 5 and get fr 0 255 |
| 86 | put t 0 0 |
| 87 | ret 0 |
| 88 | end |
| 89 | |
| 90 | export fn fake_get fr view ulong 12 st edit ulong 64 to ulong |
| 91 | i = and get fr 0 UMAX |
| 92 | if lt i 64 |
| 93 | ret get st i |
| 94 | end |
| 95 | ret 18446744073709551615 |
| 96 | end |
| 97 | |
| 98 | export fn fake_trapped fr view ulong 12 t edit ulong 8 to ulong |
| 99 | ret get t 0 |
| 100 | end |