Merge "Add tests for <endian.h>."
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 0f2a7b5..ec1d18f 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -34,7 +34,6 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -47,6 +46,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/uio.h>
#include <sys/un.h>
#include <sys/xattr.h>
@@ -487,8 +487,8 @@
class PropertyServiceConnection {
public:
PropertyServiceConnection() : last_error_(0) {
- fd_ = socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
- if (fd_ == -1) {
+ socket_ = ::socket(AF_LOCAL, SOCK_STREAM | SOCK_CLOEXEC, 0);
+ if (socket_ == -1) {
last_error_ = errno;
return;
}
@@ -500,54 +500,33 @@
addr.sun_family = AF_LOCAL;
socklen_t alen = namelen + offsetof(sockaddr_un, sun_path) + 1;
- if (TEMP_FAILURE_RETRY(connect(fd_, reinterpret_cast<sockaddr*>(&addr), alen)) == -1) {
- close(fd_);
- fd_ = -1;
+ if (TEMP_FAILURE_RETRY(connect(socket_, reinterpret_cast<sockaddr*>(&addr), alen)) == -1) {
+ close(socket_);
+ socket_ = -1;
last_error_ = errno;
}
}
bool IsValid() {
- return fd_ != -1;
+ return socket_ != -1;
}
int GetLastError() {
return last_error_;
}
- bool SendUint32(uint32_t value) {
- int result = TEMP_FAILURE_RETRY(send(fd_, &value, sizeof(value), 0));
- return CheckSendRecvResult(result, sizeof(value));
- }
-
- bool SendString(const char* value) {
- uint32_t valuelen = strlen(value);
- if (!SendUint32(valuelen)) {
- return false;
- }
-
- // Trying to send even 0 bytes to closed socket may lead to
- // broken pipe (http://b/34670529).
- if (valuelen == 0) {
- return true;
- }
-
- int result = TEMP_FAILURE_RETRY(send(fd_, value, valuelen, 0));
- return CheckSendRecvResult(result, valuelen);
- }
-
bool RecvInt32(int32_t* value) {
- int result = TEMP_FAILURE_RETRY(recv(fd_, value, sizeof(*value), MSG_WAITALL));
+ int result = TEMP_FAILURE_RETRY(recv(socket_, value, sizeof(*value), MSG_WAITALL));
return CheckSendRecvResult(result, sizeof(*value));
}
- int GetFd() {
- return fd_;
+ int socket() {
+ return socket_;
}
~PropertyServiceConnection() {
- if (fd_ != -1) {
- close(fd_);
+ if (socket_ != -1) {
+ close(socket_);
}
}
@@ -564,8 +543,69 @@
return last_error_ == 0;
}
- int fd_;
+ int socket_;
int last_error_;
+
+ friend class SocketWriter;
+};
+
+class SocketWriter {
+ public:
+ explicit SocketWriter(PropertyServiceConnection* connection)
+ : connection_(connection), iov_index_(0), uint_buf_index_(0)
+ {}
+
+ SocketWriter& WriteUint32(uint32_t value) {
+ CHECK(uint_buf_index_ < kUintBufSize);
+ CHECK(iov_index_ < kIovSize);
+ uint32_t* ptr = uint_buf_ + uint_buf_index_;
+ uint_buf_[uint_buf_index_++] = value;
+ iov_[iov_index_].iov_base = ptr;
+ iov_[iov_index_].iov_len = sizeof(*ptr);
+ ++iov_index_;
+ return *this;
+ }
+
+ SocketWriter& WriteString(const char* value) {
+ uint32_t valuelen = strlen(value);
+ WriteUint32(valuelen);
+ if (valuelen == 0) {
+ return *this;
+ }
+
+ CHECK(iov_index_ < kIovSize);
+ iov_[iov_index_].iov_base = const_cast<char*>(value);
+ iov_[iov_index_].iov_len = valuelen;
+ ++iov_index_;
+
+ return *this;
+ }
+
+ bool Send() {
+ if (!connection_->IsValid()) {
+ return false;
+ }
+
+ if (writev(connection_->socket(), iov_, iov_index_) == -1) {
+ connection_->last_error_ = errno;
+ return false;
+ }
+
+ iov_index_ = uint_buf_index_ = 0;
+ return true;
+ }
+
+ private:
+ static constexpr size_t kUintBufSize = 8;
+ static constexpr size_t kIovSize = 8;
+
+ PropertyServiceConnection* connection_;
+ iovec iov_[kIovSize];
+ size_t iov_index_;
+ uint32_t uint_buf_[kUintBufSize];
+ size_t uint_buf_index_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(SocketWriter);
};
struct prop_msg {
@@ -581,9 +621,9 @@
}
int result = -1;
- int fd = connection.GetFd();
+ int s = connection.socket();
- const int num_bytes = TEMP_FAILURE_RETRY(send(fd, msg, sizeof(prop_msg), 0));
+ const int num_bytes = TEMP_FAILURE_RETRY(send(s, msg, sizeof(prop_msg), 0));
if (num_bytes == sizeof(prop_msg)) {
// We successfully wrote to the property server but now we
// wait for the property server to finish its work. It
@@ -593,7 +633,7 @@
// once the socket closes. Out of paranoia we cap our poll
// at 250 ms.
pollfd pollfds[1];
- pollfds[0].fd = fd;
+ pollfds[0].fd = s;
pollfds[0].events = 0;
const int poll_result = TEMP_FAILURE_RETRY(poll(pollfds, 1, 250 /* ms */));
if (poll_result == 1 && (pollfds[0].revents & POLLHUP) != 0) {
@@ -1230,7 +1270,6 @@
detect_protocol_version();
}
- int result = -1;
if (g_propservice_protocol_version == kProtocolVersion1) {
// Old protocol does not support long names
if (strlen(key) >= PROP_NAME_MAX) return -1;
@@ -1241,27 +1280,60 @@
strlcpy(msg.name, key, sizeof msg.name);
strlcpy(msg.value, value, sizeof msg.value);
- result = send_prop_msg(&msg);
+ return send_prop_msg(&msg);
} else {
// Use proper protocol
PropertyServiceConnection connection;
- if (connection.IsValid() && connection.SendUint32(PROP_MSG_SETPROP2) &&
- connection.SendString(key) && connection.SendString(value) &&
- connection.RecvInt32(&result)) {
- if (result != PROP_SUCCESS) {
- __libc_format_log(ANDROID_LOG_WARN, "libc",
- "Unable to set property \"%s\" to \"%s\": error code: 0x%x", key, value,
- result);
- }
- } else {
- result = connection.GetLastError();
- __libc_format_log(ANDROID_LOG_WARN, "libc",
- "Unable to set property \"%s\" to \"%s\": error code: 0x%x (%s)", key,
- value, result, strerror(result));
+ if (!connection.IsValid()) {
+ errno = connection.GetLastError();
+ __libc_format_log(ANDROID_LOG_WARN,
+ "libc",
+ "Unable to set property \"%s\" to \"%s\": connection failed; errno=%d (%s)",
+ key,
+ value,
+ errno,
+ strerror(errno));
+ return -1;
}
- }
- return result != 0 ? -1 : 0;
+ SocketWriter writer(&connection);
+ if (!writer.WriteUint32(PROP_MSG_SETPROP2).WriteString(key).WriteString(value).Send()) {
+ errno = connection.GetLastError();
+ __libc_format_log(ANDROID_LOG_WARN,
+ "libc",
+ "Unable to set property \"%s\" to \"%s\": write failed; errno=%d (%s)",
+ key,
+ value,
+ errno,
+ strerror(errno));
+ return -1;
+ }
+
+ int result = -1;
+ if (!connection.RecvInt32(&result)) {
+ errno = connection.GetLastError();
+ __libc_format_log(ANDROID_LOG_WARN,
+ "libc",
+ "Unable to set property \"%s\" to \"%s\": recv failed; errno=%d (%s)",
+ key,
+ value,
+ errno,
+ strerror(errno));
+ return -1;
+ }
+
+ if (result != PROP_SUCCESS) {
+ __libc_format_log(ANDROID_LOG_WARN,
+ "libc",
+ "Unable to set property \"%s\" to \"%s\": error code: 0x%x",
+ key,
+ value,
+ result);
+ return -1;
+ }
+
+ return 0;
+ }
}
int __system_property_update(prop_info* pi, const char* value, unsigned int len) {
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 798b9c3..9ad26ff 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -185,10 +185,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__timer_create; # arm x86 mips
__timer_delete; # arm x86 mips
@@ -1540,8 +1542,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index c686bb9..4953380 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -130,10 +130,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
__vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
@@ -1257,8 +1259,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.map.txt b/libc/libc.map.txt
index 1217bd5..6cc0f32 100644
--- a/libc/libc.map.txt
+++ b/libc/libc.map.txt
@@ -186,10 +186,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__timer_create; # arm x86 mips
__timer_delete; # arm x86 mips
@@ -1566,8 +1568,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 79fbc1a..91d80e0 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -182,10 +182,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__timer_create; # arm x86 mips
__timer_delete; # arm x86 mips
@@ -1381,8 +1383,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index c686bb9..4953380 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -130,10 +130,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
__vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
@@ -1257,8 +1259,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index a968693..7a72fca 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -182,10 +182,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__timer_create; # arm x86 mips
__timer_delete; # arm x86 mips
@@ -1380,8 +1382,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index c686bb9..4953380 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -130,10 +130,12 @@
__sym_ntop;
__sym_ntos;
__sym_ston;
+ __system_property_area_serial; # introduced=23
__system_property_find;
__system_property_foreach; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_get;
__system_property_read;
+ __system_property_serial; # introduced-arm=19 introduced-arm64=21 introduced-mips=19 introduced-mips64=21 introduced-x86=19 introduced-x86_64=21
__system_property_set; # introduced-arm=12 introduced-arm64=21 introduced-mips=12 introduced-mips64=21 introduced-x86=12 introduced-x86_64=21
__umask_chk; # introduced-arm=18 introduced-arm64=21 introduced-mips=18 introduced-mips64=21 introduced-x86=18 introduced-x86_64=21
__vsnprintf_chk; # introduced-arm=17 introduced-arm64=21 introduced-mips=17 introduced-mips64=21 introduced-x86=17 introduced-x86_64=21
@@ -1257,8 +1259,6 @@
__system_property_area__; # var
__system_property_add;
__system_property_area_init;
- __system_property_area_serial;
- __system_property_serial;
__system_property_set_filename;
__system_property_update;
android_net_res_stats_get_info_for_net;
diff --git a/libc/private/libc_logging.h b/libc/private/libc_logging.h
index 49a5a3c..d3e4140 100644
--- a/libc/private/libc_logging.h
+++ b/libc/private/libc_logging.h
@@ -97,6 +97,14 @@
#endif
int __libc_write_log(int pri, const char* _Nonnull tag, const char* _Nonnull msg);
+#define CHECK(predicate) \
+ do { \
+ if (!(predicate)) { \
+ __libc_fatal("%s:%d: %s CHECK '" #predicate "' failed", \
+ __FILE__, __LINE__, __FUNCTION__); \
+ } \
+ } while(0)
+
__END_DECLS
#endif
diff --git a/linker/Android.bp b/linker/Android.bp
index aab05b4..a43f8b3 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -39,29 +39,35 @@
srcs: ["arch/arm/begin.S"],
cflags: ["-D__work_around_b_24465209__"],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
arm64: {
srcs: ["arch/arm64/begin.S"],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
x86: {
srcs: ["arch/x86/begin.c"],
cflags: ["-D__work_around_b_24465209__"],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
x86_64: {
srcs: ["arch/x86_64/begin.S"],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
mips: {
srcs: [
"arch/mips/begin.S",
"linker_mips.cpp",
],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker"],
},
mips64: {
srcs: [
"arch/mips64/begin.S",
"linker_mips.cpp",
],
+ ldflags: ["-Wl,-dynamic-linker,/system/bin/linker64"],
},
},
diff --git a/linker/linker_debug.h b/linker/linker_debug.h
index 5af9929..42796e9 100644
--- a/linker/linker_debug.h
+++ b/linker/linker_debug.h
@@ -59,13 +59,6 @@
__LIBC_HIDDEN__ extern int g_ld_debug_verbosity;
-#define CHECK(predicate) { \
- if (!(predicate)) { \
- __libc_fatal("%s:%d: %s CHECK '" #predicate "' failed", \
- __FILE__, __LINE__, __FUNCTION__); \
- } \
- }
-
#if LINKER_DEBUG_TO_LOG
#define _PRINTVF(v, x...) \
do { \
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index d52b1d6..d037a18 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -496,7 +496,7 @@
// see also https://code.google.com/p/android/issues/detail?id=63174
if (reinterpret_cast<ElfW(Addr)>(&_start) == entry_point) {
__libc_format_fd(STDOUT_FILENO,
- "This is %s, the helper program for shared library executables.\n",
+ "This is %s, the helper program for dynamic executables.\n",
args.argv[0]);
exit(0);
}
diff --git a/tests/dl_test.cpp b/tests/dl_test.cpp
index 74c7b51..ee9b2e1 100644
--- a/tests/dl_test.cpp
+++ b/tests/dl_test.cpp
@@ -24,6 +24,8 @@
#include <string>
+#include "utils.h"
+
extern "C" int main_global_default_serial() {
return 3370318;
}
@@ -69,4 +71,19 @@
ASSERT_EQ(3370318, lib_global_protected_get_serial());
}
+TEST(dl, exec_linker) {
+#if defined(__BIONIC__)
+#if defined(__LP64__)
+ static constexpr const char* kPathToLinker = "/system/bin/linker64";
+#else
+ static constexpr const char* kPathToLinker = "/system/bin/linker";
+#endif
+ ExecTestHelper eth;
+ std::string expected_output = std::string("This is ") + kPathToLinker +
+ ", the helper program for dynamic executables.\n";
+ eth.SetArgs( { kPathToLinker, nullptr });
+ eth.Run([&]() { execve(kPathToLinker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
+#endif
+}
+
// TODO: Add tests for LD_PRELOADs