Skip to content

Commit 4be0888

Browse files
committed
PR Feedback
1 parent f754b22 commit 4be0888

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

src/symbolize/gimli.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,8 @@ impl Mapping {
330330

331331
type Cache = Vec<(PathBuf, Mapping)>;
332332

333-
fn with_cache(f: impl FnOnce(&mut Cache)) {
333+
/// Warning: this function is not threadsafe and needs to be externally synchronized
334+
unsafe fn with_cache(f: impl FnOnce(&mut Cache)) {
334335
// A very small, very simple LRU cache for debug info mappings.
335336
//
336337
// The hit rate should be very high, since the typical stack doesn't cross
@@ -343,10 +344,10 @@ fn with_cache(f: impl FnOnce(&mut Cache)) {
343344
// never happen, and symbolicating backtraces would be ssssllllooooowwww.
344345
static mut MAPPINGS_CACHE: Option<Cache> = None;
345346

346-
unsafe { f(MAPPINGS_CACHE.get_or_insert_with(|| Vec::with_capacity(MAPPINGS_CACHE_SIZE))) }
347+
f(MAPPINGS_CACHE.get_or_insert_with(|| Vec::with_capacity(MAPPINGS_CACHE_SIZE)))
347348
}
348349

349-
pub fn clear_symbol_cache() {
350+
pub unsafe fn clear_symbol_cache() {
350351
with_cache(|cache| cache.clear());
351352
}
352353

src/symbolize/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -439,16 +439,20 @@ mod dladdr;
439439
/// Each resolve() implementation allocates and caches several megabytes worth of symbols,
440440
/// clear_symbol_cache tries to reclaim that cached memory.
441441
/// Note: for now, only the Gimli implementation is able to clear its cache.
442-
pub fn clear_symbol_cache() {
443-
clear_imp()
442+
#[cfg(feature = "std")]
443+
pub fn clear_symbol_cache() {
444+
let _guard = crate::lock::lock();
445+
unsafe {
446+
clear_imp()
447+
}
444448
}
445449

446450
cfg_if::cfg_if! {
447451
if #[cfg(all(windows, target_env = "msvc", feature = "dbghelp"))] {
448452
mod dbghelp;
449453
use self::dbghelp::resolve as resolve_imp;
450454
use self::dbghelp::Symbol as SymbolImp;
451-
fn noop_clear_symbol_cache() {}
455+
unsafe fn noop_clear_symbol_cache() {}
452456
use noop_clear_symbol_cache as clear_imp;
453457
} else if #[cfg(all(
454458
feature = "std",
@@ -473,7 +477,7 @@ cfg_if::cfg_if! {
473477
use self::coresymbolication::resolve as resolve_imp;
474478
use self::coresymbolication::Symbol as SymbolImp;
475479

476-
fn noop_clear_symbol_cache() {}
480+
unsafe fn noop_clear_symbol_cache() {}
477481
use noop_clear_symbol_cache as clear_imp;
478482
} else if #[cfg(all(feature = "libbacktrace",
479483
any(unix, all(windows, not(target_vendor = "uwp"), target_env = "gnu")),
@@ -483,7 +487,7 @@ cfg_if::cfg_if! {
483487
use self::libbacktrace::resolve as resolve_imp;
484488
use self::libbacktrace::Symbol as SymbolImp;
485489

486-
fn noop_clear_symbol_cache() {}
490+
unsafe fn noop_clear_symbol_cache() {}
487491
use noop_clear_symbol_cache as clear_imp;
488492
} else if #[cfg(all(unix,
489493
not(target_os = "emscripten"),
@@ -492,14 +496,14 @@ cfg_if::cfg_if! {
492496
use self::dladdr_resolve::resolve as resolve_imp;
493497
use self::dladdr_resolve::Symbol as SymbolImp;
494498

495-
fn noop_clear_symbol_cache() {}
499+
unsafe fn noop_clear_symbol_cache() {}
496500
use noop_clear_symbol_cache as clear_imp;
497501
} else {
498502
mod noop;
499503
use self::noop::resolve as resolve_imp;
500504
use self::noop::Symbol as SymbolImp;
501505

502-
fn noop_clear_symbol_cache() {}
506+
unsafe fn noop_clear_symbol_cache() {}
503507
use noop_clear_symbol_cache as clear_imp;
504508
}
505509
}

0 commit comments

Comments
 (0)