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 / host / tests / netdata.om

144 lines · 3350 bytes Raw Blame History
1note Native Linux-arm64 network primitives. Runs only in a private scratch directory.
2text npth "netdata.sock"
3text nmsg "native sendmsg"
4text nok "PASS native peercred pollfds sendmsg allowlist\n"
5global na uchar 110
6global nb uchar 64
7global nc uchar 16
8global np uchar 24
9global nv uchar 4
10global nlarge uchar 1048576
11fn ncheck yes bool to void
12if not yes
13exit 1
14end
15end
16fn nget32 off ulong to ulong
17v = ulong 0
18for i ulong 4
19v = or v shl ulong get nc add off i mul i 8
20end
21ret v
22end
23fn nfdput off ulong fd long to void
24for i ulong 4
25put np add off i uchar and shr ulong fd mul i 8 255
26end
27put np add off 4 1
28end
29fn nopts fd int to void
30put nv 0 1
31ncheck eq sockopt fd 1 2 nv 0 4 0
32ncheck eq sockopt fd 1 15 nv 0 4 0
33ncheck eq sockopt fd 1 9 nv 0 4 0
34ncheck eq sockopt fd 1 7 nv 0 4 0
35ncheck eq sockopt fd 1 8 nv 0 4 0
36ncheck eq sockopt fd 1 16 nv 0 4 neg long 92
37ncheck eq sockopt fd 999 2 nv 0 4 neg long 92
38ncheck eq sockopt fd 1 2 nv 0 3 neg long 22
39ncheck eq sockopt neg int 1 1 2 nv 0 4 neg long 9
40end
41fn ntraps to int
42ncheck eq argread 1 nb 0 1 1
43if eq get nb 0 49
44ret int peercred neg int 1 nc 0 11
45end
46if eq get nb 0 50
47ret int pollfds np 0 7 0
48end
49if eq get nb 0 51
50ret int sendmsg neg int 1 nb 18446744073709551615 1 0
51end
52ret 90
53end
54fn nexchange a long b long to void
55nfdput 0 a
56nfdput 8 b
57ncheck eq pollfds np 0 16 0 0
58ncheck eq pollfds np 0 0 1000000 0
59ncheck eq sendmsg int b nmsg 0 len nmsg 0 long len nmsg
60ncheck eq pollfds np 0 16 1000000000 1
61ncheck ne and get np 6 1 0
62ncheck eq get np 14 0
63ncheck eq recv int a nb 1 len nmsg 0 long len nmsg
64for i ulong len nmsg
65ncheck eq get nb add i 1 get nmsg i
66end
67ncheck eq peercred int a nc 2 12 0
68ncheck eq nget32 2 ulong getpid
69ncheck eq nget32 6 ulong getuid
70ncheck eq nget32 10 ulong getgid
71ncheck eq peercred neg int 1 nc 0 12 neg long 9
72end
73note MSG_DONTWAIT=64 forces a short send into a deliberately small kernel send buffer.
74fn nshort a long b long to void
75for i ulong 4
76put nv i 0
77end
78put nv 1 16
79ncheck eq sockopt int b 1 7 nv 0 4 0
80n = sendmsg int b nlarge 0 len nlarge 64
81ncheck gt n 0
82ncheck lt n long len nlarge
83ncheck le n 65536
84left = n
85while gt left 0 bound 65536
86take = ulong left
87if gt take len nb
88take = len nb
89end
90r = recv int a nb 0 take 0
91ncheck gt r 0
92left = sub left r
93end
94end
95fn nleaks to void
96first = socknew 1 524289 0
97ncheck ge first 0
98ncheck eq fclose int first 0
99for i ulong 64
100fd = socknew 1 524289 0
101ncheck eq fd first
102ncheck eq fclose int fd 0
103end
104start = monons
105ncheck ge start 0
106ncheck eq pollfds np 0 0 1000000 0
107finish = monons
108ncheck ge sub finish start 1000000
109end
110fn main to int
111if eq argcnt 2
112ret ntraps
113end
114put na 0 1
115for i ulong len npth
116put na add i 2 get npth i
117end
118s = socknew 1 524289 0
119ncheck ge s 0
120ncheck eq bind int s na 0 len na 0
121ncheck eq listen int s 1 0
122c = socknew 1 524289 0
123ncheck ge c 0
124ncheck eq connect int c na 0 len na 0
125a = accept int s 524288
126ncheck ge a 0
127nexchange a c
128nshort a c
129ncheck eq fclose int a 0
130ncheck eq sendmsg int a nmsg 0 len nmsg 0 neg long 9
131ncheck eq sendmsg int c nmsg 0 len nmsg 0 neg long 32
132ncheck eq fclose int c 0
133ncheck eq fclose int s 0
134ncheck eq unlink npth 0 len npth 0
135t = socknew 2 524289 0
136ncheck ge t 0
137nopts int t
138ncheck eq sockopt int t 6 1 nv 0 4 0
139ncheck eq sockopt int t 6 2 nv 0 4 neg long 92
140ncheck eq fclose int t 0
141nleaks
142ncheck eq write 1 nok 0 len nok long len nok
143ret 0
144end