Fixup futex emulation

std::unordered_multimap::find may return any matching element.. unlike equal_range. (code relied on matching the first)
There was also UB there of reference to an element after it has deleted.
This commit is contained in:
Elad 2025-12-16 00:16:02 +02:00
parent 86fd2a6fe2
commit 5d1be471b5
2 changed files with 7 additions and 10 deletions

View File

@ -81,9 +81,9 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
{
struct waiter
{
uint val;
uint mask;
std::condition_variable cv;
uint val;
uint mask;
std::condition_variable cv;
};
std::mutex mutex;
@ -111,7 +111,7 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
waiter rec;
rec.val = val;
rec.mask = mask;
const auto& ref = *map.emplace(uaddr, &rec);
const auto itr = map.emplace(uaddr, &rec);
int res = 0;
@ -134,7 +134,7 @@ inline int futex(volatile void* uaddr, int futex_op, uint val, const timespec* t
// TODO: absolute timeout
}
map.erase(std::find(map.find(uaddr), map.end(), ref));
map.erase(itr);
return res;
}

View File

@ -2228,11 +2228,8 @@ void lv2_obj::notify_all() noexcept
break;
}
if (cpu != &g_to_notify)
{
// Note: by the time of notification the thread could have been deallocated which is why the direct function is used
atomic_wait_engine::notify_all(cpu);
}
// Note: by the time of notification the thread could have been deallocated which is why the direct function is used
atomic_wait_engine::notify_all(cpu);
}
g_to_notify[0] = nullptr;