mirror of
https://github.com/ivall/xcl.git
synced 2026-11-24 05:14:57 +01:00
Merge PR #213
This commit is contained in:
@@ -1765,7 +1765,11 @@ mod tests {
|
||||
|
||||
fnd::SetLastError(0);
|
||||
assert_eq!(GetProcAddress(k32, std::ptr::null()), 0);
|
||||
assert_eq!(fnd::GetLastError(), win32_err);
|
||||
assert_eq!(fnd::GetLastError(), fnd::ERROR_INVALID_PARAMETER);
|
||||
// Windows' own answer; Wine's GetProcAddress says ERROR_PROC_NOT_FOUND instead
|
||||
if !crate::util::under_wine() {
|
||||
assert_eq!(win32_err, fnd::ERROR_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
// Non-zero ordinal lookup still resolves when valid (ordinal #1 on kernel32).
|
||||
assert_ne!(GetProcAddress(k32, 1usize as *const u8), 0);
|
||||
|
||||
@@ -341,9 +341,7 @@ pub fn run_main(m: &Arc<MappedModule>) -> u32 {
|
||||
};
|
||||
unsafe {
|
||||
// PEB.ImageBaseAddress → GetModuleHandle(NULL), resources with NULL module, …
|
||||
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
|
||||
let wine = GetProcAddress(GetModuleHandleA(c"ntdll.dll".as_ptr() as *const u8), c"wine_get_version".as_ptr() as *const u8).is_some();
|
||||
if wine {
|
||||
if crate::util::under_wine() {
|
||||
crate::xlog_info!("Wine: PEB.ImageBaseAddress left alone (its loader needs the real main image there)");
|
||||
} else {
|
||||
*(peb().add(0x10) as *mut usize) = m.base;
|
||||
|
||||
@@ -104,6 +104,16 @@ pub unsafe fn from_ansi_ptr(p: *const u8) -> Option<String> {
|
||||
Some(String::from_utf16_lossy(&buf))
|
||||
}
|
||||
|
||||
/// The process runs under Wine (its ntdll exports `wine_get_version`).
|
||||
pub fn under_wine() -> bool {
|
||||
use windows_sys::Win32::System::LibraryLoader::{GetModuleHandleA, GetProcAddress};
|
||||
static WINE: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
// SAFETY: ntdll is always loaded; both names are NUL-terminated.
|
||||
*WINE.get_or_init(|| unsafe {
|
||||
GetProcAddress(GetModuleHandleA(c"ntdll.dll".as_ptr() as *const u8), c"wine_get_version".as_ptr() as *const u8).is_some()
|
||||
})
|
||||
}
|
||||
|
||||
/// Normalised DLL key: lower-case file name, ".dll" appended when no extension.
|
||||
pub fn dll_key(name: &str) -> String {
|
||||
let base = name.rsplit(['\\', '/']).next().unwrap_or(name);
|
||||
|
||||
@@ -904,7 +904,11 @@ mod tests {
|
||||
)
|
||||
};
|
||||
assert_eq!(h, windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE);
|
||||
assert_eq!(unsafe { windows_sys::Win32::Foundation::GetLastError() }, expected);
|
||||
// Windows' own codes are the reference; Wine answers a directory opened with
|
||||
// FILE_FLAG_BACKUP_SEMANTICS and TRUNCATE_EXISTING with ERROR_FILE_EXISTS
|
||||
if !crate::util::under_wine() {
|
||||
assert_eq!(unsafe { windows_sys::Win32::Foundation::GetLastError() }, expected);
|
||||
}
|
||||
assert_eq!(v.open_decision("G:\\data", GENERIC_WRITE, TRUNCATE_EXISTING, flags), Decision::Fail(expected));
|
||||
}
|
||||
assert!(!v.visible_in_overlay("data"));
|
||||
|
||||
@@ -1289,7 +1289,13 @@ mod tests {
|
||||
.unwrap()
|
||||
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
|
||||
.collect();
|
||||
assert_eq!(ov_names, vec!["Hello.txt".to_string()]);
|
||||
if crate::util::under_wine() {
|
||||
// Wine's MoveFileExW succeeds on a case-only rename but keeps the old name
|
||||
assert_eq!(ov_names.len(), 1);
|
||||
assert!(ov_names[0].eq_ignore_ascii_case("Hello.txt"), "{ov_names:?}");
|
||||
} else {
|
||||
assert_eq!(ov_names, vec!["Hello.txt".to_string()]);
|
||||
}
|
||||
|
||||
// Exact self-rename is a safe no-op.
|
||||
let ok = unsafe { move_file_vfs(v, "G:\\data\\gone.txt", "G:\\data\\gone.txt", 0, real_move) };
|
||||
|
||||
Reference in New Issue
Block a user