Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cygwin support #704

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cpp_demangle = { default-features = false, version = "0.4.0", optional = true, f
"alloc",
] }

[target.'cfg(windows)'.dependencies]
[target.'cfg(any(windows, target_os = "cygwin"))'.dependencies]
windows-targets = "0.52.6"

[target.'cfg(not(all(windows, target_env = "msvc", not(target_vendor = "uwp"))))'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,5 +247,5 @@ mod lock {
))]
mod dbghelp;
// Auto-generated by windows-bindgen/riddle
#[cfg(windows)]
#[cfg(any(windows, target_os = "cygwin"))]
mod windows_sys;
4 changes: 2 additions & 2 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fn mmap(path: &Path) -> Option<Mmap> {
}

cfg_if::cfg_if! {
if #[cfg(windows)] {
if #[cfg(any(windows, target_os = "cygwin"))] {
mod coff;
use self::coff::{handle_split_dwarf, Object};
} else if #[cfg(any(target_vendor = "apple"))] {
Expand All @@ -209,7 +209,7 @@ cfg_if::cfg_if! {
}

cfg_if::cfg_if! {
if #[cfg(windows)] {
if #[cfg(any(windows, target_os = "cygwin"))] {
mod libs_windows;
use libs_windows::native_libraries;
} else if #[cfg(target_vendor = "apple")] {
Expand Down
33 changes: 31 additions & 2 deletions src/symbolize/gimli/libs_windows.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use super::super::super::windows_sys::*;
use super::mystd::ffi::OsString;
use super::mystd::os::windows::prelude::*;
use super::{coff, mmap, Library, LibrarySegment};
use alloc::vec;
use alloc::vec::Vec;
Expand Down Expand Up @@ -49,7 +48,37 @@ unsafe fn load_library(me: &MODULEENTRY32W) -> Option<Library> {
.iter()
.position(|i| *i == 0)
.unwrap_or(me.szExePath.len());
let name = OsString::from_wide(&me.szExePath[..pos]);
let name_len = unsafe {
WideCharToMultiByte(
CP_UTF8,
0,
me.szExePath.as_ptr(),
pos as i32,
core::ptr::null_mut(),
0,
core::ptr::null_mut(),
core::ptr::null_mut(),
) as usize
};
let mut name_buffer = vec![0_u8; name_len];
let name_len = unsafe {
WideCharToMultiByte(
CP_UTF8,
0,
me.szExePath.as_ptr(),
pos as i32,
name_buffer.as_mut_ptr(),
name_buffer.len() as i32,
core::ptr::null_mut(),
core::ptr::null_mut(),
) as usize
};
if name_len == 0 || name_len > name_buffer.len() {
// This can't happen.
return None;
}
unsafe { name_buffer.set_len(name_len) };
let name = unsafe { OsString::from_encoded_bytes_unchecked(name_buffer) };

// MinGW libraries currently don't support ASLR
// (rust-lang/rust#16514), but DLLs can still be relocated around in
Expand Down
Loading