mirror of
https://github.com/vosen/ZLUDA.git
synced 2025-08-02 14:57:43 +03:00
Re-fix
This commit is contained in:
@ -56,10 +56,7 @@ pub(crate) struct CudaDynamicFns {
|
||||
|
||||
impl CudaDynamicFns {
|
||||
pub(crate) unsafe fn load_library(path: &str) -> Option<Self> {
|
||||
let lib: libloading::os::unix::Library = zluda_trace_common::dlopen_local_noredirect(path)
|
||||
.ok()?
|
||||
.into();
|
||||
let lib_handle = NonNull::new(lib.into_raw())?;
|
||||
let lib_handle = os::dlopen_local_noredirect(path).ok()?;
|
||||
Some(CudaDynamicFns {
|
||||
lib_handle,
|
||||
fn_table: CudaFnTable::default(),
|
||||
|
@ -4,6 +4,14 @@ use std::mem;
|
||||
|
||||
pub(crate) const LIBCUDA_DEFAULT_PATH: &str = "/usr/lib/x86_64-linux-gnu/libcuda.so.1";
|
||||
|
||||
pub fn dlopen_local_noredirect<'a>(
|
||||
path: impl Into<Cow<'a, str>>,
|
||||
) -> Result<NonNull<c_void>, libloading::Error> {
|
||||
let lib: libloading::os::unix::Library =
|
||||
zluda_trace_common::dlopen_local_noredirect(path)?.into();
|
||||
NonNull::new(lib.into_raw()).ok_or(libloading::Error::DlOpenUnknown)
|
||||
}
|
||||
|
||||
pub unsafe fn get_proc_address(handle: *mut c_void, func: &CStr) -> *mut c_void {
|
||||
libc::dlsym(handle, func.as_ptr() as *const _)
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
use cuda_types::cuda::CUuuid;
|
||||
use std::borrow::Cow;
|
||||
use std::os::windows::io::AsRawHandle;
|
||||
use std::ptr::NonNull;
|
||||
use std::{
|
||||
ffi::{c_void, CStr},
|
||||
mem, ptr,
|
||||
@ -15,6 +17,14 @@ pub(crate) const LIBCUDA_DEFAULT_PATH: &'static str = "C:\\Windows\\System32\\nv
|
||||
const LOAD_LIBRARY_NO_REDIRECT: &'static [u8] = b"ZludaLoadLibraryW_NoRedirect\0";
|
||||
const GET_PROC_ADDRESS_NO_REDIRECT: &'static [u8] = b"ZludaGetProcAddress_NoRedirect\0";
|
||||
|
||||
pub fn dlopen_local_noredirect<'a>(
|
||||
path: impl Into<Cow<'a, str>>,
|
||||
) -> Result<NonNull<c_void>, libloading::Error> {
|
||||
let lib: libloading::os::windows::Library =
|
||||
zluda_trace_common::dlopen_local_noredirect(path)?.into();
|
||||
NonNull::new(lib.into_raw() as *mut _).ok_or(libloading::Error::DlOpenUnknown)
|
||||
}
|
||||
|
||||
static PLATFORM_LIBRARY: LazyLock<PlatformLibrary> =
|
||||
LazyLock::new(|| unsafe { PlatformLibrary::new() });
|
||||
|
||||
|
@ -95,6 +95,7 @@ pub(crate) mod os {
|
||||
#[cfg(windows)]
|
||||
pub(crate) mod os {
|
||||
use libloading::os;
|
||||
use std::borrow::Cow;
|
||||
|
||||
pub fn open_driver() -> Result<libloading::Library, libloading::Error> {
|
||||
os::windows::Library::open_already_loaded("nvcuda").map(Into::into)
|
||||
@ -104,7 +105,7 @@ pub(crate) mod os {
|
||||
path: Cow<'a, str>,
|
||||
) -> Result<libloading::Library, libloading::Error> {
|
||||
fn terminate_with_nul(mut path: Vec<u16>) -> Vec<u16> {
|
||||
if !path.ends_with(0) {
|
||||
if path.last().copied() == Some(0) {
|
||||
path.push(0);
|
||||
}
|
||||
path
|
||||
@ -123,7 +124,7 @@ pub(crate) mod os {
|
||||
Ok(libloading::os::windows::Library::from_raw(symbol).into())
|
||||
}
|
||||
}
|
||||
Err(_) => libloading::Library::new(path),
|
||||
Err(_) => libloading::Library::new(&*path),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user