aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2023-05-27 14:57:02 +0200
committerOriol Brufau <obrufau@igalia.com>2023-05-30 23:26:03 +0200
commit2a42be3cc83fb45bbbaaa5dbfe60635526ba1675 (patch)
treeddf35d4318e4a6db0d3181d37d7dfff8ab73292a
parent75acb72256df67e380b8c5b6f10936869ef0c100 (diff)
downloadservo-2a42be3cc83fb45bbbaaa5dbfe60635526ba1675.tar.gz
servo-2a42be3cc83fb45bbbaaa5dbfe60635526ba1675.zip
style: Print lock address on assert
Note that the crash reason is sanitized so we're not exposing anything sensitive. I think my patch just changed the signature of the stack, as it didn't change anything related to guards or what not. But without knowing why is failing or a repro it's hard to know what's going on. Printing the address at list would give us some indication of what might be going wrong (perhaps we're using a static lock when we don't expect one or such?). Differential Revision: https://phabricator.services.mozilla.com/D125948
-rw-r--r--components/style/shared_lock.rs35
1 files changed, 21 insertions, 14 deletions
diff --git a/components/style/shared_lock.rs b/components/style/shared_lock.rs
index 5bfa7d19737..d524f0c6cdf 100644
--- a/components/style/shared_lock.rs
+++ b/components/style/shared_lock.rs
@@ -94,6 +94,12 @@ impl SharedRwLock {
SharedRwLock { cell: None }
}
+ #[cfg(feature = "gecko")]
+ #[inline]
+ fn ptr(&self) -> *const SomethingZeroSizedButTyped {
+ self.cell.as_ref().map(|cell| cell.as_ptr() as *const _).unwrap_or(ptr::null())
+ }
+
/// Wrap the given data to make its access protected by this lock.
pub fn wrap<T>(&self, data: T) -> Locked<T> {
Locked {
@@ -144,6 +150,14 @@ impl<'a> Drop for SharedRwLockReadGuard<'a> {
}
}
+impl<'a> SharedRwLockReadGuard<'a> {
+ #[inline]
+ #[cfg(feature = "gecko")]
+ fn ptr(&self) -> *const SomethingZeroSizedButTyped {
+ self.0.as_ref().map(|r| &**r as *const _).unwrap_or(ptr::null())
+ }
+}
+
/// Proof that a shared lock was obtained for writing (servo).
#[cfg(feature = "servo")]
pub struct SharedRwLockWriteGuard<'a>(&'a SharedRwLock);
@@ -190,25 +204,18 @@ impl<T> Locked<T> {
}
#[cfg(feature = "gecko")]
- fn same_lock_as(&self, derefed_guard: Option<&SomethingZeroSizedButTyped>) -> bool {
- ptr::eq(
- self.shared_lock
- .cell
- .as_ref()
- .map(|cell| cell.as_ptr())
- .unwrap_or(ptr::null_mut()),
- derefed_guard
- .map(|guard| guard as *const _ as *mut _)
- .unwrap_or(ptr::null_mut()),
- )
+ fn same_lock_as(&self, ptr: *const SomethingZeroSizedButTyped) -> bool {
+ ptr::eq(self.shared_lock.ptr(), ptr)
}
/// Access the data for reading.
pub fn read_with<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a T {
#[cfg(feature = "gecko")]
assert!(
- self.is_read_only_lock() || self.same_lock_as(guard.0.as_ref().map(|r| &**r)),
- "Locked::read_with called with a guard from an unrelated SharedRwLock"
+ self.is_read_only_lock() || self.same_lock_as(guard.ptr()),
+ "Locked::read_with called with a guard from an unrelated SharedRwLock: {:?} vs. {:?}",
+ self.shared_lock.ptr(),
+ guard.ptr(),
);
#[cfg(not(feature = "gecko"))]
assert!(self.same_lock_as(&guard.0));
@@ -235,7 +242,7 @@ impl<T> Locked<T> {
pub fn write_with<'a>(&'a self, guard: &'a mut SharedRwLockWriteGuard) -> &'a mut T {
#[cfg(feature = "gecko")]
assert!(
- !self.is_read_only_lock() && self.same_lock_as(Some(&guard.0)),
+ !self.is_read_only_lock() && self.same_lock_as(&*guard.0),
"Locked::write_with called with a guard from a read only or unrelated SharedRwLock"
);
#[cfg(not(feature = "gecko"))]