| 475 | } |
| 476 | |
| 477 | fn custom_publish(&mut self) -> Result<bool> { |
| 478 | if let Some(mem) = self.custom_code_memory.as_ref() { |
| 479 | let text = self.text(); |
| 480 | // The text section should be aligned to |
| 481 | // `custom_code_memory.required_alignment()` due to a |
| 482 | // combination of two invariants: |
| 483 | // |
| 484 | // - MmapVec aligns its start address, even in owned-Vec mode; and |
| 485 | // - The text segment inside the ELF image will be aligned according |
| 486 | // to the platform's requirements. |
| 487 | let text_addr = text.as_ptr() as usize; |
| 488 | assert_eq!(text_addr & (mem.required_alignment() - 1), 0); |
| 489 | |
| 490 | // The custom code memory handler will ensure the |
| 491 | // memory is executable and also handle icache |
| 492 | // coherence. |
| 493 | mem.publish_executable(text.as_ptr(), text.len())?; |
| 494 | Ok(true) |
| 495 | } else { |
| 496 | Ok(false) |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /// "Unpublish" code memory (transition it from executable to read/writable). |
| 501 | /// |