|
34 | 34 | #include <sys/kernel.h> |
35 | 35 | #include <sys/devmap.h> |
36 | 36 | #include <sys/proc.h> |
| 37 | +#include <vm/vm.h> |
37 | 38 |
|
38 | 39 | #include <cheri/cheri.h> |
39 | 40 | #include <cheri/cheric.h> |
@@ -127,3 +128,37 @@ hybridabi_thread_setregs(struct thread *td, unsigned long entry_addr) |
127 | 128 | td, CHERI_CAP_USER_CODE_PERMS, CHERI_CAP_USER_CODE_BASE, |
128 | 129 | CHERI_CAP_USER_CODE_LENGTH, entry_addr)); |
129 | 130 | } |
| 131 | + |
| 132 | +int |
| 133 | +vm_map_prot2perms(int base, vm_prot_t prot) |
| 134 | +{ |
| 135 | + int perms = 0; |
| 136 | + |
| 137 | + if (prot & (VM_PROT_CAP | VM_PROT_NO_IMPLY_CAP)) { |
| 138 | + if (prot & (VM_PROT_READ | VM_PROT_COPY)) |
| 139 | + perms |= CHERI_PERM_LOAD; |
| 140 | + if (VM_PROT_HAS_READ_CAP(prot)) |
| 141 | + perms |= CHERI_PERM_LOAD_CAP | CHERI_PERM_MUTABLE_LOAD; |
| 142 | + if (prot & VM_PROT_WRITE) |
| 143 | + perms |= CHERI_PERM_STORE; |
| 144 | + if (VM_PROT_HAS_WRITE_CAP(prot)) |
| 145 | + perms |= CHERI_PERM_STORE_CAP | |
| 146 | + CHERI_PERM_STORE_LOCAL_CAP; |
| 147 | + } else { |
| 148 | + if (prot & (VM_PROT_READ | VM_PROT_COPY)) |
| 149 | + perms |= CHERI_PERM_LOAD | CHERI_PERM_LOAD_CAP | |
| 150 | + CHERI_PERM_MUTABLE_LOAD; |
| 151 | + if (prot & VM_PROT_WRITE) |
| 152 | + perms |= CHERI_PERM_STORE | CHERI_PERM_STORE_CAP | |
| 153 | + CHERI_PERM_STORE_LOCAL_CAP; |
| 154 | + } |
| 155 | + if (prot & VM_PROT_EXECUTE) |
| 156 | + perms |= CHERI_PERM_EXECUTE | CHERI_PERM_EXECUTIVE | |
| 157 | + CHERI_PERM_LOAD; |
| 158 | + |
| 159 | + base &= ~(CHERI_PERM_LOAD | CHERI_PERM_LOAD_CAP | CHERI_PERM_MUTABLE_LOAD | |
| 160 | + CHERI_PERM_STORE | CHERI_PERM_STORE_CAP | CHERI_PERM_STORE_LOCAL_CAP | |
| 161 | + CHERI_PERM_EXECUTE | CHERI_PERM_EXECUTIVE); |
| 162 | + |
| 163 | + return (base | perms); |
| 164 | +} |
0 commit comments