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/aienux/blob/main/native/omega/allen/memory.om # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / omega / allen / memory.om` 451 lines ยท 6496 bytes Raw Blame History 1 note Legacy application record codec; SHA is unkeyed integrity ONLY. 2 global Unit uchar 4096 3 global Enc uchar 4096 4 global Mem uchar 3692 5 global Md ulong 3 6 global Note uchar 128 7 global Ns ulong 4 8 text Magic "AIENALM1" 9 text Nmagic "AIENNOT1" 10 fn get32 off ulong to ulong 11 v = ulong 0 12 for i ulong 4 13 v = or v shl ulong get Unit add off i mul i 8 14 end 15 ret v 16 end 17 fn get64 off ulong to ulong 18 ret or get32 off shl get32 add off 4 32 19 end 20 fn put32 off ulong v ulong to void 21 for i ulong 4 22 put Unit add off i uchar and shr v mul i 8 255 23 end 24 end 25 fn put64 off ulong v ulong to void 26 put32 off and v `4294967295` 27 put32 add off 4 shr v 32 28 end 29 fn mem32 off ulong to ulong 30 v = ulong 0 31 for i ulong 4 32 v = or v shl ulong get Mem add off i mul i 8 33 end 34 ret v 35 end 36 fn mset32 off ulong v ulong to void 37 for i ulong 4 38 put Mem add off i uchar and shr v mul i 8 255 39 end 40 end 41 fn zeroend off ulong to bool 42 for i ulong sub ulong 4096 off 43 if ne get Unit add off i 0 44 ret false 45 end 46 end 47 ret true 48 end 49 fn fieldok off ulong cap ulong name bool to bool 50 n = ulong 0 51 while lt n cap 52 if eq get Unit add off n 0 53 for j ulong sub cap n 54 if ne get Unit add add off n j 0 55 ret false 56 end 57 end 58 ret true 59 end 60 c = get Unit add off n 61 lower = and ge c 97 le c 122 62 digit = isdigit c 63 if name 64 if eq n 0 65 if not or and ge c 65 le c 90 digit 66 ret false 67 end 68 else 69 if not or lower digit 70 ret false 71 end 72 end 73 else 74 if eq c 32 75 if or eq n 0 eq n sub cap 1 76 ret false 77 end 78 if eq get Unit add off add n 1 0 79 ret false 80 end 81 if eq get Unit add off sub n 1 32 82 ret false 83 end 84 else 85 if not or lower digit 86 ret false 87 end 88 end 89 end 90 n = add n 1 91 end 92 ret false 93 end 94 fn digest count ulong to void 95 hinit 96 for i ulong 32 97 hbyte get Unit i 98 end 99 for i ulong count 100 hbyte get Unit add i 64 101 end 102 finish 103 end 104 fn hashok count ulong to bool 105 digest count 106 d = uchar 0 107 for i ulong 32 108 d = or d xor get Hash i get Unit add i 32 109 end 110 ret eq d 0 111 end 112 fn seal count ulong to void 113 digest count 114 for i ulong 32 115 put Unit add i 32 get Hash i 116 end 117 end 118 fn memvalid to bool 119 for i ulong 8 120 if ne get Unit i get Magic i 121 ret false 122 end 123 end 124 ver = get32 8 125 if or lt ver 2 gt ver 4 126 ret false 127 end 128 n = get32 96 129 if or gt n 32 gt get32 100 512 130 ret false 131 end 132 size = add 40 mul n 113 133 if ge ver 3 134 size = add size 24 135 end 136 if eq ver 4 137 size = add size 12 138 end 139 if or ne size get32 12 eq get64 16 0 140 ret false 141 end 142 for i ulong 8 143 if ne get Unit add i 24 0 144 ret false 145 end 146 end 147 if not zeroend add 64 size 148 ret false 149 end 150 if not hashok size 151 ret false 152 end 153 if not fieldok 72 24 true 154 ret false 155 end 156 for i ulong n 157 off = add 104 mul i 113 158 if or eq get Unit off 0 eq get Unit add off 48 0 159 ret false 160 end 161 if not fieldok off 48 false 162 ret false 163 end 164 if not fieldok add off 48 64 false 165 ret false 166 end 167 if gt get Unit add off 112 1 168 ret false 169 end 170 end 171 off = add 104 mul n 113 172 if ge ver 3 173 if not fieldok off 24 true 174 ret false 175 end 176 end 177 if eq ver 4 178 if ne get Unit add off 27 0 179 ret false 180 end 181 end 182 ret true 183 end 184 fn memdec to bool 185 if not memvalid 186 ret false 187 end 188 size = get32 12 189 for i ulong 3692 190 put Mem i 0 191 end 192 for i ulong size 193 put Mem i get Unit add i 64 194 end 195 put Md 0 get64 16 196 put Md 1 get32 8 197 put Md 2 size 198 ret true 199 end 200 fn memenc gen ulong to bool 201 n = mem32 32 202 if or gt n 32 eq gen 0 203 ret false 204 end 205 size = add 76 mul n 113 206 for i ulong 4096 207 put Unit i 0 208 end 209 for i ulong 8 210 put Unit i get Magic i 211 end 212 put32 8 4 213 put32 12 size 214 put64 16 gen 215 for i ulong size 216 put Unit add i 64 get Mem i 217 end 218 seal size 219 if not memvalid 220 ret false 221 end 222 for i ulong 4096 223 put Enc i get Unit i 224 end 225 ret true 226 end 227 fn noteval index ulong to bool 228 for i ulong 8 229 if ne get Unit i get Nmagic i 230 ret false 231 end 232 end 233 n = get32 12 234 if or eq n 0 ge n 128 235 ret false 236 end 237 if or ne get32 8 1 ne get32 16 index 238 ret false 239 end 240 if or gt get32 24 1 ne get32 28 0 241 ret false 242 end 243 if not zeroend add n 64 244 ret false 245 end 246 for i ulong n 247 c = get Unit add i 64 248 if or lt c 32 gt c 126 249 ret false 250 end 251 end 252 ret hashok n 253 end 254 fn notedec index ulong to bool 255 if not noteval index 256 ret false 257 end 258 n = get32 12 259 for i ulong 128 260 put Note i 0 261 end 262 for i ulong n 263 put Note i get Unit add i 64 264 end 265 put Ns 0 n 266 put Ns 1 index 267 put Ns 2 get32 20 268 put Ns 3 get32 24 269 ret true 270 end 271 fn noteenc to bool 272 n = get Ns 0 273 if or eq n 0 ge n 128 274 ret false 275 end 276 if or gt get Ns 1 511 gt get Ns 2 `4294967295` 277 ret false 278 end 279 if gt get Ns 3 1 280 ret false 281 end 282 for i ulong n 283 c = get Note i 284 if or lt c 32 gt c 126 285 ret false 286 end 287 end 288 for i ulong 4096 289 put Unit i 0 290 end 291 for i ulong 8 292 put Unit i get Nmagic i 293 end 294 put32 8 1 295 put32 12 n 296 put32 16 get Ns 1 297 put32 20 get Ns 2 298 put32 24 get Ns 3 299 for i ulong n 300 put Unit add i 64 get Note i 301 end 302 seal n 303 for i ulong 4096 304 put Enc i get Unit i 305 end 306 ret true 307 end 308 note Store St gen,newest,valid. Tx phase,target,newgen. Provider owns actual I/O. 309 global St ulong 3 310 global Nt ulong 2 311 global Load ulong 1 312 global Tx ulong 3 313 fn txbegin to bool 314 if ne get Nt 0 0 315 ret false 316 end 317 if or ne get Tx 0 0 eq get St 0 `18446744073709551615` 318 ret false 319 end 320 if not memenc add get St 0 1 321 ret false 322 end 323 put Tx 1 0 324 if ne get St 0 0 325 put Tx 1 sub ulong 1 get St 1 326 end 327 put Tx 2 add get St 0 1 328 put Tx 0 1 329 ret true 330 end 331 fn txwrite ok bool to bool 332 if ne get Tx 0 1 333 ret false 334 end 335 if not ok 336 put Tx 0 0 337 ret false 338 end 339 put Tx 0 2 340 ret true 341 end 342 fn txflush ok bool to bool 343 if ne get Tx 0 2 344 ret false 345 end 346 if not ok 347 put Tx 0 0 348 ret false 349 end 350 put Tx 0 3 351 ret true 352 end 353 fn txread ok bool to bool 354 if ne get Tx 0 3 355 ret false 356 end 357 put Tx 0 0 358 if not ok 359 ret false 360 end 361 d = uchar 0 362 for i ulong 4096 363 d = or d xor get Unit i get Enc i 364 end 365 if ne d 0 366 ret false 367 end 368 put St 0 get Tx 2 369 put St 1 get Tx 1 370 if lt get St 2 2 371 put St 2 add get St 2 1 372 end 373 ret true 374 end 375 note Load each copy once into Unit. Caller resets St and calls loadcopy0,1. 376 fn loadbeg to void 377 for i ulong 3 378 put St i 0 379 end 380 put Load 0 0 381 end 382 fn loadcopy slot ulong to bool 383 if gt slot 1 384 ret false 385 end 386 if ne and get Load 0 shl ulong 1 slot 0 387 ret false 388 end 389 if not memvalid 390 ret false 391 end 392 put Load 0 or get Load 0 shl ulong 1 slot 393 put St 2 add get St 2 1 394 if gt get64 16 get St 0 395 b = memdec 396 put St 0 get Md 0 397 put St 1 slot 398 end 399 ret true 400 end 401 note Note transaction completes before the parent copy may publish its count. 402 fn nbegin to bool 403 if or ne get Nt 0 0 ne get Tx 0 0 404 ret false 405 end 406 if not noteenc 407 ret false 408 end 409 put Nt 1 get Ns 1 410 put Nt 0 1 411 ret true 412 end 413 fn nwrite ok bool to bool 414 if ne get Nt 0 1 415 ret false 416 end 417 if not ok 418 put Nt 0 0 419 ret false 420 end 421 put Nt 0 2 422 ret true 423 end 424 fn nflush ok bool to bool 425 if ne get Nt 0 2 426 ret false 427 end 428 if not ok 429 put Nt 0 0 430 ret false 431 end 432 put Nt 0 3 433 ret true 434 end 435 fn nread ok bool to bool 436 if ne get Nt 0 3 437 ret false 438 end 439 put Nt 0 0 440 if not ok 441 ret false 442 end 443 d = uchar 0 444 for i ulong 4096 445 d = or d xor get Enc i get Unit i 446 end 447 if ne d 0 448 ret false 449 end 450 ret noteval get Nt 1 451 end