diff options
Diffstat (limited to 'zluda_inject/tests/helpers')
-rw-r--r-- | zluda_inject/tests/helpers/do_cuinit.rs | 10 | ||||
-rw-r--r-- | zluda_inject/tests/helpers/do_cuinit_main.rs | 23 | ||||
-rw-r--r-- | zluda_inject/tests/helpers/indirect_cuinit.rs | 16 |
3 files changed, 49 insertions, 0 deletions
diff --git a/zluda_inject/tests/helpers/do_cuinit.rs b/zluda_inject/tests/helpers/do_cuinit.rs new file mode 100644 index 0000000..468d56c --- /dev/null +++ b/zluda_inject/tests/helpers/do_cuinit.rs @@ -0,0 +1,10 @@ +#![crate_type = "cdylib"]
+
+extern "system" {
+ fn cuInit(flags: u32) -> u32;
+}
+
+#[no_mangle]
+unsafe extern "system" fn do_cuinit(flags: u32) -> u32 {
+ cuInit(flags)
+}
diff --git a/zluda_inject/tests/helpers/do_cuinit_main.rs b/zluda_inject/tests/helpers/do_cuinit_main.rs new file mode 100644 index 0000000..4a24752 --- /dev/null +++ b/zluda_inject/tests/helpers/do_cuinit_main.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 cuInit = unsafe { GetProcAddress(nvcuda, b"do_cuinit\0".as_ptr()) };
+ let cuInit = unsafe { mem::transmute::<_, unsafe extern "system" fn(u32) -> u32>(cuInit) };
+ unsafe { cuInit(0) };
+}
diff --git a/zluda_inject/tests/helpers/indirect_cuinit.rs b/zluda_inject/tests/helpers/indirect_cuinit.rs new file mode 100644 index 0000000..3b4f1a7 --- /dev/null +++ b/zluda_inject/tests/helpers/indirect_cuinit.rs @@ -0,0 +1,16 @@ +#![crate_type = "bin"]
+
+use std::ffi::c_void;
+use std::mem;
+
+extern "system" {
+ fn LoadLibraryA(lpFileName: *const u8) -> *mut c_void;
+ fn GetProcAddress(hModule: *mut c_void, lpProcName: *const u8) -> *mut c_void;
+}
+
+fn main() {
+ let nvcuda = unsafe { LoadLibraryA(b"C:\\Windows\\System32\\nvcuda.dll\0".as_ptr()) };
+ let cuInit = unsafe { GetProcAddress(nvcuda, b"cuInit\0".as_ptr()) };
+ let cuInit = unsafe { mem::transmute::<_, unsafe extern "system" fn(u32) -> u32>(cuInit) };
+ unsafe { cuInit(0) };
+}
|