Skip to content

Commit 6885574

Browse files
yujincheng08ImSpiDy
authored andcommitted
Don't use dirty backup area anymore
It's to solve race, but magisk will always has a race with init, so simply don't use it.
1 parent 841c21d commit 6885574

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

libc/system_properties/system_properties.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ uint32_t SystemProperties::ReadMutablePropertyValue(const prop_info* pi, char* v
195195
serial = new_serial;
196196
len = SERIAL_VALUE_LEN(serial);
197197
if (__predict_false(SERIAL_DIRTY(serial))) {
198-
// See the comment in the prop_area constructor.
199-
prop_area* pa = contexts_->GetPropAreaForName(pi->name);
200-
memcpy(value, pa->dirty_backup_area(), len + 1);
198+
__futex_wait(const_cast<atomic_uint_least32_t*>(&pi->serial), serial, nullptr);
199+
new_serial = load_const_atomic(&pi->serial, memory_order_relaxed);
200+
continue;
201201
} else {
202202
memcpy(value, pi->value, len + 1);
203203
}
@@ -300,17 +300,6 @@ int SystemProperties::Update(prop_info* pi, const char* value, unsigned int len)
300300
auto* override_pi = const_cast<prop_info*>(have_override ? override_pa->find(pi->name) : nullptr);
301301

302302
uint32_t serial = atomic_load_explicit(&pi->serial, memory_order_relaxed);
303-
unsigned int old_len = SERIAL_VALUE_LEN(serial);
304-
305-
// The contract with readers is that whenever the dirty bit is set, an undamaged copy
306-
// of the pre-dirty value is available in the dirty backup area. The fence ensures
307-
// that we publish our dirty area update before allowing readers to see a
308-
// dirty serial.
309-
memcpy(pa->dirty_backup_area(), pi->value, old_len + 1);
310-
if (have_override) {
311-
memcpy(override_pa->dirty_backup_area(), override_pi->value, old_len + 1);
312-
}
313-
atomic_thread_fence(memory_order_release);
314303
serial |= 1;
315304
atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
316305
strncpy(pi->value, value, PROP_VALUE_MAX);

0 commit comments

Comments
 (0)