| 52 | |
| 53 | impl Drop for CodeMemory { |
| 54 | fn drop(&mut self) { |
| 55 | // If there is a custom code memory handler, restore the |
| 56 | // original (non-executable) state of the memory. |
| 57 | // |
| 58 | // We do this rather than invoking `unpublish()` because we |
| 59 | // want to skip the mprotect() if we natively own the mmap and |
| 60 | // are going to munmap soon anyway. |
| 61 | if let Some(mem) = self.custom_code_memory.as_ref() { |
| 62 | if self.published && self.needs_executable { |
| 63 | let text = self.text(); |
| 64 | mem.unpublish_executable(text.as_ptr(), text.len()) |
| 65 | .expect("Executable memory unpublish failed"); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | // Drop the registrations before `self.mmap` since they (implicitly) refer to it. |
| 70 | #[cfg(has_host_compiler_backend)] |
| 71 | let _ = self.unwind_registration.take(); |
| 72 | #[cfg(feature = "debug-builtins")] |
| 73 | let _ = self.debug_registration.take(); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | fn _assert() { |