waterbox linux - rework to avoid possible memory leak
Bizhawk never would hit this because it only ever runs waterboxes in one host thread, but an application that spun up many threads and ran waterboxes in each would leak 32 bytes of heap for each native thread destroyed, which is super duper not really meaningful at all
This commit is contained in:
parent
7f28bc2caf
commit
a67fa70632
Binary file not shown.
|
@ -68,6 +68,11 @@ pub struct Context {
|
|||
pub extcall_slots: [Option<ExternalCallback>; 64],
|
||||
}
|
||||
|
||||
|
||||
#[cfg(unix)]
|
||||
thread_local!(static TIB: Box<[usize; 4]> = Box::new([0usize; 4]));
|
||||
|
||||
|
||||
/// Prepares this host thread to be allowed to call guest code. Noop if already called.
|
||||
/// Only needs to happen once per host thread
|
||||
pub fn prepare_thread() {
|
||||
|
@ -84,8 +89,10 @@ pub fn prepare_thread() {
|
|||
let mut gs = 0usize;
|
||||
assert_eq!(syscall(SYS_arch_prctl, 0x1004 /*ARCH_GET_GS*/, &gs), 0);
|
||||
if gs == 0 {
|
||||
gs = Box::into_raw(Box::new([0usize; 4])) as usize;
|
||||
assert_eq!(syscall(SYS_arch_prctl, 0x1001 /*ARCH_SET_GS*/, gs), 0);
|
||||
TIB.with(|b| {
|
||||
gs = b.as_ref()[0] as *const usize as usize;
|
||||
assert_eq!(syscall(SYS_arch_prctl, 0x1001 /*ARCH_SET_GS*/, gs), 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue