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 / seed / ng / a64 / tests / macho / lib / libback.om

117 lines · 2468 bytes Raw Blame History
1target macos
2note libback: library code calls back into Omega. qsort of libSystem sorts eight 64-bit numbers; its comparison
3note function is callback entry 5 (libfn 7), so the function libback runs with k = 5 and the addresses of two
4note elements. It reads them with memcpy: a libcall inside a callback, on the C stack below qsort's frames.
5note Status 1 when the numbers come out sorted, the callback ran at least seven times with k = 5 and no other k,
6note libfn gives nothing for 18 and different entries for 2 and 3, and a libcall after the sort still works.
7note 2 to 8 name the step that failed.
8text s_qs "qsort"
9text s_mc "memcpy"
10text s_in "53819274"
11global g_f ulong 4
12global g_rg uchar 128
13global g_a uchar 16
14
15fn p64 b edit uchar 128 o ulong v ulong to void
16for i ulong 8
17put b add o i uchar and shr v mul i 8 255
18end
19end
20
21fn pr o ulong v ulong to void
22for i ulong 8
23put g_rg add o i uchar and shr v mul i 8 255
24end
25end
26
27fn ga o ulong to ulong
28v = ulong 0
29for i ulong 8
30v = or v shl ulong get g_a add o i mul i 8
31end
32ret v
33end
34
35fn sym rg edit uchar 128 nm edit uchar 64 to ulong
36p64 rg 0 18446744073709551614
37p64 rg 8 ulong libptr nm 0 64
38ret ulong libcall ulong libfn 1 rg 0 128
39end
40
41fn libback k ulong a ulong b ulong c ulong d ulong e ulong to ulong
42put g_f 1 add get g_f 1 1
43if ne k 5
44put g_f 2 1
45end
46pr 0 ulong libptr g_a 0 16
47pr 8 a
48pr 16 8
49r = libcall get g_f 0 g_rg 0 128
50pr 0 ulong libptr g_a 8 8
51pr 8 b
52pr 16 8
53r = libcall get g_f 0 g_rg 0 128
54x = ga 0
55y = ga 8
56if lt x y
57ret 18446744073709551615
58end
59if gt x y
60ret 1
61end
62ret 0
63end
64
65fn main to int
66rg = new uchar 128 0
67nm = new uchar 64 0
68arr = new uchar 64 0
69out = new uchar 64 0
70for i ulong 8
71put arr mul i 8 uchar sub get s_in i 48
72end
73for i ulong len s_qs
74put nm i get s_qs i
75end
76put nm len s_qs 0
77qs = sym rg nm
78for i ulong len s_mc
79put nm i get s_mc i
80end
81put nm len s_mc 0
82mc = sym rg nm
83if or eq qs 0 eq mc 0
84ret 2
85end
86put g_f 0 mc
87cb = ulong libfn 7
88if or eq cb 0 ne ulong libfn 18 0
89ret 3
90end
91if or eq ulong libfn 2 ulong libfn 3 ne sub ulong libfn 3 ulong libfn 2 8
92ret 4
93end
94p64 rg 0 ulong libptr arr 0 64
95p64 rg 8 8
96p64 rg 16 8
97p64 rg 24 cb
98r = libcall qs rg 0 128
99if or ne get g_f 2 0 lt get g_f 1 7
100ret 5
101end
102p64 rg 0 ulong libptr out 0 64
103p64 rg 8 ulong libptr arr 0 64
104p64 rg 16 64
105r = libcall mc rg 0 128
106want = ulong 1
107for i ulong 8
108if or ne ulong get out mul i 8 want ne ulong get out add mul i 8 1 0
109ret 6
110end
111want = add want 1
112if eq want 6
113want = ulong 7
114end
115end
116ret 1
117end