From e23d90df685534333f56b2aeb50996b757509157 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 21 Aug 2017 16:54:50 -0700 Subject: [PATCH 01/14] Add a function on `SharedLibrary` to go from an AVMA to an SVMA --- src/lib.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 4038e6b..b6fa00a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -244,6 +244,17 @@ pub trait SharedLibrary: Sized + Debug { /// See the module documentation for details. fn virtual_memory_bias(&self) -> Bias; + /// Given an AVMA within this shared library, convert it back to an SVMA by + /// removing this shared library's bias. + #[inline] + fn avma_to_svma(&self, address: Avma) -> Svma { + let bias = self.virtual_memory_bias(); + let reverse_bias = -bias.0; + Svma(unsafe { + address.0.offset(reverse_bias) + }) + } + /// Find all shared libraries in this process and invoke `f` with each one. fn each(f: F) where From 4e6635a834b77ec05c78a5e5cd49d57613f87420 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 21 Aug 2017 16:56:56 -0700 Subject: [PATCH 02/14] Bump to version 0.3.3 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 78f3adc..179c414 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0/MIT" name = "findshlibs" readme = "./README.md" repository = "https://github.com/fitzgen/findshlibs" -version = "0.3.2" +version = "0.3.3" [badges.coveralls] repository = "fitzgen/findshlibs" From 9fcb63673f35804ab8b77b7c0b8b9df628e6c6f7 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 11 Nov 2017 10:05:47 -0800 Subject: [PATCH 03/14] Clean up panic propagation in linux implementation --- src/linux/mod.rs | 68 ++++++++++++++---------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/src/linux/mod.rs b/src/linux/mod.rs index e12a9c4..5b0d79f 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -5,13 +5,11 @@ use super::Segment as SegmentTrait; use super::SharedLibrary as SharedLibraryTrait; use std::any::Any; -use std::cell::RefCell; use std::ffi::CStr; use std::isize; use std::marker::PhantomData; use std::os::raw; use std::panic; -use std::process; use std::slice; mod bindings; @@ -99,13 +97,13 @@ pub struct SharedLibrary<'a> { headers: &'a [Phdr], } -thread_local! { - static PANIC_VALUE: RefCell>> = RefCell::new(None); +struct IterState { + f: F, + panic: Option>, } const CONTINUE: raw::c_int = 0; const BREAK: raw::c_int = 1; -const PANIC: raw::c_int = 2; impl<'a> SharedLibrary<'a> { unsafe fn new(info: &'a bindings::dl_phdr_info, size: usize) -> Self { @@ -119,46 +117,24 @@ impl<'a> SharedLibrary<'a> { unsafe extern "C" fn callback(info: *mut bindings::dl_phdr_info, size: usize, - f: *mut raw::c_void) + state: *mut raw::c_void) -> raw::c_int where F: FnMut(&Self) -> C, C: Into { - // XXX: We must be very careful to avoid unwinding back into C code - // here, which is UB. We attempt to shepherd the panic across the C - // frames, by stashing it in the `PANIC_VALUE` thread local, and then - // resuming the panic after we exit the `dl_iterate_phdr` call. If, - // however, we panic *again* while stashing the panic value, then we are - // left with no choice but to abort. + let state = &mut *(state as *mut IterState); match panic::catch_unwind(panic::AssertUnwindSafe(|| { - let f = f as *mut F; - let f = f.as_mut().unwrap(); - let info = info.as_ref().unwrap(); let shlib = SharedLibrary::new(info, size); - f(&shlib).into() + (state.f)(&shlib).into() })) { Ok(IterationControl::Continue) => CONTINUE, Ok(IterationControl::Break) => BREAK, Err(panicked) => { - if let Err(_) = panic::catch_unwind(panic::AssertUnwindSafe(|| { - PANIC_VALUE.with(|p| { - *p.borrow_mut() = Some(panicked); - }); - })) { - // Try and print out a diagnostic message before aborting. - let _ = panic::catch_unwind(|| { - eprintln!( - "findshlibs: aborting due to double-panic when unwinding a panic \ - across C frames" - ); - }); - process::abort(); - } - - PANIC + state.panic = Some(panicked); + BREAK } } } @@ -185,25 +161,21 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { } #[inline] - fn each(mut f: F) + fn each(f: F) where F: FnMut(&Self) -> C, C: Into { - match unsafe { - bindings::dl_iterate_phdr(Some(Self::callback::), &mut f as *mut _ as *mut _) - } { - r if r == BREAK || r == CONTINUE => return, - r if r == PANIC => { - panic::resume_unwind(PANIC_VALUE.with(|p| { - p.borrow_mut() - .take() - .expect("dl_iterate_phdr returned PANIC, but we don't have a PANIC_VALUE") - })) - } - otherwise => unreachable!( - "dl_iterate_phdr returned some value we never return from our callback: {}", - otherwise - ) + let mut state = IterState { + f: f, + panic: None, + }; + + unsafe { + bindings::dl_iterate_phdr(Some(Self::callback::), &mut state as *mut _ as *mut _); + } + + if let Some(panic) = state.panic { + panic::resume_unwind(panic); } } } From 44e1a3e0d2bbad249586accd2c99579f16a6983c Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sat, 11 Nov 2017 16:21:58 -0800 Subject: [PATCH 04/14] Update dependencies ...and replace deprecated bindgen methods with the non-deprecated versions. --- Cargo.toml | 6 +++--- build.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 179c414..6b8bfa3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,11 +16,11 @@ repository = "fitzgen/findshlibs" [build-dependencies.bindgen] default-features = false -version = "0.29.0" +version = "0.31.3" [dependencies] -cfg-if = "0.1.0" -lazy_static = "0.2.2" +cfg-if = "0.1.2" +lazy_static = "0.2.9" [features] nightly = [] diff --git a/build.rs b/build.rs index e4514c8..a0fb9c9 100644 --- a/build.rs +++ b/build.rs @@ -16,9 +16,9 @@ fn main() { fn generate_linux_bindings() { let bindings = bindgen::Builder::default() .header("./src/linux/bindings.h") - .whitelisted_function("dl_iterate_phdr") - .whitelisted_type(r#"Elf\d*.*"#) - .whitelisted_var("PT_.*") + .whitelist_function("dl_iterate_phdr") + .whitelist_type(r#"Elf\d*.*"#) + .whitelist_var("PT_.*") .generate() .expect("Should generate linux FFI bindings OK"); @@ -31,12 +31,12 @@ fn generate_linux_bindings() { fn generate_macos_bindings() { let bindings = bindgen::Builder::default() .header("./src/macos/bindings.h") - .whitelisted_function("_dyld_.*") - .whitelisted_type("mach_header.*") - .whitelisted_type("load_command.*") - .whitelisted_type("segment_command.*") - .whitelisted_var("MH_MAGIC.*") - .whitelisted_var("LC_SEGMENT.*") + .whitelist_function("_dyld_.*") + .whitelist_type("mach_header.*") + .whitelist_type("load_command.*") + .whitelist_type("segment_command.*") + .whitelist_var("MH_MAGIC.*") + .whitelist_var("LC_SEGMENT.*") .generate() .expect("Should generate macOS FFI bindings OK"); From 9adf2a266f2e2a3da8a91a4f837624d4850614ce Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Sun, 12 Nov 2017 14:11:49 -0800 Subject: [PATCH 05/14] Updte links to point to gimli-rs/findshlibs instead of fitzgen/findshlibs --- Cargo.toml | 7 ++++--- README.md | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 179c414..50da044 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,13 +6,14 @@ keywords = ["dyld", "dylib", "shared", "library", "dl_iterate_phdr"] license = "Apache-2.0/MIT" name = "findshlibs" readme = "./README.md" -repository = "https://github.com/fitzgen/findshlibs" +repository = "https://github.com/gimli-rs/findshlibs" version = "0.3.3" + [badges.coveralls] -repository = "fitzgen/findshlibs" +repository = "gimli-rs/findshlibs" [badges.travis-ci] -repository = "fitzgen/findshlibs" +repository = "gimli-rs/findshlibs" [build-dependencies.bindgen] default-features = false diff --git a/README.md b/README.md index 2517cf3..e6b331f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # `findshlibs` -[![](http://meritbadge.herokuapp.com/findshlibs) ![](https://img.shields.io/crates/d/findshlibs.png)](https://crates.io/crates/findshlibs) [![Build Status](https://travis-ci.org/fitzgen/findshlibs.png?branch=master)](https://travis-ci.org/fitzgen/findshlibs) [![Coverage Status](https://coveralls.io/repos/github/fitzgen/findshlibs/badge.svg?branch=master)](https://coveralls.io/github/fitzgen/findshlibs?branch=master) +[![](http://meritbadge.herokuapp.com/findshlibs) ![](https://img.shields.io/crates/d/findshlibs.png)](https://crates.io/crates/findshlibs) [![Build Status](https://travis-ci.org/gimli-rs/findshlibs.png?branch=master)](https://travis-ci.org/gimli-rs/findshlibs) [![Coverage Status](https://coveralls.io/repos/github/gimli-rs/findshlibs/badge.svg?branch=master)](https://coveralls.io/github/gimli-rs/findshlibs?branch=master) Find the shared libraries loaded in the current process with a cross platform API. From 3d6f6d24e18e558ae040f0ca303b57a62283301f Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Apr 2018 20:56:02 +0200 Subject: [PATCH 06/14] Fixed deprecated usage of tyvar_behind_raw_pointer --- src/macos/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/macos/mod.rs b/src/macos/mod.rs index 33c148a..ccd799a 100644 --- a/src/macos/mod.rs +++ b/src/macos/mod.rs @@ -141,7 +141,8 @@ impl<'a> MachHeader<'a> { MachType::from_header_ptr(header).and_then(|ty| { match ty { MachType::Mach32 => header.as_ref().map(MachHeader::Header32), - MachType::Mach64 => (header as *const _).as_ref().map(MachHeader::Header64), + MachType::Mach64 => (header as *const bindings::mach_header_64) + .as_ref().map(MachHeader::Header64), } }) } From 9d83263fa4deaf71cd8e4e88fada0e9386bb709f Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Apr 2018 21:29:23 +0200 Subject: [PATCH 07/14] Added support for fetching IDs from a shared library --- build.rs | 2 ++ src/lib.rs | 37 +++++++++++++++++++++++++++++++++++++ src/macos/mod.rs | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/build.rs b/build.rs index a0fb9c9..0355e20 100644 --- a/build.rs +++ b/build.rs @@ -34,9 +34,11 @@ fn generate_macos_bindings() { .whitelist_function("_dyld_.*") .whitelist_type("mach_header.*") .whitelist_type("load_command.*") + .whitelist_type("uuid_command.*") .whitelist_type("segment_command.*") .whitelist_var("MH_MAGIC.*") .whitelist_var("LC_SEGMENT.*") + .whitelist_var("LC_UUID.*") .generate() .expect("Should generate macOS FFI bindings OK"); diff --git a/src/lib.rs b/src/lib.rs index b6fa00a..39542d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -225,6 +225,40 @@ pub trait Segment: Sized + Debug { } } +/// Represents an ID for a shared library. +#[derive(PartialEq, Eq, Hash)] +pub enum SharedLibraryId { + /// A UUID (used on mac) + Uuid([u8; 16]), +} + +impl fmt::Display for SharedLibraryId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + SharedLibraryId::Uuid(ref bytes) => { + for (idx, byte) in bytes.iter().enumerate() { + if idx == 4 || idx == 6 || idx == 8 || idx == 10 { + try!(write!(f, "-")); + } + try!(write!(f, "{:02x}", byte)); + } + } + } + Ok(()) + } +} + +impl fmt::Debug for SharedLibraryId { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + SharedLibraryId::Uuid(..) => { + write!(f, "Uuid(\"{}\")", self)?; + } + } + Ok(()) + } +} + /// A trait representing a shared library that is loaded in this process. pub trait SharedLibrary: Sized + Debug { /// The associated segment type for this shared library. @@ -236,6 +270,9 @@ pub trait SharedLibrary: Sized + Debug { /// Get the name of this shared library. fn name(&self) -> &CStr; + /// Get the debug-id of this shared library if available. + fn id(&self) -> Option { None } + /// Iterate over this shared library's segments. fn segments(&self) -> Self::SegmentIter; diff --git a/src/macos/mod.rs b/src/macos/mod.rs index ccd799a..39b289d 100644 --- a/src/macos/mod.rs +++ b/src/macos/mod.rs @@ -1,7 +1,7 @@ //! The MacOS implementation of the [SharedLibrary //! trait](../trait.SharedLibrary.html). -use super::{Bias, IterationControl, Svma}; +use super::{Bias, IterationControl, Svma, SharedLibraryId}; use super::Segment as SegmentTrait; use super::SharedLibrary as SharedLibraryTrait; @@ -74,6 +74,26 @@ pub struct SegmentIter<'a> { num_commands: usize, } +impl<'a> SegmentIter<'a> { + fn find_uuid(&self) -> Option<[u8; 16]> { + let mut num_commands = self.num_commands; + let mut commands = self.commands; + + while num_commands > 0 { + num_commands -= 1; + let this_command = unsafe { commands.as_ref().unwrap() }; + let command_size = this_command.cmdsize as isize; + if let bindings::LC_UUID = this_command.cmd { + let uuid_cmd = commands as *const bindings::uuid_command; + return Some(unsafe { (*uuid_cmd).uuid }); + } + commands = unsafe { (commands as *const u8).offset(command_size) as *const _ }; + } + + None + } +} + impl<'a> Iterator for SegmentIter<'a> { type Item = Segment<'a>; @@ -180,6 +200,10 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { self.name } + fn id(&self) -> Option { + self.segments().find_uuid().map(SharedLibraryId::Uuid) + } + fn segments(&self) -> Self::SegmentIter { match self.header { MachHeader::Header32(header) => { @@ -291,6 +315,13 @@ mod tests { }); } + #[test] + fn get_id() { + macos::SharedLibrary::each(|shlib| { + assert!(shlib.id().is_some()); + }); + } + #[test] fn have_text_or_pagezero() { macos::SharedLibrary::each(|shlib| { From 117544868d2755cbba7bc1c2ea84d921e871bfa5 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Apr 2018 21:34:58 +0200 Subject: [PATCH 08/14] Do not implement defaults for id() --- src/lib.rs | 2 +- src/linux/mod.rs | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 39542d2..30645d0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -271,7 +271,7 @@ pub trait SharedLibrary: Sized + Debug { fn name(&self) -> &CStr; /// Get the debug-id of this shared library if available. - fn id(&self) -> Option { None } + fn id(&self) -> Option; /// Iterate over this shared library's segments. fn segments(&self) -> Self::SegmentIter; diff --git a/src/linux/mod.rs b/src/linux/mod.rs index 5b0d79f..b104ac4 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -1,6 +1,6 @@ //! Linux-specific implementation of the `SharedLibrary` trait. -use super::{Bias, IterationControl, Svma}; +use super::{Bias, IterationControl, Svma, SharedLibraryId}; use super::Segment as SegmentTrait; use super::SharedLibrary as SharedLibraryTrait; @@ -55,6 +55,10 @@ impl<'a> SegmentTrait for Segment<'a> { } } + fn id(&self) -> Option { + None + } + #[inline] fn stated_virtual_memory_address(&self) -> Svma { Svma(unsafe { From 319b897fb284ae0ed1c199c8f6006ca1188124ec Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Apr 2018 22:23:41 +0200 Subject: [PATCH 09/14] Added a default implementation for unsupported platforms. Fixes #14 --- build.rs | 2 -- src/lib.rs | 15 +++++++- src/unsupported.rs | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 src/unsupported.rs diff --git a/build.rs b/build.rs index 0355e20..4a6c8c4 100644 --- a/build.rs +++ b/build.rs @@ -8,8 +8,6 @@ fn main() { generate_linux_bindings(); } else if cfg!(target_os = "macos") { generate_macos_bindings(); - } else { - panic!("`findshlibs` does not support the target OS :("); } } diff --git a/src/lib.rs b/src/lib.rs index 30645d0..40800a9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -83,6 +83,8 @@ use std::ffi::CStr; use std::fmt::{self, Debug}; use std::ptr; +pub mod unsupported; + cfg_if!( if #[cfg(target_os = "linux")] { @@ -92,6 +94,9 @@ cfg_if!( /// implementation for the target operating system. pub type TargetSharedLibrary<'a> = linux::SharedLibrary<'a>; + /// An indicator if this platform is supported. + pub const TARGET_SUPPORTED: bool = true; + } else if #[cfg(target_os = "macos")] { pub mod macos; @@ -100,9 +105,17 @@ cfg_if!( /// implementation for the target operating system. pub type TargetSharedLibrary<'a> = macos::SharedLibrary<'a>; + /// An indicator if this platform is supported. + pub const TARGET_SUPPORTED: bool = true; + } else { - // No implementation for this platform :( + /// The [`SharedLibrary` trait](./trait.SharedLibrary.html) + /// implementation for the target operating system. + pub type TargetSharedLibrary<'a> = unsupported::SharedLibrary<'a>; + + /// An indicator if this platform is supported. + pub const TARGET_SUPPORTED: bool = false; } ); diff --git a/src/unsupported.rs b/src/unsupported.rs new file mode 100644 index 0000000..20fdf2a --- /dev/null +++ b/src/unsupported.rs @@ -0,0 +1,88 @@ +//! The fallback implementation of the [SharedLibrary +//! trait](../trait.SharedLibrary.html) that does nothing. + +use super::{Bias, IterationControl, Svma, SharedLibraryId}; +use super::Segment as SegmentTrait; +use super::SharedLibrary as SharedLibraryTrait; + +use std::ffi::CStr; +use std::marker::PhantomData; +use std::usize; + +/// An unsupported segment +#[derive(Debug)] +pub struct Segment<'a> { + phantom: PhantomData<&'a SharedLibrary<'a>>, +} + +impl<'a> SegmentTrait for Segment<'a> { + type SharedLibrary = ::unsupported::SharedLibrary<'a>; + + #[inline] + fn name(&self) -> &CStr { + unreachable!() + } + + #[inline] + fn stated_virtual_memory_address(&self) -> Svma { + unreachable!() + } + + #[inline] + fn len(&self) -> usize { + unreachable!() + } +} + +/// An iterator over Mach-O segments. +#[derive(Debug)] +pub struct SegmentIter<'a> { + phantom: PhantomData<&'a SharedLibrary<'a>>, +} + +impl<'a> Iterator for SegmentIter<'a> { + type Item = Segment<'a>; + + fn next(&mut self) -> Option { + None + } +} + + +/// The fallback implementation of the [SharedLibrary +/// trait](../trait.SharedLibrary.html). +#[derive(Debug)] +pub struct SharedLibrary<'a> { + phantom: PhantomData<&'a SharedLibrary<'a>>, +} + +impl<'a> SharedLibraryTrait for SharedLibrary<'a> { + type Segment = Segment<'a>; + type SegmentIter = SegmentIter<'a>; + + #[inline] + fn name(&self) -> &CStr { + unsafe { CStr::from_bytes_with_nul_unchecked(b"\x00") } + } + + fn id(&self) -> Option { + None + } + + fn segments(&self) -> Self::SegmentIter { + SegmentIter { + phantom: PhantomData, + } + } + + #[inline] + fn virtual_memory_bias(&self) -> Bias { + Bias(0) + } + + fn each(_f: F) + where F: FnMut(&Self) -> C, + C: Into + { + } +} From 2deb38a69c5e1e723a53730effd9fd2801c398d1 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 10 Apr 2018 22:35:59 +0200 Subject: [PATCH 10/14] Moved a method to the right trait implementation --- src/linux/mod.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/linux/mod.rs b/src/linux/mod.rs index b104ac4..ccb0f51 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -55,10 +55,6 @@ impl<'a> SegmentTrait for Segment<'a> { } } - fn id(&self) -> Option { - None - } - #[inline] fn stated_virtual_memory_address(&self) -> Svma { Svma(unsafe { @@ -153,6 +149,11 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { self.name } + #[inline] + fn id(&self) -> Option { + None + } + #[inline] fn segments(&self) -> Self::SegmentIter { SegmentIter { inner: self.headers.iter() } From e75edf50136dafe1e7d46ee8c35a11949b2a7319 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Wed, 11 Apr 2018 00:56:11 +0200 Subject: [PATCH 11/14] Made some methods unreachable! and documented fallback behavior --- README.md | 4 ++++ src/lib.rs | 4 ++++ src/unsupported.rs | 6 +++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e6b331f..4cdb0e2 100644 --- a/README.md +++ b/README.md @@ -39,4 +39,8 @@ These are the OSes that `findshlibs` currently supports: * Linux * macOS +If a platform is not supported then a fallback implementation is used that +does nothing. To see if your platform does something at runtime the +`TARGET_SUPPORTED` constant can be used. + Is your OS missing here? Send us a pull request! diff --git a/src/lib.rs b/src/lib.rs index 40800a9..a9e0143 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,6 +36,10 @@ //! * Linux //! * macOS //! +//! If a platform is not supported then a fallback implementation is used that +//! does nothing. To see if your platform does something at runtime the +//! `TARGET_SUPPORTED` constant can be used. +//! //! Is your OS missing here? Send us a pull request! //! //! ## Addresses diff --git a/src/unsupported.rs b/src/unsupported.rs index 20fdf2a..24f37a8 100644 --- a/src/unsupported.rs +++ b/src/unsupported.rs @@ -62,11 +62,11 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { #[inline] fn name(&self) -> &CStr { - unsafe { CStr::from_bytes_with_nul_unchecked(b"\x00") } + unreachable!() } fn id(&self) -> Option { - None + unreachable!() } fn segments(&self) -> Self::SegmentIter { @@ -77,7 +77,7 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { #[inline] fn virtual_memory_bias(&self) -> Bias { - Bias(0) + unreachable!() } fn each(_f: F) From c9c2cbfe62e580661636ba6f55792a57872a1b79 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 13 Apr 2018 15:30:48 -0700 Subject: [PATCH 12/14] Run `cargo fmt` --- src/lib.rs | 13 ++++++++----- src/unsupported.rs | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a9e0143..7ccc67b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -304,9 +304,7 @@ pub trait SharedLibrary: Sized + Debug { fn avma_to_svma(&self, address: Avma) -> Svma { let bias = self.virtual_memory_bias(); let reverse_bias = -bias.0; - Svma(unsafe { - address.0.offset(reverse_bias) - }) + Svma(unsafe { address.0.offset(reverse_bias) }) } /// Find all shared libraries in this process and invoke `f` with each one. @@ -340,10 +338,15 @@ mod tests { fn panic_in_each() { use std::panic; - match panic::catch_unwind(|| { TargetSharedLibrary::each(|_| panic!("uh oh")); }) { + match panic::catch_unwind(|| { + TargetSharedLibrary::each(|_| panic!("uh oh")); + }) { Ok(()) => panic!("Expected a panic, but didn't get one"), Err(any) => { - assert!(any.is::<&'static str>(), "panic value should be a &'static str"); + assert!( + any.is::<&'static str>(), + "panic value should be a &'static str" + ); assert_eq!(*any.downcast_ref::<&'static str>().unwrap(), "uh oh"); } } diff --git a/src/unsupported.rs b/src/unsupported.rs index 24f37a8..5da7d5f 100644 --- a/src/unsupported.rs +++ b/src/unsupported.rs @@ -1,9 +1,9 @@ //! The fallback implementation of the [SharedLibrary //! trait](../trait.SharedLibrary.html) that does nothing. -use super::{Bias, IterationControl, Svma, SharedLibraryId}; use super::Segment as SegmentTrait; use super::SharedLibrary as SharedLibraryTrait; +use super::{Bias, IterationControl, SharedLibraryId, Svma}; use std::ffi::CStr; use std::marker::PhantomData; @@ -48,7 +48,6 @@ impl<'a> Iterator for SegmentIter<'a> { } } - /// The fallback implementation of the [SharedLibrary /// trait](../trait.SharedLibrary.html). #[derive(Debug)] @@ -81,8 +80,9 @@ impl<'a> SharedLibraryTrait for SharedLibrary<'a> { } fn each(_f: F) - where F: FnMut(&Self) -> C, - C: Into + where + F: FnMut(&Self) -> C, + C: Into, { } } From df036c6d288db62e519ab51b5a683c279b86e02c Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Fri, 13 Apr 2018 15:33:35 -0700 Subject: [PATCH 13/14] Update dependencies to their latest versions --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 27ac018..ac3fa44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,11 @@ repository = "gimli-rs/findshlibs" [build-dependencies.bindgen] default-features = false -version = "0.31.3" +version = "0.36.0" [dependencies] cfg-if = "0.1.2" -lazy_static = "0.2.9" +lazy_static = "1.0.0" [features] nightly = [] From 0c91beb5db7985736a00c3befcb6e58dc99f08c1 Mon Sep 17 00:00:00 2001 From: Nick Fitzgerald Date: Mon, 16 Apr 2018 10:05:40 -0700 Subject: [PATCH 14/14] Bump to version 0.4.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ac3fa44..f06d37f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0/MIT" name = "findshlibs" readme = "./README.md" repository = "https://github.com/gimli-rs/findshlibs" -version = "0.3.3" +version = "0.4.0" [badges.coveralls] repository = "gimli-rs/findshlibs"