From: Heather McIntyre Date: Tue, 16 Jul 2024 16:37:32 +0000 (-0400) Subject: libdw: Make libdw_findcu thread-safe X-Git-Tag: elfutils-0.192~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a0a2996d15529673bf43269fe7fcafa2e4a0187b;p=thirdparty%2Felfutils.git libdw: Make libdw_findcu thread-safe * libdw/libdw_findcu.c (__libdw_findcu): Add locking. Signed-off-by: Heather S. McIntyre Signed-off-by: Aaron Merey Signed-off-by: Mark Wielaard --- diff --git a/libdw/libdw_findcu.c b/libdw/libdw_findcu.c index c74e895e..bbbbee5d 100644 --- a/libdw/libdw_findcu.c +++ b/libdw/libdw_findcu.c @@ -245,27 +245,39 @@ __libdw_findcu (Dwarf *dbg, Dwarf_Off start, bool v4_debug_types) /* Maybe we already know that CU. */ struct Dwarf_CU fake = { .start = start, .end = 0 }; struct Dwarf_CU **found = eu_tfind (&fake, tree, findcu_cb); + struct Dwarf_CU *result = NULL; if (found != NULL) return *found; + rwlock_wrlock (dbg->dwarf_lock); + if (start < *next_offset) + __libdw_seterrno (DWARF_E_INVALID_DWARF); + else { - __libdw_seterrno (DWARF_E_INVALID_DWARF); - return NULL; - } + /* No. Then read more CUs. */ + while (1) + { + struct Dwarf_CU *newp + = __libdw_intern_next_unit (dbg, v4_debug_types); - /* No. Then read more CUs. */ - while (1) - { - struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, v4_debug_types); - if (newp == NULL) - return NULL; + if (newp == NULL) + { + result = NULL; + break; + } - /* Is this the one we are looking for? */ - if (start < *next_offset || start == newp->start) - return newp; + /* Is this the one we are looking for? */ + if (start < *next_offset || start == newp->start) + { + result = newp; + break; + } + } } - /* NOTREACHED */ + + rwlock_unlock (dbg->dwarf_lock); + return result; } struct Dwarf_CU *