Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/host/tests/netdata.om # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / host / tests / netdata.om` 144 lines ยท 3350 bytes Raw Blame History 1 note Native Linux-arm64 network primitives. Runs only in a private scratch directory. 2 text npth "netdata.sock" 3 text nmsg "native sendmsg" 4 text nok "PASS native peercred pollfds sendmsg allowlist\n" 5 global na uchar 110 6 global nb uchar 64 7 global nc uchar 16 8 global np uchar 24 9 global nv uchar 4 10 global nlarge uchar `1048576` 11 fn ncheck yes bool to void 12 if not yes 13 exit 1 14 end 15 end 16 fn nget32 off ulong to ulong 17 v = ulong 0 18 for i ulong 4 19 v = or v shl ulong get nc add off i mul i 8 20 end 21 ret v 22 end 23 fn nfdput off ulong fd long to void 24 for i ulong 4 25 put np add off i uchar and shr ulong fd mul i 8 255 26 end 27 put np add off 4 1 28 end 29 fn nopts fd int to void 30 put nv 0 1 31 ncheck eq sockopt fd 1 2 nv 0 4 0 32 ncheck eq sockopt fd 1 15 nv 0 4 0 33 ncheck eq sockopt fd 1 9 nv 0 4 0 34 ncheck eq sockopt fd 1 7 nv 0 4 0 35 ncheck eq sockopt fd 1 8 nv 0 4 0 36 ncheck eq sockopt fd 1 16 nv 0 4 neg long 92 37 ncheck eq sockopt fd 999 2 nv 0 4 neg long 92 38 ncheck eq sockopt fd 1 2 nv 0 3 neg long 22 39 ncheck eq sockopt neg int 1 1 2 nv 0 4 neg long 9 40 end 41 fn ntraps to int 42 ncheck eq argread 1 nb 0 1 1 43 if eq get nb 0 49 44 ret int peercred neg int 1 nc 0 11 45 end 46 if eq get nb 0 50 47 ret int pollfds np 0 7 0 48 end 49 if eq get nb 0 51 50 ret int sendmsg neg int 1 nb `18446744073709551615` 1 0 51 end 52 ret 90 53 end 54 fn nexchange a long b long to void 55 nfdput 0 a 56 nfdput 8 b 57 ncheck eq pollfds np 0 16 0 0 58 ncheck eq pollfds np 0 0 `1000000` 0 59 ncheck eq sendmsg int b nmsg 0 len nmsg 0 long len nmsg 60 ncheck eq pollfds np 0 16 `1000000000` 1 61 ncheck ne and get np 6 1 0 62 ncheck eq get np 14 0 63 ncheck eq recv int a nb 1 len nmsg 0 long len nmsg 64 for i ulong len nmsg 65 ncheck eq get nb add i 1 get nmsg i 66 end 67 ncheck eq peercred int a nc 2 12 0 68 ncheck eq nget32 2 ulong getpid 69 ncheck eq nget32 6 ulong getuid 70 ncheck eq nget32 10 ulong getgid 71 ncheck eq peercred neg int 1 nc 0 12 neg long 9 72 end 73 note MSG_DONTWAIT=64 forces a short send into a deliberately small kernel send buffer. 74 fn nshort a long b long to void 75 for i ulong 4 76 put nv i 0 77 end 78 put nv 1 16 79 ncheck eq sockopt int b 1 7 nv 0 4 0 80 n = sendmsg int b nlarge 0 len nlarge 64 81 ncheck gt n 0 82 ncheck lt n long len nlarge 83 ncheck le n 65536 84 left = n 85 while gt left 0 bound 65536 86 take = ulong left 87 if gt take len nb 88 take = len nb 89 end 90 r = recv int a nb 0 take 0 91 ncheck gt r 0 92 left = sub left r 93 end 94 end 95 fn nleaks to void 96 first = socknew 1 524289 0 97 ncheck ge first 0 98 ncheck eq fclose int first 0 99 for i ulong 64 100 fd = socknew 1 524289 0 101 ncheck eq fd first 102 ncheck eq fclose int fd 0 103 end 104 start = monons 105 ncheck ge start 0 106 ncheck eq pollfds np 0 0 `1000000` 0 107 finish = monons 108 ncheck ge sub finish start `1000000` 109 end 110 fn main to int 111 if eq argcnt 2 112 ret ntraps 113 end 114 put na 0 1 115 for i ulong len npth 116 put na add i 2 get npth i 117 end 118 s = socknew 1 524289 0 119 ncheck ge s 0 120 ncheck eq bind int s na 0 len na 0 121 ncheck eq listen int s 1 0 122 c = socknew 1 524289 0 123 ncheck ge c 0 124 ncheck eq connect int c na 0 len na 0 125 a = accept int s 524288 126 ncheck ge a 0 127 nexchange a c 128 nshort a c 129 ncheck eq fclose int a 0 130 ncheck eq sendmsg int a nmsg 0 len nmsg 0 neg long 9 131 ncheck eq sendmsg int c nmsg 0 len nmsg 0 neg long 32 132 ncheck eq fclose int c 0 133 ncheck eq fclose int s 0 134 ncheck eq unlink npth 0 len npth 0 135 t = socknew 2 524289 0 136 ncheck ge t 0 137 nopts int t 138 ncheck eq sockopt int t 6 1 nv 0 4 0 139 ncheck eq sockopt int t 6 2 nv 0 4 neg long 92 140 ncheck eq fclose int t 0 141 nleaks 142 ncheck eq write 1 nok 0 len nok long len nok 143 ret 0 144 end