From 7a3b453fbb001f5ed68e36ec8a85c88c0fb6aff9 Mon Sep 17 00:00:00 2001
From: 4lDO2 <4lDO2@protonmail.com>
Date: Thu, 27 Jul 2023 15:34:33 +0200
Subject: [PATCH] Declare __usercopy_{start,end} as functions.

---
 src/arch/x86_64/paging/mod.rs | 7 ++-----
 src/lib.rs                    | 2 +-
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs
index b8a760f6..51881f0f 100644
--- a/src/arch/x86_64/paging/mod.rs
+++ b/src/arch/x86_64/paging/mod.rs
@@ -19,6 +19,7 @@ pub use super::CurrentRmmArch as RmmA;
 pub type PageMapper = rmm::PageMapper<RmmA, crate::arch::rmm::LockedAllocator>;
 use crate::context::memory::{AccessMode, try_correcting_page_tables, PfError};
 use crate::interrupt::InterruptStack;
+use crate::kernel_executable_offsets::{__usercopy_end, __usercopy_start};
 pub use crate::rmm::KernelMapper;
 
 pub mod entry;
@@ -145,11 +146,7 @@ pub struct Segv;
 pub fn page_fault_handler(stack: &mut InterruptStack, code: PageFaultError, faulting_address: VirtualAddress) -> Result<(), Segv> {
     let faulting_page = Page::containing_address(faulting_address);
 
-    extern "C" {
-        static __usercopy_start: u8;
-        static __usercopy_end: u8;
-    }
-    let usercopy_region = unsafe { (&__usercopy_start as *const u8 as usize)..(&__usercopy_end as *const u8 as usize) };
+    let usercopy_region = __usercopy_start()..__usercopy_end();
 
     // TODO: Most likely not necessary, but maybe also check that cr2 is not too close to USER_END.
     let address_is_user = faulting_address.kind() == TableKind::User;
diff --git a/src/lib.rs b/src/lib.rs
index 3d77cc36..78007aae 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -294,5 +294,5 @@ macro_rules! linker_offsets(
     }
 );
 pub mod kernel_executable_offsets {
-    linker_offsets!(__text_start, __text_end, __rodata_start, __rodata_end, __data_start, __data_end, __bss_start, __bss_end, __tdata_start, __tdata_end, __tbss_start, __tbss_end);
+    linker_offsets!(__text_start, __text_end, __rodata_start, __rodata_end, __data_start, __data_end, __bss_start, __bss_end, __tdata_start, __tdata_end, __tbss_start, __tbss_end, __usercopy_start, __usercopy_end);
 }
-- 
GitLab