Merge "Update docs/status.md function counts for recent releases."
diff --git a/benchmarks/property_benchmark.cpp b/benchmarks/property_benchmark.cpp
index 77814bf..ba54ed1 100644
--- a/benchmarks/property_benchmark.cpp
+++ b/benchmarks/property_benchmark.cpp
@@ -184,7 +184,7 @@
size_t i = 0;
while (state.KeepRunning()) {
- pa.system_properties().Serial(pinfo[i]);
+ __system_property_serial(pinfo[i]);
i = (i + 1) % nprops;
}
diff --git a/libc/Android.bp b/libc/Android.bp
index c5ea4c5..cdbdf63 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -42,7 +42,6 @@
"-Wno-deprecated-declarations",
"-Wno-gcc-compat",
"-Wframe-larger-than=2048",
- "-Wimplicit-fallthrough",
// Try to catch typical 32-bit assumptions that break with 64-bit pointers.
"-Werror=pointer-to-int-cast",
@@ -1711,6 +1710,8 @@
strip: {
keep_symbols_and_debug_frame: true,
},
+
+ whole_static_libs: [ "libgcc_stripped" ],
},
arm64: {
version_script: ":libc.arm64.map",
diff --git a/libc/arch-x86_64/string/cache.h b/libc/arch-x86_64/string/cache.h
index 38acc6e..4131509 100644
--- a/libc/arch-x86_64/string/cache.h
+++ b/libc/arch-x86_64/string/cache.h
@@ -28,9 +28,9 @@
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-/* Values are optimized for Silvermont */
-#define SHARED_CACHE_SIZE (1024*1024) /* Silvermont L2 Cache */
-#define DATA_CACHE_SIZE (24*1024) /* Silvermont L1 Data Cache */
+/* Values are optimized for Core Architecture */
+#define SHARED_CACHE_SIZE (4096*1024) /* Core Architecture L2 Cache */
+#define DATA_CACHE_SIZE (24*1024) /* Core Architecture L1 Data Cache */
-#define SHARED_CACHE_SIZE_HALF (SHARED_CACHE_SIZE / 2)
-#define DATA_CACHE_SIZE_HALF (DATA_CACHE_SIZE / 2)
+#define SHARED_CACHE_SIZE_HALF (SHARED_CACHE_SIZE / 2)
+#define DATA_CACHE_SIZE_HALF (DATA_CACHE_SIZE / 2)
diff --git a/libc/bionic/jemalloc.h b/libc/bionic/jemalloc.h
index ef77c9c..4ce51c0 100644
--- a/libc/bionic/jemalloc.h
+++ b/libc/bionic/jemalloc.h
@@ -29,7 +29,7 @@
__BEGIN_DECLS
void* je_aligned_alloc_wrapper(size_t, size_t);
-int je_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
+int je_malloc_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
int je_mallctl(const char *name, void *oldp, size_t *oldlenp, void *newp, size_t newlen) __attribute__((nothrow));
struct mallinfo je_mallinfo();
void je_malloc_disable();
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index 96e6140..a0da3db 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -215,9 +215,9 @@
void (*callback)(uintptr_t base, size_t size, void* arg), void* arg) {
auto dispatch_table = GetDispatchTable();
if (__predict_false(dispatch_table != nullptr)) {
- return dispatch_table->iterate(base, size, callback, arg);
+ return dispatch_table->malloc_iterate(base, size, callback, arg);
}
- return Malloc(iterate)(base, size, callback, arg);
+ return Malloc(malloc_iterate)(base, size, callback, arg);
}
// Disable calls to malloc so malloc_iterate gets a consistent view of
@@ -247,9 +247,10 @@
#if __has_feature(hwaddress_sanitizer)
// FIXME: implement these in HWASan allocator.
-extern "C" int __sanitizer_iterate(uintptr_t base __unused, size_t size __unused,
- void (*callback)(uintptr_t base, size_t size, void* arg) __unused,
- void* arg __unused) {
+extern "C" int __sanitizer_malloc_iterate(uintptr_t base __unused, size_t size __unused,
+ void (*callback)(uintptr_t base, size_t size, void* arg)
+ __unused,
+ void* arg __unused) {
return 0;
}
diff --git a/libc/bionic/malloc_common.h b/libc/bionic/malloc_common.h
index 2176e63..89dccc3 100644
--- a/libc/bionic/malloc_common.h
+++ b/libc/bionic/malloc_common.h
@@ -42,9 +42,9 @@
__BEGIN_DECLS
// FIXME: implement these in HWASan allocator.
-int __sanitizer_iterate(uintptr_t base, size_t size,
- void (*callback)(uintptr_t base, size_t size, void* arg),
- void* arg);
+int __sanitizer_malloc_iterate(uintptr_t base, size_t size,
+ void (*callback)(uintptr_t base, size_t size, void* arg),
+ void* arg);
void __sanitizer_malloc_disable();
void __sanitizer_malloc_enable();
int __sanitizer_malloc_info(int options, FILE* fp);
diff --git a/libc/bionic/malloc_common_dynamic.cpp b/libc/bionic/malloc_common_dynamic.cpp
index 9ad79a0..0ac3f62 100644
--- a/libc/bionic/malloc_common_dynamic.cpp
+++ b/libc/bionic/malloc_common_dynamic.cpp
@@ -95,7 +95,7 @@
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
Malloc(valloc),
#endif
- Malloc(iterate),
+ Malloc(malloc_iterate),
Malloc(malloc_disable),
Malloc(malloc_enable),
Malloc(mallopt),
@@ -184,7 +184,8 @@
if (!InitMallocFunction<MallocRealloc>(impl_handler, &table->realloc, prefix, "realloc")) {
return false;
}
- if (!InitMallocFunction<MallocIterate>(impl_handler, &table->iterate, prefix, "iterate")) {
+ if (!InitMallocFunction<MallocIterate>(impl_handler, &table->malloc_iterate, prefix,
+ "malloc_iterate")) {
return false;
}
if (!InitMallocFunction<MallocMallocDisable>(impl_handler, &table->malloc_disable, prefix,
diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp
index 62249fb..5860222 100644
--- a/libc/bionic/malloc_heapprofd.cpp
+++ b/libc/bionic/malloc_heapprofd.cpp
@@ -104,7 +104,7 @@
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
Malloc(valloc),
#endif
- Malloc(iterate),
+ Malloc(malloc_iterate),
Malloc(malloc_disable),
Malloc(malloc_enable),
Malloc(mallopt),
diff --git a/libc/bionic/malloc_limit.cpp b/libc/bionic/malloc_limit.cpp
index 6a67cae..d8c0ebe 100644
--- a/libc/bionic/malloc_limit.cpp
+++ b/libc/bionic/malloc_limit.cpp
@@ -350,9 +350,9 @@
static int LimitIterate(uintptr_t base, size_t size, void (*callback)(uintptr_t, size_t, void*), void* arg) {
auto dispatch_table = GetDefaultDispatchTable();
if (__predict_false(dispatch_table != nullptr)) {
- return dispatch_table->iterate(base, size, callback, arg);
+ return dispatch_table->malloc_iterate(base, size, callback, arg);
}
- return Malloc(iterate)(base, size, callback, arg);
+ return Malloc(malloc_iterate)(base, size, callback, arg);
}
static void LimitMallocDisable() {
diff --git a/libc/bionic/scudo.h b/libc/bionic/scudo.h
index d9933c4..a80d754 100644
--- a/libc/bionic/scudo.h
+++ b/libc/bionic/scudo.h
@@ -52,7 +52,7 @@
void* scudo_valloc(size_t);
#endif
-int scudo_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
+int scudo_malloc_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
void scudo_malloc_disable();
void scudo_malloc_enable();
diff --git a/libc/bionic/scudo_wrapper.cpp b/libc/bionic/scudo_wrapper.cpp
index e17f20b..debd8d9 100644
--- a/libc/bionic/scudo_wrapper.cpp
+++ b/libc/bionic/scudo_wrapper.cpp
@@ -48,7 +48,7 @@
return -1;
}
-int scudo_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*) {
+int scudo_malloc_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*) {
return 0;
}
diff --git a/libc/bionic/system_property_api.cpp b/libc/bionic/system_property_api.cpp
index 051bc4c..a641f12 100644
--- a/libc/bionic/system_property_api.cpp
+++ b/libc/bionic/system_property_api.cpp
@@ -100,7 +100,13 @@
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
uint32_t __system_property_serial(const prop_info* pi) {
- return system_properties.Serial(pi);
+ // N.B. a previous version of this function was much heavier-weight
+ // and enforced acquire semantics, so give our load here acquire
+ // semantics just in case somebody depends on
+ // __system_property_serial enforcing memory order, e.g., in case
+ // someone spins on the result of this function changing before
+ // loading some value.
+ return atomic_load_explicit(&pi->serial, memory_order_acquire);
}
__BIONIC_WEAK_FOR_NATIVE_BRIDGE
diff --git a/libc/include/bits/sys_statvfs_inlines.h b/libc/include/bits/sys_statvfs_inlines.h
index fd4578c..991fac7 100644
--- a/libc/include/bits/sys_statvfs_inlines.h
+++ b/libc/include/bits/sys_statvfs_inlines.h
@@ -38,20 +38,20 @@
#if defined(__BIONIC_NEED_STATVFS_INLINES)
-static __inline void __bionic_statfs_to_statvfs(const struct statfs* __in,
- struct statvfs* __out) {
- __out->f_bsize = __in->f_bsize;
- __out->f_frsize = __in->f_frsize;
- __out->f_blocks = __in->f_blocks;
- __out->f_bfree = __in->f_bfree;
- __out->f_bavail = __in->f_bavail;
- __out->f_files = __in->f_files;
- __out->f_ffree = __in->f_ffree;
- __out->f_favail = __in->f_ffree;
- __out->f_fsid = __in->f_fsid.__val[0] |
- __BIONIC_CAST(static_cast, uint64_t, __in->f_fsid.__val[1]) << 32;
- __out->f_flag = __in->f_flags;
- __out->f_namemax = __in->f_namelen;
+static __inline void __bionic_statfs_to_statvfs(const struct statfs* __src,
+ struct statvfs* __dst) {
+ __dst->f_bsize = __src->f_bsize;
+ __dst->f_frsize = __src->f_frsize;
+ __dst->f_blocks = __src->f_blocks;
+ __dst->f_bfree = __src->f_bfree;
+ __dst->f_bavail = __src->f_bavail;
+ __dst->f_files = __src->f_files;
+ __dst->f_ffree = __src->f_ffree;
+ __dst->f_favail = __src->f_ffree;
+ __dst->f_fsid = __src->f_fsid.__val[0] |
+ __BIONIC_CAST(static_cast, uint64_t, __src->f_fsid.__val[1]) << 32;
+ __dst->f_flag = __src->f_flags;
+ __dst->f_namemax = __src->f_namelen;
}
__BIONIC_SYS_STATVFS_INLINE int statvfs(const char* __path,
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index a4ab600..8e843af 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -1468,10 +1468,10 @@
__system_properties_init; # apex
# Used by libmemunreachable
- malloc_backtrace; # apex vndk
- malloc_disable; # apex vndk
- malloc_enable; # apex vndk
- malloc_iterate; # apex vndk
+ malloc_backtrace; # apex llndk
+ malloc_disable; # apex llndk
+ malloc_enable; # apex llndk
+ malloc_iterate; # apex llndk
# Used by libandroid_net
android_getaddrinfofornet; # apex
diff --git a/libc/malloc_debug/exported32.map b/libc/malloc_debug/exported32.map
index 8ed37fa..f75d173 100644
--- a/libc/malloc_debug/exported32.map
+++ b/libc/malloc_debug/exported32.map
@@ -8,13 +8,13 @@
debug_free_malloc_leak_info;
debug_get_malloc_leak_info;
debug_initialize;
- debug_iterate;
debug_mallinfo;
debug_malloc;
debug_malloc_backtrace;
debug_malloc_disable;
debug_malloc_enable;
debug_malloc_info;
+ debug_malloc_iterate;
debug_malloc_usable_size;
debug_mallopt;
debug_memalign;
diff --git a/libc/malloc_debug/exported64.map b/libc/malloc_debug/exported64.map
index cdff88b..6dea58c 100644
--- a/libc/malloc_debug/exported64.map
+++ b/libc/malloc_debug/exported64.map
@@ -8,13 +8,13 @@
debug_free_malloc_leak_info;
debug_get_malloc_leak_info;
debug_initialize;
- debug_iterate;
debug_mallinfo;
debug_malloc;
debug_malloc_backtrace;
debug_malloc_disable;
debug_malloc_enable;
debug_malloc_info;
+ debug_malloc_iterate;
debug_malloc_usable_size;
debug_mallopt;
debug_memalign;
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 3c0e630..c0765a9 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -91,8 +91,8 @@
int debug_mallopt(int param, int value);
int debug_malloc_info(int options, FILE* fp);
int debug_posix_memalign(void** memptr, size_t alignment, size_t size);
-int debug_iterate(uintptr_t base, size_t size,
- void (*callback)(uintptr_t base, size_t size, void* arg), void* arg);
+int debug_malloc_iterate(uintptr_t base, size_t size,
+ void (*callback)(uintptr_t base, size_t size, void* arg), void* arg);
void debug_malloc_disable();
void debug_malloc_enable();
@@ -841,7 +841,7 @@
return (*memptr != nullptr) ? 0 : ENOMEM;
}
-int debug_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t, size_t, void*),
+int debug_malloc_iterate(uintptr_t base, size_t size, void (*callback)(uintptr_t, size_t, void*),
void* arg) {
ScopedConcurrentLock lock;
if (g_debug->TrackPointers()) {
@@ -854,7 +854,7 @@
// An option that adds a header will add pointer tracking, so no need to
// check if headers are enabled.
- return g_dispatch->iterate(base, size, callback, arg);
+ return g_dispatch->malloc_iterate(base, size, callback, arg);
}
void debug_malloc_disable() {
diff --git a/libc/malloc_hooks/exported32.map b/libc/malloc_hooks/exported32.map
index 293d9ac..2b02806 100644
--- a/libc/malloc_hooks/exported32.map
+++ b/libc/malloc_hooks/exported32.map
@@ -7,13 +7,13 @@
hooks_free_malloc_leak_info;
hooks_get_malloc_leak_info;
hooks_initialize;
- hooks_iterate;
hooks_mallinfo;
hooks_malloc;
hooks_malloc_backtrace;
hooks_malloc_disable;
hooks_malloc_enable;
hooks_malloc_info;
+ hooks_malloc_iterate;
hooks_malloc_usable_size;
hooks_mallopt;
hooks_memalign;
diff --git a/libc/malloc_hooks/exported64.map b/libc/malloc_hooks/exported64.map
index 340106b..59ec1f0 100644
--- a/libc/malloc_hooks/exported64.map
+++ b/libc/malloc_hooks/exported64.map
@@ -7,13 +7,13 @@
hooks_free_malloc_leak_info;
hooks_get_malloc_leak_info;
hooks_initialize;
- hooks_iterate;
hooks_mallinfo;
hooks_malloc;
hooks_malloc_backtrace;
hooks_malloc_disable;
hooks_malloc_enable;
hooks_malloc_info;
+ hooks_malloc_iterate;
hooks_malloc_usable_size;
hooks_mallopt;
hooks_memalign;
diff --git a/libc/malloc_hooks/malloc_hooks.cpp b/libc/malloc_hooks/malloc_hooks.cpp
index b1c1d50..1ba8696 100644
--- a/libc/malloc_hooks/malloc_hooks.cpp
+++ b/libc/malloc_hooks/malloc_hooks.cpp
@@ -67,7 +67,7 @@
struct mallinfo hooks_mallinfo();
int hooks_mallopt(int param, int value);
int hooks_posix_memalign(void** memptr, size_t alignment, size_t size);
-int hooks_iterate(uintptr_t base, size_t size,
+int hooks_malloc_iterate(uintptr_t base, size_t size,
void (*callback)(uintptr_t base, size_t size, void* arg), void* arg);
void hooks_malloc_disable();
void hooks_malloc_enable();
@@ -209,7 +209,7 @@
return g_dispatch->posix_memalign(memptr, alignment, size);
}
-int hooks_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*) {
+int hooks_malloc_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*) {
return 0;
}
diff --git a/libc/private/bionic_malloc_dispatch.h b/libc/private/bionic_malloc_dispatch.h
index aea3a1c..52d8573 100644
--- a/libc/private/bionic_malloc_dispatch.h
+++ b/libc/private/bionic_malloc_dispatch.h
@@ -70,7 +70,7 @@
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
MallocValloc valloc;
#endif
- MallocIterate iterate;
+ MallocIterate malloc_iterate;
MallocMallocDisable malloc_disable;
MallocMallocEnable malloc_enable;
MallocMallopt mallopt;
diff --git a/libc/system_properties/include/system_properties/prop_area.h b/libc/system_properties/include/system_properties/prop_area.h
index a69f90e..53b2745 100644
--- a/libc/system_properties/include/system_properties/prop_area.h
+++ b/libc/system_properties/include/system_properties/prop_area.h
@@ -106,6 +106,20 @@
memset(reserved_, 0, sizeof(reserved_));
// Allocate enough space for the root node.
bytes_used_ = sizeof(prop_bt);
+ // To make property reads wait-free, we reserve a
+ // PROP_VALUE_MAX-sized block of memory, the "dirty backup area",
+ // just after the root node. When we're about to modify a
+ // property, we copy the old value into the dirty backup area and
+ // copy the new value into the prop_info structure. Before
+ // starting the latter copy, we mark the property's serial as
+ // being dirty. If a reader comes along while we're doing the
+ // property update and sees a dirty serial, the reader copies from
+ // the dirty backup area instead of the property value
+ // proper. After the copy, the reader checks whether the property
+ // serial is the same: if it is, the dirty backup area hasn't been
+ // reused for something else and we can complete the
+ // read immediately.
+ bytes_used_ += __BIONIC_ALIGN(PROP_VALUE_MAX, sizeof(uint_least32_t));
}
const prop_info* find(const char* name);
@@ -122,6 +136,9 @@
uint32_t version() const {
return version_;
}
+ char* dirty_backup_area() {
+ return data_ + sizeof (prop_bt);
+ }
private:
static prop_area* map_fd_ro(const int fd);
diff --git a/libc/system_properties/include/system_properties/system_properties.h b/libc/system_properties/include/system_properties/system_properties.h
index cad29cc..0666e28 100644
--- a/libc/system_properties/include/system_properties/system_properties.h
+++ b/libc/system_properties/include/system_properties/system_properties.h
@@ -66,7 +66,6 @@
int Get(const char* name, char* value);
int Update(prop_info* pi, const char* value, unsigned int len);
int Add(const char* name, unsigned int namelen, const char* value, unsigned int valuelen);
- uint32_t Serial(const prop_info* pi);
uint32_t WaitAny(uint32_t old_serial);
bool Wait(const prop_info* pi, uint32_t old_serial, uint32_t* new_serial_ptr,
const timespec* relative_timeout);
@@ -74,6 +73,8 @@
int Foreach(void (*propfn)(const prop_info* pi, void* cookie), void* cookie);
private:
+ uint32_t ReadMutablePropertyValue(const prop_info* pi, char* value);
+
// We don't want to use new or malloc in properties (b/31659220), and we don't want to waste a
// full page by using mmap(), so we set aside enough space to create any context of the three
// contexts.
diff --git a/libc/system_properties/system_properties.cpp b/libc/system_properties/system_properties.cpp
index d7c441b..8404778 100644
--- a/libc/system_properties/system_properties.cpp
+++ b/libc/system_properties/system_properties.cpp
@@ -140,42 +140,58 @@
return strncmp(name, "ro.", 3) == 0;
}
-int SystemProperties::Read(const prop_info* pi, char* name, char* value) {
- while (true) {
- uint32_t serial = Serial(pi); // acquire semantics
- size_t len = SERIAL_VALUE_LEN(serial);
- memcpy(value, pi->value, len + 1);
- // TODO: Fix the synchronization scheme here.
- // There is no fully supported way to implement this kind
- // of synchronization in C++11, since the memcpy races with
- // updates to pi, and the data being accessed is not atomic.
- // The following fence is unintuitive, but would be the
- // correct one if memcpy used memory_order_relaxed atomic accesses.
- // In practice it seems unlikely that the generated code would
- // would be any different, so this should be OK.
+uint32_t SystemProperties::ReadMutablePropertyValue(const prop_info* pi, char* value) {
+ // We assume the memcpy below gets serialized by the acquire fence.
+ uint32_t new_serial = load_const_atomic(&pi->serial, memory_order_acquire);
+ uint32_t serial;
+ unsigned int len;
+ for (;;) {
+ serial = new_serial;
+ len = SERIAL_VALUE_LEN(serial);
+ if (__predict_false(SERIAL_DIRTY(serial))) {
+ // See the comment in the prop_area constructor.
+ prop_area* pa = contexts_->GetPropAreaForName(pi->name);
+ memcpy(value, pa->dirty_backup_area(), len + 1);
+ } else {
+ memcpy(value, pi->value, len + 1);
+ }
atomic_thread_fence(memory_order_acquire);
- if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) {
- if (name != nullptr) {
- size_t namelen = strlcpy(name, pi->name, PROP_NAME_MAX);
- if (namelen >= PROP_NAME_MAX) {
- async_safe_format_log(ANDROID_LOG_ERROR, "libc",
- "The property name length for \"%s\" is >= %d;"
- " please use __system_property_read_callback"
- " to read this property. (the name is truncated to \"%s\")",
- pi->name, PROP_NAME_MAX - 1, name);
- }
- }
- if (is_read_only(pi->name) && pi->is_long()) {
- async_safe_format_log(
- ANDROID_LOG_ERROR, "libc",
- "The property \"%s\" has a value with length %zu that is too large for"
- " __system_property_get()/__system_property_read(); use"
- " __system_property_read_callback() instead.",
- pi->name, strlen(pi->long_value()));
- }
- return len;
+ new_serial = load_const_atomic(&pi->serial, memory_order_relaxed);
+ if (__predict_true(serial == new_serial)) {
+ break;
+ }
+ // We need another fence here because we want to ensure that the memcpy in the
+ // next iteration of the loop occurs after the load of new_serial above. We could
+ // get this guarantee by making the load_const_atomic of new_serial
+ // memory_order_acquire instead of memory_order_relaxed, but then we'd pay the
+ // penalty of the memory_order_acquire even in the overwhelmingly common case
+ // that the serial number didn't change.
+ atomic_thread_fence(memory_order_acquire);
+ }
+ return serial;
+}
+
+int SystemProperties::Read(const prop_info* pi, char* name, char* value) {
+ uint32_t serial = ReadMutablePropertyValue(pi, value);
+ if (name != nullptr) {
+ size_t namelen = strlcpy(name, pi->name, PROP_NAME_MAX);
+ if (namelen >= PROP_NAME_MAX) {
+ async_safe_format_log(ANDROID_LOG_ERROR, "libc",
+ "The property name length for \"%s\" is >= %d;"
+ " please use __system_property_read_callback"
+ " to read this property. (the name is truncated to \"%s\")",
+ pi->name, PROP_NAME_MAX - 1, name);
}
}
+ if (is_read_only(pi->name) && pi->is_long()) {
+ async_safe_format_log(
+ ANDROID_LOG_ERROR, "libc",
+ "The property \"%s\" has a value with length %zu that is too large for"
+ " __system_property_get()/__system_property_read(); use"
+ " __system_property_read_callback() instead.",
+ pi->name, strlen(pi->long_value()));
+ }
+ return SERIAL_VALUE_LEN(serial);
}
void SystemProperties::ReadCallback(const prop_info* pi,
@@ -183,9 +199,9 @@
const char* value, uint32_t serial),
void* cookie) {
// Read only properties don't need to copy the value to a temporary buffer, since it can never
- // change.
+ // change. We use relaxed memory order on the serial load for the same reason.
if (is_read_only(pi->name)) {
- uint32_t serial = Serial(pi);
+ uint32_t serial = load_const_atomic(&pi->serial, memory_order_relaxed);
if (pi->is_long()) {
callback(cookie, pi->name, pi->long_value(), serial);
} else {
@@ -194,21 +210,9 @@
return;
}
- while (true) {
- uint32_t serial = Serial(pi); // acquire semantics
- size_t len = SERIAL_VALUE_LEN(serial);
- char value_buf[len + 1];
-
- memcpy(value_buf, pi->value, len);
- value_buf[len] = '\0';
-
- // TODO: see todo in Read function
- atomic_thread_fence(memory_order_acquire);
- if (serial == load_const_atomic(&(pi->serial), memory_order_relaxed)) {
- callback(cookie, pi->name, value_buf, serial);
- return;
- }
- }
+ char value_buf[PROP_VALUE_MAX];
+ uint32_t serial = ReadMutablePropertyValue(pi, value_buf);
+ callback(cookie, pi->name, value_buf, serial);
}
int SystemProperties::Get(const char* name, char* value) {
@@ -231,26 +235,37 @@
return -1;
}
- prop_area* pa = contexts_->GetSerialPropArea();
- if (!pa) {
+ prop_area* serial_pa = contexts_->GetSerialPropArea();
+ if (!serial_pa) {
+ return -1;
+ }
+ prop_area* pa = contexts_->GetPropAreaForName(pi->name);
+ if (__predict_false(!pa)) {
+ async_safe_format_log(ANDROID_LOG_ERROR, "libc", "Could not find area for \"%s\"", pi->name);
return -1;
}
uint32_t serial = atomic_load_explicit(&pi->serial, memory_order_relaxed);
+ unsigned int old_len = SERIAL_VALUE_LEN(serial);
+
+ // The contract with readers is that whenever the dirty bit is set, an undamaged copy
+ // of the pre-dirty value is available in the dirty backup area. The fence ensures
+ // that we publish our dirty area update before allowing readers to see a
+ // dirty serial.
+ memcpy(pa->dirty_backup_area(), pi->value, old_len + 1);
+ atomic_thread_fence(memory_order_release);
serial |= 1;
atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
- // The memcpy call here also races. Again pretend it
- // used memory_order_relaxed atomics, and use the analogous
- // counterintuitive fence.
- atomic_thread_fence(memory_order_release);
strlcpy(pi->value, value, len + 1);
-
- atomic_store_explicit(&pi->serial, (len << 24) | ((serial + 1) & 0xffffff), memory_order_release);
- __futex_wake(&pi->serial, INT32_MAX);
-
- atomic_store_explicit(pa->serial(), atomic_load_explicit(pa->serial(), memory_order_relaxed) + 1,
+ // Now the primary value property area is up-to-date. Let readers know that they should
+ // look at the property value instead of the backup area.
+ atomic_thread_fence(memory_order_release);
+ atomic_store_explicit(&pi->serial, (len << 24) | ((serial + 1) & 0xffffff), memory_order_relaxed);
+ __futex_wake(&pi->serial, INT32_MAX); // Fence by side effect
+ atomic_store_explicit(serial_pa->serial(),
+ atomic_load_explicit(serial_pa->serial(), memory_order_relaxed) + 1,
memory_order_release);
- __futex_wake(pa->serial(), INT32_MAX);
+ __futex_wake(serial_pa->serial(), INT32_MAX);
return 0;
}
@@ -294,16 +309,6 @@
return 0;
}
-// Wait for non-locked serial, and retrieve it with acquire semantics.
-uint32_t SystemProperties::Serial(const prop_info* pi) {
- uint32_t serial = load_const_atomic(&pi->serial, memory_order_acquire);
- while (SERIAL_DIRTY(serial)) {
- __futex_wait(const_cast<_Atomic(uint_least32_t)*>(&pi->serial), serial, nullptr);
- serial = load_const_atomic(&pi->serial, memory_order_acquire);
- }
- return serial;
-}
-
uint32_t SystemProperties::WaitAny(uint32_t old_serial) {
uint32_t new_serial;
Wait(nullptr, old_serial, &new_serial, nullptr);
diff --git a/libm/Android.bp b/libm/Android.bp
index bf05b17..de32185 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -286,6 +286,7 @@
pack_relocations: false,
ldflags: ["-Wl,--hash-style=both"],
version_script: ":libm.arm.map",
+ whole_static_libs: [ "libgcc_stripped" ],
},
arm64: {
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 1393eb5..e09b2a4 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1503,7 +1503,16 @@
// Open the file.
int fd = open_library(ns, zip_archive_cache, name, needed_by, &file_offset, &realpath);
if (fd == -1) {
- DL_OPEN_ERR("library \"%s\" not found", name);
+ if (task->is_dt_needed()) {
+ if (needed_by->is_main_executable()) {
+ DL_OPEN_ERR("library \"%s\" not found: needed by main executable", name);
+ } else {
+ DL_OPEN_ERR("library \"%s\" not found: needed by %s in namespace %s", name,
+ needed_by->get_realpath(), task->get_start_from()->get_name());
+ }
+ } else {
+ DL_OPEN_ERR("library \"%s\" not found", name);
+ }
return false;
}
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 9e46394..b69da97 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -204,7 +204,10 @@
// The two libs are in ns2/ subdir.
TEST(dl, exec_without_ld_config_file) {
#if defined(__BIONIC__)
- std::string error_message = "CANNOT LINK EXECUTABLE \"" + GetTestlibRoot() + "/ld_config_test_helper/ld_config_test_helper\": library \"ld_config_test_helper_lib1.so\" not found\n";
+ std::string error_message =
+ "CANNOT LINK EXECUTABLE \"" + GetTestlibRoot() +
+ "/ld_config_test_helper/ld_config_test_helper\": library \"ld_config_test_helper_lib1.so\" "
+ "not found: needed by main executable\n";
std::string helper = GetTestlibRoot() +
"/ld_config_test_helper/ld_config_test_helper";
chmod(helper.c_str(), 0755);
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index e98d66f..7e772b8 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -28,6 +28,7 @@
#include <android/dlext.h>
#include <android-base/file.h>
#include <android-base/strings.h>
+#include <android-base/test_utils.h>
#include <sys/mman.h>
#include <sys/types.h>
@@ -1374,7 +1375,10 @@
void* handle2 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle2 == nullptr);
- ASSERT_STREQ("dlopen failed: library \"libnstest_private_external.so\" not found", dlerror());
+ const char* error = dlerror();
+ ASSERT_MATCH(error,
+ R"(dlopen failed: library "libnstest_private_external.so" not found: needed by )"
+ R"(\S+libnstest_root_not_isolated.so in namespace private_isolated1)");
// Check dlopen by absolute path
handle2 = android_dlopen_ext(lib_private_external_path.c_str(), RTLD_NOW, &extinfo);
@@ -1502,7 +1506,9 @@
void* handle2 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle2 == nullptr);
- ASSERT_STREQ("dlopen failed: library \"libnstest_private_external.so\" not found", dlerror());
+ ASSERT_MATCH(dlerror(),
+ R"(dlopen failed: library "libnstest_private_external.so" not found: needed by )"
+ R"(\S+libnstest_root_not_isolated.so in namespace private_isolated_shared)");
// Check dlopen by absolute path
handle2 = android_dlopen_ext(lib_private_external_path.c_str(), RTLD_NOW, &extinfo);
@@ -1762,7 +1768,10 @@
handle1 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
ASSERT_TRUE(handle1 == nullptr);
- ASSERT_STREQ("dlopen failed: library \"libnstest_public.so\" not found", dlerror());
+ ASSERT_MATCH(
+ dlerror(),
+ R"(dlopen failed: library "libnstest_public.so" not found: needed by \S+libnstest_root.so)"
+ R"( in namespace isolated2)");
}
TEST(dlext, ns_inaccessible_error_message) {
diff --git a/tests/system_properties_test.cpp b/tests/system_properties_test.cpp
index 245e42f..6d696c7 100644
--- a/tests/system_properties_test.cpp
+++ b/tests/system_properties_test.cpp
@@ -340,9 +340,9 @@
ASSERT_EQ(0, system_properties.Add("property", 8, "value1", 6));
const prop_info* pi = system_properties.Find("property");
ASSERT_TRUE(pi != nullptr);
- unsigned serial = system_properties.Serial(pi);
+ unsigned serial = __system_property_serial(pi);
ASSERT_EQ(0, system_properties.Update(const_cast<prop_info*>(pi), "value2", 6));
- ASSERT_NE(serial, system_properties.Serial(pi));
+ ASSERT_NE(serial, __system_property_serial(pi));
#else // __BIONIC__
GTEST_SKIP() << "bionic-only test";
#endif // __BIONIC__
@@ -389,7 +389,7 @@
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));
ASSERT_TRUE(pi != nullptr);
- unsigned serial = system_properties.Serial(pi);
+ unsigned serial = __system_property_serial(pi);
std::thread thread([&system_properties]() {
prop_info* pi = const_cast<prop_info*>(system_properties.Find("property"));