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/mapping.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 / mapping.om` 175 lines ยท 3965 bytes Raw Blame History 1 note Native memory ownership, shared/private files, bounds, stale handles and resource limits. 2 text path "mapped.bin" 3 text payload "native Omega mapped memory" 4 text ok "PASS native mapping\n" 5 global buf uchar 8192 6 global caps long 128 7 global wstat uchar 4 8 global fdnum int 1 9 fn expect yes bool to void 10 if not yes 11 exit int 80 12 end 13 end 14 note Keep five distinct caller values live across each native mapping operation. 15 fn held h long a ulong b ulong c ulong d ulong e ulong to void 16 expect eq mapwrite h 31 payload 0 len payload long len payload 17 expect eq a 101 18 expect eq b 202 19 expect eq c 303 20 expect eq d 404 21 expect eq e 505 22 expect eq mapread h 31 buf 1 len payload long len payload 23 expect eq a 101 24 expect eq b 202 25 expect eq c 303 26 expect eq d 404 27 expect eq e 505 28 expect eq mapdrop h 0 29 expect eq a 101 30 expect eq b 202 31 expect eq c 303 32 expect eq d 404 33 expect eq e 505 34 end 35 fn fault kind int to int 36 h = mapnew neg int 1 0 4096 3 34 37 expect gt h 0 38 if eq kind 0 39 expect eq mapdrop h 0 40 r = mapread h 0 buf 0 1 41 ret int r 42 end 43 if eq kind 1 44 expect eq mapdrop h 0 45 next = mapnew neg int 1 0 4096 3 34 46 expect ne next h 47 r = mapwrite h 0 payload 0 1 48 ret int r 49 end 50 if eq kind 2 51 r = mapread h 4096 buf 0 1 52 ret int r 53 end 54 if eq kind 3 55 r = mapwrite h `18446744073709551615` payload 0 1 56 ret int r 57 end 58 if eq kind 4 59 ro = mapnew get fdnum 0 0 4096 1 2 60 r = mapwrite ro 0 payload 0 1 61 ret int r 62 end 63 if eq kind 5 64 r = mapdrop long 0 65 ret int r 66 end 67 if eq kind 6 68 r = mapdrop long 129 69 ret int r 70 end 71 if eq kind 7 72 r = mapnew neg int 1 0 0 3 34 73 ret int r 74 end 75 if eq kind 8 76 r = mapnew neg int 1 0 `68719476737` 3 34 77 ret int r 78 end 79 if eq kind 9 80 r = mapnew neg int 1 1 4096 3 34 81 ret int r 82 end 83 if eq kind 10 84 r = mapread h 0 buf 8192 1 85 ret int r 86 end 87 if eq kind 11 88 r = mapread h 0 buf 0 `18446744073709551615` 89 ret int r 90 end 91 if eq kind 12 92 r = mapdrop neg long 1 93 ret int r 94 end 95 if eq kind 13 96 r = mapnew int 0 0 4096 3 34 97 ret int r 98 end 99 ret 99 100 end 101 fn main to int 102 fd = fopen path 0 len path 194 384 103 expect ge fd 0 104 put fdnum 0 int fd 105 expect eq write int fd buf 0 8192 8192 106 shared = mapnew int fd 0 8192 3 1 107 expect gt shared 0 108 expect eq mapwrite shared 4099 payload 0 len payload long len payload 109 expect eq fseek int fd 4099 0 4099 110 expect eq read int fd buf 0 len payload long len payload 111 for i ulong len payload 112 expect eq get buf i get payload i 113 end 114 private = mapnew int fd 4096 4096 3 2 115 expect gt private 0 116 expect ne private shared 117 expect eq mapread private 3 buf 100 len payload long len payload 118 for i ulong len payload 119 expect eq get buf add i 100 get payload i 120 end 121 put buf 0 222 122 expect eq mapwrite private 3 buf 0 1 1 123 expect eq mapread private 3 buf 1 1 1 124 expect eq get buf 1 222 125 expect eq mapread shared 4099 buf 2 1 1 126 expect eq get buf 2 get payload 0 127 expect eq mapdrop shared 0 128 expect eq mapdrop private 0 129 ro = mapnew int fd 0 8192 1 2 130 expect gt ro 0 131 expect eq mapread ro 4099 buf 0 len payload long len payload 132 expect eq mapdrop ro 0 133 expect eq mapnew neg int 1 0 4096 1 2 neg long 9 134 expect eq mapnew int fd 1 4096 1 2 neg long 22 135 live = mapnew neg int 1 0 4096 3 34 136 held live 101 202 303 404 505 137 note A failed kernel mapping must not consume a slot. 138 for i ulong 128 139 h = mapnew neg int 1 0 4096 3 34 140 expect gt h 0 141 put caps i h 142 expect eq mapread h 4095 buf 0 1 1 143 expect eq get buf 0 0 144 expect eq mapwrite h 4096 payload len payload 0 0 145 end 146 expect eq mapnew neg int 1 0 4096 3 34 neg long 24 147 for i ulong 128 148 expect eq mapdrop get caps i 0 149 end 150 for i ulong 1024 151 h = mapnew neg int 1 0 4096 3 34 152 expect gt h get caps 0 153 expect eq mapwrite h 13 payload 0 len payload long len payload 154 expect eq mapread h 13 buf 1 len payload long len payload 155 for j ulong len payload 156 expect eq get buf add j 1 get payload j 157 end 158 expect eq mapdrop h 0 159 put caps 0 h 160 end 161 for kind int 14 162 pid = fork 163 expect ge pid 0 164 if eq pid 0 165 exit fault kind 166 end 167 expect eq waitpid int pid wstat 0 4 0 pid 168 expect eq get wstat 0 0 169 expect eq get wstat 1 103 170 end 171 expect eq fclose int fd 0 172 expect eq unlink path 0 len path 0 173 expect eq write 1 ok 0 len ok long len ok 174 ret 0 175 end