From 49f63eb021e03b5bdd09645d5e0e68bbeae781ee Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Tue, 28 Mar 2023 17:53:34 +0800 Subject: [PATCH] Check data segment range --- compiler/rustc_session/src/filesearch.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_session/src/filesearch.rs b/compiler/rustc_session/src/filesearch.rs index 5d8002b493e6..c6c910a3f4d4 100644 --- a/compiler/rustc_session/src/filesearch.rs +++ b/compiler/rustc_session/src/filesearch.rs @@ -89,9 +89,8 @@ fn current_dll_path() -> Result { // * 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::(); 64]; loop { if libc::loadquery( @@ -110,9 +109,9 @@ fn current_dll_path() -> Result { } 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));