| 46 | } |
| 47 | |
| 48 | fn finalize(&mut self, branch_protection: BranchProtection) { |
| 49 | if self.finalized { |
| 50 | return; |
| 51 | } |
| 52 | |
| 53 | // Executable regions are handled separately to correctly deal with |
| 54 | // branch protection and cache coherence. |
| 55 | if self.target_prot == region::Protection::READ_EXECUTE { |
| 56 | super::set_readable_and_executable(self.ptr, self.len, branch_protection) |
| 57 | .expect("unable to set memory protection for jit memory segment"); |
| 58 | } else { |
| 59 | unsafe { |
| 60 | region::protect(self.ptr, self.len, self.target_prot) |
| 61 | .expect("unable to change memory protection for jit memory segment"); |
| 62 | } |
| 63 | } |
| 64 | self.finalized = true; |
| 65 | } |
| 66 | |
| 67 | // Note: We do pointer arithmetic on `ptr` passed to `Segment::new` here. |
| 68 | // This assumes that `ptr` is valid for `len` bytes, or will result in UB. |