#endif
#include <assert.h>
-#include <search.h>
+#include <eu-search.h>
#include "libdwP.h"
+/* __libdw_findcu modifies "&dbg->next_tu_offset : &dbg->next_cu_offset".
+ May read or write, so mutual exclusion is enforced to prevent a race. */
+rwlock_define(static, next_tucu_offset_lock);
+
static int
findcu_cb (const void *arg1, const void *arg2)
{
Dwarf_Sig8_Hash_insert (&dbg->sig8_hash, unit_id8, newp);
/* Add the new entry to the search tree. */
- if (tsearch (newp, tree, findcu_cb) == NULL)
+ if (eu_tsearch (newp, tree, findcu_cb) == NULL)
{
/* Something went wrong. Undo the operation. */
*offsetp = oldoff;
/* Maybe we already know that CU. */
struct Dwarf_CU fake = { .start = start, .end = 0 };
- struct Dwarf_CU **found = tfind (&fake, tree, findcu_cb);
+ struct Dwarf_CU **found = eu_tfind (&fake, tree, findcu_cb);
+ struct Dwarf_CU *result = NULL;
+
if (found != NULL)
return *found;
- if (start < *next_offset)
- {
- __libdw_seterrno (DWARF_E_INVALID_DWARF);
- return NULL;
- }
+ rwlock_wrlock(next_tucu_offset_lock);
- /* No. Then read more CUs. */
- while (1)
+ if (start < *next_offset)
+ __libdw_seterrno (DWARF_E_INVALID_DWARF);
+ else
{
- struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg, v4_debug_types);
- if (newp == NULL)
- return NULL;
+ /* No. Then read more CUs. */
+ while (1)
+ {
+ struct Dwarf_CU *newp = __libdw_intern_next_unit (dbg,
+ v4_debug_types);
+ 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(next_tucu_offset_lock);
+ return result;
}
struct Dwarf_CU *
return NULL;
struct Dwarf_CU fake = { .start = start, .end = 0 };
- struct Dwarf_CU **found = tfind (&fake, tree, findcu_cb);
+ struct Dwarf_CU **found = eu_tfind (&fake, tree, findcu_cb);
if (found != NULL)
return *found;
/* XXX Assumes split DWARF only has CUs in main IDX_debug_info. */
Elf_Data fake_data = { .d_buf = addr, .d_size = 0 };
Dwarf fake = { .sectiondata[IDX_debug_info] = &fake_data };
- Dwarf **found = tfind (&fake, &dbg->split_tree, __libdw_finddbg_cb);
+ Dwarf **found = eu_tfind (&fake, &dbg->split_tree, __libdw_finddbg_cb);
if (found != NULL)
return *found;