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/tests/arboris/caproot_issuer.c # 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 / tests / arboris / caproot_issuer.c` 91 lines ยท 4395 bytes Raw Blame History 1 /* SPDX-License-Identifier: AGPL-3.0-only 2 * Exercise the OM admission decision with the resident runtime's sealed table. */ 3 #include "runtime/rx_caproot.h" 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 11 #define GPU_RESOURCE UINT64_C(0x4152425247423130) 12 _Static_assert(sizeof(RxCapTable) == 22560 && sizeof(RxCapEntry) == 88, "caproot ABI"); 13 _Static_assert(offsetof(RxCapTable, entries) == 32 && offsetof(RxCapEntry, parent_generation) == 64, "caproot ABI"); 14 15 static int check(const char *program, const RxCapRoot *root, uint32_t subject, 16 RxCapRef ref, uint64_t epoch, uint64_t planned_gen, int allow) { 17 int input[2]; 18 if (pipe(input) < 0) return 1; 19 pid_t pid = fork(); 20 if (pid == 0) { 21 if (dup2(input[0], STDIN_FILENO) < 0 || dup2(root->ro_fd, 3) < 0 || 22 fcntl(3, F_SETFD, 0) < 0) _exit(126); 23 close(input[1]); 24 execl(program, program, (char *)NULL); 25 _exit(127); 26 } 27 close(input[0]); 28 uint64_t request[] = {subject, ref.cap_id, ref.generation, epoch, planned_gen, (uint64_t)allow}; 29 int bad = pid < 0 || write(input[1], request, sizeof request) != sizeof request; 30 close(input[1]); 31 int status; 32 if (pid <= 0 || waitpid(pid, &status, 0) != pid || !WIFEXITED(status)) return 1; 33 if (bad || WEXITSTATUS(status) != 0) { 34 fprintf(stderr, "admission test failed, expected %d, runner exit %d\n", allow, WEXITSTATUS(status)); 35 return 1; 36 } 37 return 0; 38 } 39 40 static int exercise(const char *program, RxCapRoot *root, RxCapAdmin *admin) { 41 RxCapMint mint = {.subject = 42, .resource = GPU_RESOURCE, .rights = RX_RIGHT_EFFECT | RX_RIGHT_DELEGATE, 42 .lease_ticks = 2, .parent = {UINT32_MAX, 0}, .authority = admin->office}; 43 RxCapRef parent, child, wrong; 44 if (rx_capadmin_mint(admin, &mint, &parent) != RX_CAP_OK) return 1; 45 mint.authority = mint.parent = parent; 46 mint.rights = RX_RIGHT_EFFECT; 47 mint.lease_ticks = 1; 48 if (rx_capadmin_mint(admin, &mint, &child) != RX_CAP_OK) return 1; 49 if (check(program, root, 42, child, 1, child.generation, 1) || 50 check(program, root, 43, child, 1, child.generation, 0) || 51 check(program, root, 42, child, 2, child.generation, 0) || 52 check(program, root, 42, child, 1, child.generation + 1, 0)) return 1; 53 mint.authority = admin->office; 54 mint.parent = (RxCapRef){UINT32_MAX, 0}; 55 mint.resource++; 56 if (rx_capadmin_mint(admin, &mint, &wrong) != RX_CAP_OK || 57 check(program, root, 42, wrong, 1, wrong.generation, 0)) return 1; 58 mint.resource = GPU_RESOURCE; 59 mint.rights = RX_RIGHT_READ; 60 if (rx_capadmin_mint(admin, &mint, &wrong) != RX_CAP_OK || 61 check(program, root, 42, wrong, 1, wrong.generation, 0)) return 1; 62 if (rx_capadmin_advance_clock(admin, admin->office, 1) != RX_CAP_OK || 63 check(program, root, 42, child, 1, child.generation, 0) || 64 check(program, root, 42, parent, 1, parent.generation, 1)) return 1; 65 if (rx_capadmin_revoke(admin, admin->office, parent) != RX_CAP_OK || 66 check(program, root, 42, parent, 1, parent.generation, 0)) return 1; 67 return 0; 68 } 69 70 int main(int argc, char **argv) { 71 RxCapRoot root; 72 RxCapAdmin admin; 73 int signed_step = argc == 3 && strcmp(argv[2], "--arboris-signed-silicon") == 0; 74 int benchmark = argc == 3 && strcmp(argv[2], "--arboris-benchmark") == 0; 75 int device = signed_step || benchmark || (argc == 3 && (strcmp(argv[2], "--sparse-silicon") == 0 || 76 strcmp(argv[2], "--arboris-silicon") == 0)); 77 if ((!device && argc != 2) || rx_caproot_start(&root, &admin) != RX_CAP_OK) return 1; 78 int result; 79 if (device) { 80 RxCapMint mint = {.subject = 42, .resource = GPU_RESOURCE, .rights = RX_RIGHT_EFFECT, 81 .parent = {UINT32_MAX, 0}, .authority = admin.office}; 82 RxCapRef ref; 83 result = rx_capadmin_mint(&admin, &mint, &ref) != RX_CAP_OK || 84 check(argv[1], &root, 42, ref, 1, ref.generation, benchmark ? 3 : signed_step ? 2 : 1); 85 } else { 86 result = exercise(argv[1], &root, &admin); 87 } 88 rx_caproot_stop(&root, &admin); 89 if (result == 0 && !device) puts("PASS sealed capability root, delegated effect, scope, epoch, generation, expiry and revocation"); 90 return result; 91 }