Retrieves a JNIEnv in the case that a JVM is already created even from another thread.
()
| 1553 | |
| 1554 | // Retrieves a JNIEnv in the case that a JVM is already created even from another thread. |
| 1555 | fn get_created_vm() -> Option<*mut JNIEnv> { |
| 1556 | unsafe { |
| 1557 | // Get the number of the already created VMs. This is most probably 1, but we retrieve the number just in case... |
| 1558 | let mut created_vms_size: jsize = 0; |
| 1559 | tweaks::get_created_java_vms( |
| 1560 | &mut Vec::with_capacity(created_vms_size as usize), |
| 1561 | 0, |
| 1562 | &mut created_vms_size, |
| 1563 | ); |
| 1564 | |
| 1565 | if created_vms_size == 0 { |
| 1566 | None |
| 1567 | } else { |
| 1568 | debug(&format!( |
| 1569 | "Retrieving the first of {} created JVMs", |
| 1570 | created_vms_size |
| 1571 | )); |
| 1572 | // Get the created VM (use 2 just in case... :) ) |
| 1573 | let mut buffer: Vec<*mut JavaVM> = Vec::with_capacity(2); |
| 1574 | for _ in 0..created_vms_size { |
| 1575 | buffer.push(ptr::null_mut()); |
| 1576 | } |
| 1577 | |
| 1578 | let retjint = tweaks::get_created_java_vms( |
| 1579 | &mut buffer, |
| 1580 | created_vms_size, |
| 1581 | &mut created_vms_size, |
| 1582 | ); |
| 1583 | if retjint == JNI_OK { |
| 1584 | let act = (**buffer[0]).v1_4.AttachCurrentThread; |
| 1585 | let mut jni_environment: *mut JNIEnv = ptr::null_mut(); |
| 1586 | (act)( |
| 1587 | buffer[0], |
| 1588 | (&mut jni_environment as *mut *mut JNIEnv) as *mut *mut c_void, |
| 1589 | ptr::null_mut(), |
| 1590 | ); |
| 1591 | Some(jni_environment) |
| 1592 | } else { |
| 1593 | error(&format!( |
| 1594 | "Error while retrieving the created JVMs: {}", |
| 1595 | retjint |
| 1596 | )); |
| 1597 | None |
| 1598 | } |
| 1599 | } |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | fn detach_current_thread(&self) { |
| 1604 | unsafe { |
nothing calls this directly
no test coverage detected