about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKai Luo <lkail@cn.ibm.com>2023-03-28 17:53:34 +0800
committerKai Luo <lkail@cn.ibm.com>2023-03-28 17:54:12 +0800
commit49f63eb021e03b5bdd09645d5e0e68bbeae781ee (patch)
tree5d0d45b809ac5e4d8246ba2bd244c5d7648b817b
parent82bfdc8aaa119b5d8484ae9c95f37c43509ef796 (diff)
downloadrust-49f63eb021e03b5bdd09645d5e0e68bbeae781ee.tar.gz
rust-49f63eb021e03b5bdd09645d5e0e68bbeae781ee.zip
Check data segment range
-rw-r--r--compiler/rustc_session/src/filesearch.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs
index 5d8002b493e..c6c910a3f4d 100644
--- a/compiler/rustc_session/src/filesearch.rs
+++ b/compiler/rustc_session/src/filesearch.rs
@@ -89,9 +89,8 @@ fn current_dll_path() -> Result<PathBuf, String> {
         // * The address of the entry point of the function.
         // * The TOC base address for the function.
         // * The environment pointer.
-        // Deref `current_dll_path` directly so that we can get the address of `current_dll_path`'s
-        // entry point in text section.
-        let addr = *(current_dll_path as *const u64);
+        // The function descriptor is in the data section.
+        let addr = current_dll_path as u64;
         let mut buffer = vec![std::mem::zeroed::<libc::ld_info>(); 64];
         loop {
             if libc::loadquery(
@@ -110,9 +109,9 @@ fn current_dll_path() -> Result<PathBuf, String> {
         }
         let mut current = buffer.as_mut_ptr() as *mut libc::ld_info;
         loop {
-            let text_base = (*current).ldinfo_textorg as u64;
-            let text_end = text_base + (*current).ldinfo_textsize;
-            if (text_base..text_end).contains(&addr) {
+            let data_base = (*current).ldinfo_dataorg as u64;
+            let data_end = data_base + (*current).ldinfo_datasize;
+            if (data_base..data_end).contains(&addr) {
                 let bytes = CStr::from_ptr(&(*current).ldinfo_filename[0]).to_bytes();
                 let os = OsStr::from_bytes(bytes);
                 return Ok(PathBuf::from(os));