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 / netpeer.om

95 lines · 2039 bytes Raw Blame History
1note Parent and child connect independently; SO_PEERCRED must return the other process PID.
2text pname "netpeer.sock"
3text pass "PASS independent Unix peer identity and offset sentinels\n"
4global pa uchar 110
5global pc uchar 16
6global ps uchar 4
7global pb uchar 8
8global pp uchar 16
9fn pcheck yes bool to void
10if not yes
11exit 1
12end
13end
14fn pget off ulong to long
15v = ulong 0
16for i ulong 4
17v = or v shl ulong get pc add off i mul i 8
18end
19ret long v
20end
21fn pcreds fd int pid long to void
22for i ulong len pc
23put pc i 165
24end
25pcheck eq add peercred fd pc 2 12 9 9
26pcheck eq pget 2 pid
27pcheck eq pget 6 getuid
28pcheck eq pget 10 getgid
29pcheck eq get pc 0 165
30pcheck eq get pc 1 165
31pcheck eq get pc 14 165
32pcheck eq get pc 15 165
33end
34fn pchild to int
35fd = socknew 1 524289 0
36pcheck ge fd 0
37pcheck eq connect int fd pa 0 len pa 0
38pcreds int fd getppid
39put pb 3 42
40pcheck eq sendmsg int fd pb 3 1 0 1
41pcheck gt waitio int fd 1 1000000000 0
42pcheck eq recv int fd pb 4 1 0 1
43pcheck eq get pb 4 99
44pcheck eq fclose int fd 0
45ret 0
46end
47fn pserve fd int pid long to void
48pcheck gt waitio fd 1 1000000000 0
49conn = accept fd 524288
50pcheck ge conn 0
51pcreds int conn pid
52for i ulong len pp
53put pp i 0
54end
55for i ulong 4
56put pp add i 4 uchar and shr ulong conn mul i 8 255
57end
58put pp 8 1
59put pp 0 165
60put pp 15 165
61pcheck eq add pollfds pp 4 8 neg long 1 9 10
62pcheck ne and get pp 10 1 0
63pcheck eq get pp 0 165
64pcheck eq get pp 15 165
65pcheck eq recv int conn pb 2 1 0 1
66pcheck eq get pb 2 42
67put pb 3 99
68pcheck eq add sendmsg int conn pb 3 1 0 9 10
69pcheck eq fclose int conn 0
70end
71fn main to int
72put pa 0 1
73for i ulong len pname
74put pa add i 2 get pname i
75end
76fd = socknew 1 524289 0
77pcheck ge fd 0
78pcheck eq bind int fd pa 0 len pa 0
79pcheck eq listen int fd 1 0
80pid = fork
81pcheck ge pid 0
82if eq pid 0
83pcheck eq fclose int fd 0
84ret pchild
85end
86pserve int fd pid
87pcheck eq waitpid int pid ps 0 4 0 pid
88for i ulong 4
89pcheck eq get ps i 0
90end
91pcheck eq fclose int fd 0
92pcheck eq unlink pname 0 len pname 0
93pcheck eq write 1 pass 0 len pass long len pass
94ret 0
95end