aboutsummaryrefslogtreecommitdiffhomepage
path: root/zluda_inject/tests/helpers/do_cuinit_late.rs
diff options
context:
space:
mode:
Diffstat (limited to 'zluda_inject/tests/helpers/do_cuinit_late.rs')
-rw-r--r--zluda_inject/tests/helpers/do_cuinit_late.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/zluda_inject/tests/helpers/do_cuinit_late.rs b/zluda_inject/tests/helpers/do_cuinit_late.rs
new file mode 100644
index 0000000..ab3516d
--- /dev/null
+++ b/zluda_inject/tests/helpers/do_cuinit_late.rs
@@ -0,0 +1,23 @@
+#![crate_type = "bin"]
+
+use std::ffi::c_void;
+use std::mem;
+use std::env;
+use std::path::PathBuf;
+use std::ffi::CString;
+
+extern "system" {
+ fn LoadLibraryA(lpFileName: *const i8) -> *mut c_void;
+ fn GetProcAddress(hModule: *mut c_void, lpProcName: *const u8) -> *mut c_void;
+}
+
+fn main() {
+ let current_exe = env::current_exe().unwrap();
+ let mut dll = PathBuf::from(current_exe.parent().unwrap());
+ dll.push("do_cuinit.dll");
+ let dll_cstring = CString::new(dll.to_str().unwrap()).unwrap();
+ let nvcuda = unsafe { LoadLibraryA(dll_cstring.as_ptr()) };
+ let cu_init = unsafe { GetProcAddress(nvcuda, b"do_cuinit\0".as_ptr()) };
+ let cu_init = unsafe { mem::transmute::<_, unsafe extern "system" fn(u32) -> u32>(cu_init) };
+ unsafe { cu_init(0) };
+}