fixed bugs, memory leaks, etc
This commit is contained in:
1 parent
aa4f6b6ddc
commit
c3f8f23c1d
124 files changed
+1060
-420
No files matched your search
@@ -123,6 +123,9 @@ impl Jni {
|
||||
pub unsafe fn register_natives(&self, c: JClass, methods: &[NativeMethod]) -> JInt {
|
||||
f!(self, 215, unsafe extern "system" fn(EnvPtr, JClass, *const NativeMethod, JInt) -> JInt)(self.env, c, methods.as_ptr(), methods.len() as JInt)
|
||||
}
|
||||
pub unsafe fn unregister_natives(&self, c: JClass) -> JInt {
|
||||
f!(self, 216, unsafe extern "system" fn(EnvPtr, JClass) -> JInt)(self.env, c)
|
||||
}
|
||||
pub unsafe fn exception_check(&self) -> bool {
|
||||
f!(self, 228, unsafe extern "system" fn(EnvPtr) -> JBool)(self.env) != 0
|
||||
}
|
||||
@@ -168,6 +171,12 @@ pub unsafe fn attach_current_thread(vm: VmPtr) -> Result<EnvPtr, String> {
|
||||
Ok(env)
|
||||
}
|
||||
|
||||
/// Detaches the current thread (it must not hold Java frames); a thread attached from native code has to detach before it ends.
|
||||
pub unsafe fn detach_current_thread(vm: VmPtr) {
|
||||
let detach = std::mem::transmute::<*const c_void, unsafe extern "system" fn(VmPtr) -> JInt>(*(*vm).add(5));
|
||||
detach(vm);
|
||||
}
|
||||
|
||||
pub unsafe fn get_jvmti(vm: VmPtr) -> Result<JvmtiPtr, String> {
|
||||
let get_env = std::mem::transmute::<*const c_void, unsafe extern "system" fn(VmPtr, *mut *mut c_void, JInt) -> JInt>(*(*vm).add(6));
|
||||
let mut out: *mut c_void = std::ptr::null_mut();
|
||||
@@ -253,3 +262,19 @@ pub unsafe fn redefine_class(j: JvmtiPtr, def: &ClassDefinition) -> JInt {
|
||||
let f = std::mem::transmute::<*const c_void, unsafe extern "system" fn(JvmtiPtr, JInt, *const ClassDefinition) -> JInt>(*(*j).add(86));
|
||||
f(j, 1, def)
|
||||
}
|
||||
|
||||
/// Disables the ClassFileLoadHook event and clears the callback table, so the JVM no longer calls into this DLL.
|
||||
pub unsafe fn disable_class_file_load_hook(j: JvmtiPtr) -> Result<(), String> {
|
||||
let set_mode = std::mem::transmute::<*const c_void, unsafe extern "C" fn(JvmtiPtr, JInt, JInt, JObject, ...) -> JInt>(*(*j).add(1));
|
||||
let rc = set_mode(j, 0, EVENT_CLASS_FILE_LOAD_HOOK, std::ptr::null_mut());
|
||||
if rc != 0 {
|
||||
return Err(format!("SetEventNotificationMode(disable) failed ({rc})"));
|
||||
}
|
||||
let callbacks = [0usize; 40];
|
||||
let set_callbacks = std::mem::transmute::<*const c_void, unsafe extern "system" fn(JvmtiPtr, *const usize, JInt) -> JInt>(*(*j).add(121));
|
||||
let rc = set_callbacks(j, callbacks.as_ptr(), std::mem::size_of_val(&callbacks) as JInt);
|
||||
if rc != 0 {
|
||||
return Err(format!("SetEventCallbacks(clear) failed ({rc})"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user