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 / gpu / driver / rm / import.om

194 lines · 3914 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2note The fake kernel translates OS fds to endpoint-issued capabilities. The endpoint
3note never trusts a process fd number, PID or a caller-supplied handle as import authority.
4fn rmtoken c edit ulong 4096 to long
5b = new uchar 4 0
6if eq get c 400 1000
7ret -24
8end
9for attempt ulong 64
10r = random b 0 4 0
11if ne r 4
12ret -5
13end
14tok = and or or ulong get b 0 shl ulong get b 1 8 or shl ulong get b 2 16 shl ulong get b 3 24 2147483647
15if eq tok 0
16continue
17end
18seen = false
19for j ulong get c 400
20if eq get c add 512 j tok
21seen = true
22end
23end
24if not seen
25put c add 512 get c 400 tok
26put c 400 add get c 400 1
27ret long tok
28end
29end
30ret -5
31end
32fn rmimport c edit ulong 4096 dst ulong src ulong to long
33if eq dst src
34ret -22
35end
36if or ne get c add 100 dst 0 ne get c add 200 dst 0
37ret -16
38end
39if eq get c add 100 src 0
40ret -9
41end
42rmalias c dst src
43ret 0
44end
45fn rmalias c edit ulong 4096 dst ulong src ulong to void
46rmdrop c dst
47put c mul dst 3 get c 450
48put c add mul dst 3 1 get c add mul src 3 1
49put c add mul dst 3 2 get c add mul src 3 2
50put c add 100 dst 1
51ret
52end
53fn rmpre b view uchar 16384 n ulong to long
54if lt n 72
55ret neg long 22
56end
57if or ne rmget b 48 4 2 ne n add ulong 72 rmget b 64 4
58ret neg long 22
59end
60h = rmdecode rmget b 52 4
61if eq h 0
62h = rmusize rmget b 52 4
63end
64if eq h 0
65ret neg long 22
66end
67if not rmptr rmget b 56 8 h
68ret neg long 14
69end
70ret 0
71end
72fn rmauth c edit ulong 4096 b edit uchar 16384 o edit uchar 16384 idx ulong n ulong to ulong
73r = rmpre b n
74if ne r 0
75ret rmbegin b o r 0
76end
77if ge n 72
78if ne rmusize rmget b 52 4 0
79ret rmuparent c b o idx n
80end
81if eq rmget b 52 4 ulong 3221505737
82note REGISTER_FD exact ioctl; header retry is handled by worker.
83if and eq n 76 and eq rmget b 64 4 4 eq rmget b 68 4 4
84src = rmclient c rmget b 72 4
85if eq src 8
86ret rmbegin b o -9 0
87end
88put c 450 get c mul idx 3
89r = rmimport c idx src
90if ne r 0
91ret rmbegin b o r 0
92end
93ret rmresult b o 4
94end
95else
96if gt rmget b 64 4 0
97put c add 100 idx 1
98end
99end
100end
101if and eq n 128 eq rmget b 52 4 ulong 3224913486
102note MAP_MEMORY's fd field is also a capability, never a guessed numeric fd.
103other = rmclient c rmget b 120 4
104if eq other 8
105ret rmbegin b o -9 0
106end
107pid = get c add mul idx 3 1
108if ne get c add mul other 3 1 pid
109busy = ne get c add 100 other 0
110owner = get c add 200 other
111if or busy and ne owner 0 ne owner pid
112ret rmbegin b o -1 0
113end
114put c add 200 other pid
115end
116end
117ret rmforward c b o idx n
118end
119fn rmnested b view uchar 16384 nr ulong to ulong
120if ne nr 42
121ret 0
122end
123cmd = rmget b 80 4
124n = rmget b 104 4
125if eq cmd 545264129
126if ne n 1
127ret 8193
128end
129ret 8
130end
131if eq cmd 8389121
132if gt n 512
133ret 8193
134end
135ret mul n 4
136end
137ret 0
138end
139fn rmretry3 b view uchar 16384 o edit uchar 16384 h ulong p ulong q ulong to ulong
140size = rmbegin b o 0 112
141rmput o 20 4 4
142rmput o 24 4 3
143rmput o 28 4 3
144for j ulong 2
145off = add 32 mul j 48
146rmput o off 8 rmget b 56 8
147rmput o add off 8 8 h
148rmput o add off 16 8 rmget b 88 8
149rmput o add off 24 8 p
150rmput o add off 32 8 rmget b 112 8
151rmput o add off 40 8 q
152end
153ret size
154end
155fn rmuparent c edit ulong 4096 b edit uchar 16384 o edit uchar 16384 idx ulong n ulong to ulong
156cmd = rmget b 52 4
157if and eq cmd 33 eq n 9336
158src = rmclient c rmget b 9320 4
159if eq src 8
160ret rmbegin b o -9 0
161end
162pid = get c add mul idx 3 1
163if ne get c add mul src 3 1 pid
164ret rmbegin b o -1 0
165end
166end
167if and eq cmd 25 eq n 104
168ready = ne get c add 300 idx 0
169ready = and ready ne get c add 320 idx 0
170if not ready
171ret rmbegin b o -1 0
172end
173src = rmclient c rmget b 88 4
174if or eq src 8 eq src idx
175ret rmbegin b o -9 0
176end
177size = rmforward c b o src n
178if and eq rmget o 4 4 0 eq rmget o 60 4 0
179put c 450 get c mul idx 3
180rmalias c idx src
181end
182ret size
183end
184size = rmforward c b o idx n
185if and gt n 72 and eq rmget o 4 4 0 eq rmget o add 32 rmuoff cmd 4 0
186if eq cmd 805306369
187put c add 300 idx 1
188end
189if eq cmd 37
190put c add 320 idx 1
191end
192end
193ret size
194end