Merge "Avoid using malloc debug code after exit."
diff --git a/libc/Android.bp b/libc/Android.bp
index fa1eab6..5554f28 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -76,6 +76,7 @@
},
native_coverage: false,
recovery_available: true,
+ native_bridge_supported: true,
// lld complains about duplicate symbols in libcrt and libgcc. Suppress the
// warning since this is intended right now.
@@ -1692,6 +1693,7 @@
host_supported: true,
vendor_available: true,
recovery_available: true,
+ native_bridge_supported: true,
no_libcrt: true,
no_libgcc: true,
@@ -1824,6 +1826,7 @@
defaults: ["linux_bionic_supported"],
vendor_available: true,
recovery_available: true,
+ native_bridge_supported: true,
cflags: [
"-Wno-gcc-compat",
@@ -2082,6 +2085,7 @@
ndk_library {
name: "libc",
+ native_bridge_supported: true,
symbol_file: "libc.map.txt",
first_version: "9",
}
@@ -2091,6 +2095,7 @@
symbol_file: "libc.map.txt",
export_headers_as_system: true,
export_preprocessed_headers: ["include"],
+ native_bridge_supported: true,
export_include_dirs: [
"kernel/android/uapi",
"kernel/uapi",
diff --git a/libc/async_safe/Android.bp b/libc/async_safe/Android.bp
index fbaaad1..c28d53a 100644
--- a/libc/async_safe/Android.bp
+++ b/libc/async_safe/Android.bp
@@ -10,6 +10,7 @@
name: "libasync_safe",
vendor_available: true,
recovery_available: true,
+ native_bridge_supported: true,
include_dirs: ["bionic/libc"],
header_libs: ["libc_headers", "liblog_headers"],
@@ -22,6 +23,7 @@
cc_library_headers {
name: "libasync_safe_headers",
recovery_available: true,
+ native_bridge_supported: true,
defaults: ["linux_bionic_supported"],
export_include_dirs: ["include"],
diff --git a/libc/bionic/malloc_heapprofd.cpp b/libc/bionic/malloc_heapprofd.cpp
index 2aeb9bf..5d3735d 100644
--- a/libc/bionic/malloc_heapprofd.cpp
+++ b/libc/bionic/malloc_heapprofd.cpp
@@ -143,22 +143,23 @@
}
}
+constexpr char kHeapprofdProgramPropertyPrefix[] = "heapprofd.enable.";
+constexpr size_t kHeapprofdProgramPropertyPrefixSize = sizeof(kHeapprofdProgramPropertyPrefix) - 1;
+constexpr size_t kMaxCmdlineSize = 512;
+
static bool GetHeapprofdProgramProperty(char* data, size_t size) {
- constexpr char prefix[] = "heapprofd.enable.";
- // - 1 to skip nullbyte, which we will write later.
- constexpr size_t prefix_size = sizeof(prefix) - 1;
- if (size < prefix_size) {
+ if (size < kHeapprofdProgramPropertyPrefixSize) {
error_log("%s: Overflow constructing heapprofd property", getprogname());
return false;
}
- memcpy(data, prefix, prefix_size);
+ memcpy(data, kHeapprofdProgramPropertyPrefix, kHeapprofdProgramPropertyPrefixSize);
int fd = open("/proc/self/cmdline", O_RDONLY | O_CLOEXEC);
if (fd == -1) {
error_log("%s: Failed to open /proc/self/cmdline", getprogname());
return false;
}
- char cmdline[128];
+ char cmdline[kMaxCmdlineSize];
ssize_t rd = read(fd, cmdline, sizeof(cmdline) - 1);
close(fd);
if (rd == -1) {
@@ -167,7 +168,7 @@
}
cmdline[rd] = '\0';
char* first_arg = static_cast<char*>(memchr(cmdline, '\0', rd));
- if (first_arg == nullptr || first_arg == cmdline + size - 1) {
+ if (first_arg == nullptr) {
error_log("%s: Overflow reading cmdline", getprogname());
return false;
}
@@ -192,12 +193,12 @@
}
size_t name_size = static_cast<size_t>(first_arg - start);
- if (name_size >= size - prefix_size) {
+ if (name_size >= size - kHeapprofdProgramPropertyPrefixSize) {
error_log("%s: overflow constructing heapprofd property.", getprogname());
return false;
}
// + 1 to also copy the trailing null byte.
- memcpy(data + prefix_size, start, name_size + 1);
+ memcpy(data + kHeapprofdProgramPropertyPrefixSize, start, name_size + 1);
return true;
}
@@ -213,7 +214,7 @@
return true;
}
- char program_property[128];
+ char program_property[kHeapprofdProgramPropertyPrefixSize + kMaxCmdlineSize];
if (!GetHeapprofdProgramProperty(program_property,
sizeof(program_property))) {
return false;
diff --git a/libc/include/bits/seek_constants.h b/libc/include/bits/seek_constants.h
index 6b88606..6f3f22d 100644
--- a/libc/include/bits/seek_constants.h
+++ b/libc/include/bits/seek_constants.h
@@ -39,3 +39,23 @@
#define SEEK_CUR 1
/** Seek relative to the end of the file. */
#define SEEK_END 2
+
+#if defined(__USE_GNU)
+
+/**
+ * Seek to the first data (non-hole) location in the file
+ * greater than or equal to the given offset.
+ *
+ * See [lseek(2)](http://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_DATA 3
+
+/**
+ * Seek to the first hole (non-data) location in the file
+ * greater than or equal to the given offset.
+ *
+ * See [lseek(2)](http://man7.org/linux/man-pages/man2/lseek.2.html).
+ */
+#define SEEK_HOLE 4
+
+#endif
diff --git a/libc/system_properties/Android.bp b/libc/system_properties/Android.bp
index 911afb1..8780dda 100644
--- a/libc/system_properties/Android.bp
+++ b/libc/system_properties/Android.bp
@@ -1,6 +1,7 @@
cc_library_static {
name: "libsystemproperties",
defaults: ["libc_defaults"],
+ native_bridge_supported: true,
srcs: [
"context_node.cpp",
"contexts_split.cpp",
diff --git a/libdl/Android.bp b/libdl/Android.bp
index b1ee5ab..e36ddc5 100644
--- a/libdl/Android.bp
+++ b/libdl/Android.bp
@@ -5,6 +5,7 @@
name: "libdl_static",
defaults: ["linux_bionic_supported"],
recovery_available: true,
+ native_bridge_supported: true,
srcs: [
"libdl.cpp",
@@ -32,6 +33,7 @@
cc_library {
name: "libdl",
recovery_available: true,
+ native_bridge_supported: true,
static_ndk_lib: true,
defaults: ["linux_bionic_supported"],
@@ -47,6 +49,7 @@
ldflags: [
"-Wl,--exclude-libs=libgcc.a",
+ "-Wl,--exclude-libs=libgcc_stripped.a",
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
@@ -115,6 +118,7 @@
defaults: ["linux_bionic_supported"],
recovery_available: true,
+ native_bridge_supported: true,
// NOTE: --exclude-libs=libgcc.a makes sure that any symbols libdl.so pulls from
// libgcc.a are made static to libdl.so. This in turn ensures that libraries that
@@ -127,6 +131,7 @@
ldflags: [
"-Wl,--exclude-libs=libgcc.a",
+ "-Wl,--exclude-libs=libgcc_stripped.a",
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
@@ -179,12 +184,14 @@
ndk_library {
name: "libdl",
+ native_bridge_supported: true,
symbol_file: "libdl.map.txt",
first_version: "9",
}
llndk_library {
name: "libdl",
+ native_bridge_supported: true,
symbol_file: "libdl.map.txt",
}
diff --git a/libm/Android.bp b/libm/Android.bp
index 8c32810..48b9a5f 100644
--- a/libm/Android.bp
+++ b/libm/Android.bp
@@ -507,6 +507,7 @@
integer_overflow: false,
},
stl: "none",
+ native_bridge_supported: true,
stubs: {
symbol_file: "libm.map.txt",
@@ -516,12 +517,14 @@
ndk_library {
name: "libm",
+ native_bridge_supported: true,
symbol_file: "libm.map.txt",
first_version: "9",
}
llndk_library {
name: "libm",
+ native_bridge_supported: true,
symbol_file: "libm.map.txt",
}
diff --git a/linker/Android.bp b/linker/Android.bp
index 95fd4f7..23ef5ac 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -2,6 +2,7 @@
name: "liblinker_malloc",
defaults: ["linux_bionic_supported"],
recovery_available: true,
+ native_bridge_supported: true,
srcs: [
"linker_memory.cpp",
@@ -318,6 +319,7 @@
ldflags: [
"-Wl,--exclude-libs=libgcc.a",
+ "-Wl,--exclude-libs=libgcc_stripped.a",
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
@@ -360,6 +362,7 @@
name: "ld-android",
defaults: ["linux_bionic_supported"],
recovery_available: true,
+ native_bridge_supported: true,
nocrt: true,
system_shared_libs: [],
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index c237d6d..01b4dba 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -19,6 +19,7 @@
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <linux/fs.h>
#include <math.h>
#include <stdio.h>
#include <sys/types.h>
@@ -2599,3 +2600,13 @@
funlockfile(fp1);
fclose(fp1);
}
+
+TEST(STDIO_TEST, SEEK_macros) {
+ ASSERT_EQ(0, SEEK_SET);
+ ASSERT_EQ(1, SEEK_CUR);
+ ASSERT_EQ(2, SEEK_END);
+ ASSERT_EQ(3, SEEK_DATA);
+ ASSERT_EQ(4, SEEK_HOLE);
+ // So we'll notice if Linux grows another constant in <linux/fs.h>...
+ ASSERT_EQ(SEEK_MAX, SEEK_HOLE);
+}