_core_rustc_static/
resources_table.rspub use heapdump_vmo::resources_table_v1::ResourceKey;
use heapdump_vmo::resources_table_v1::ResourcesTableWriter;
use std::sync::atomic::fence;
use std::sync::atomic::Ordering::Release;
use zx::{self as zx, AsHandleRef, HandleBased};
const VMO_SIZE: usize = 1 << 31;
const VMO_NAME: zx::Name = zx::Name::new_lossy("heapdump-resources");
pub struct ResourcesTable {
vmo: zx::Vmo,
writer: ResourcesTableWriter,
}
impl Default for ResourcesTable {
fn default() -> ResourcesTable {
let vmo = zx::Vmo::create(VMO_SIZE as u64).expect("failed to create resources VMO");
vmo.set_name(&VMO_NAME).expect("failed to set VMO name");
let writer = ResourcesTableWriter::new(&vmo).expect("failed to create writer");
ResourcesTable { vmo, writer }
}
}
impl ResourcesTable {
pub fn share_vmo(&self) -> zx::Vmo {
self.vmo.duplicate_handle(zx::Rights::SAME_RIGHTS).expect("failed to share resources VMO")
}
pub fn intern_stack_trace(&mut self, compressed_stack_trace: &[u8]) -> ResourceKey {
let (resource_key, inserted) = self
.writer
.intern_compressed_stack_trace(compressed_stack_trace)
.expect("failed to insert stack trace");
if inserted {
fence(Release);
}
resource_key
}
pub fn insert_thread_info(&mut self, koid: zx::Koid, name: &zx::Name) -> ResourceKey {
self.writer.insert_thread_info(koid.raw_koid(), name).expect("failed to insert thread info")
}
}