Merge "Move __libc_int0x80 to an assembly file"
diff --git a/libc/Android.bp b/libc/Android.bp
index 0451cfd..2db2edf 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -2079,6 +2079,7 @@
srcs: ["arch-common/bionic/crtbegin_so.c"],
defaults: ["crt_so_defaults"],
+ bazel_module: { bp2build_available: true },
}
cc_object {
diff --git a/libc/bionic/iconv.cpp b/libc/bionic/iconv.cpp
index 015d70f..79a429c 100644
--- a/libc/bionic/iconv.cpp
+++ b/libc/bionic/iconv.cpp
@@ -356,6 +356,10 @@
errno = EBADF;
return -1;
}
+
+ // Since none of our encodings are stateful, state flushing is a no-op.
+ if (!__src_buf) return 0;
+
return __converter->Convert(__src_buf, __src_bytes_left, __dst_buf, __dst_bytes_left);
}
diff --git a/libc/private/bionic_inline_raise.h b/libc/private/bionic_inline_raise.h
index 7223b4e..8565c80 100644
--- a/libc/private/bionic_inline_raise.h
+++ b/libc/private/bionic_inline_raise.h
@@ -60,8 +60,18 @@
register long x3 __asm__("x3") = reinterpret_cast<long>(&info);
register long x8 __asm__("x8") = __NR_rt_tgsigqueueinfo;
__asm__("svc #0" : "=r"(x0) : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory");
+#elif defined(__x86_64__)
+ register long rax __asm__("rax") = __NR_rt_tgsigqueueinfo;
+ register long rdi __asm__("rdi") = pid;
+ register long rsi __asm__("rsi") = tid;
+ register long rdx __asm__("rdx") = sig;
+ register long r10 __asm__("r10") = reinterpret_cast<long>(&info);
+ __asm__("syscall"
+ : "+r"(rax)
+ : "r"(rdi), "r"(rsi), "r"(rdx), "r"(r10)
+ : "memory", "cc", "r11", "rcx");
#else
+ // 32-bit x86 is a huge mess, so don't even bother...
syscall(__NR_rt_tgsigqueueinfo, pid, tid, sig, &info);
#endif
}
-
diff --git a/linker/Android.bp b/linker/Android.bp
index 06e6fbc..8b2d842 100644
--- a/linker/Android.bp
+++ b/linker/Android.bp
@@ -391,7 +391,7 @@
sh_binary {
name: "ldd",
- src: "ldd",
+ src: "ldd.sh",
bazel_module: { bp2build_available: true },
}
diff --git a/linker/ldd b/linker/ldd.sh
similarity index 100%
rename from linker/ldd
rename to linker/ldd.sh
diff --git a/tests/BionicDeathTest.h b/tests/BionicDeathTest.h
index 6826ab7..f70839a 100644
--- a/tests/BionicDeathTest.h
+++ b/tests/BionicDeathTest.h
@@ -14,8 +14,7 @@
* limitations under the License.
*/
-#ifndef BIONIC_TESTS_BIONIC_DEATH_TEST_H_
-#define BIONIC_TESTS_BIONIC_DEATH_TEST_H_
+#pragma once
#include <signal.h>
@@ -44,5 +43,3 @@
private:
struct sigaction64 previous_;
};
-
-#endif // BIONIC_TESTS_BIONIC_DEATH_TEST_H_
diff --git a/tests/assert_test.cpp b/tests/assert_test.cpp
index 9436151..714e22a 100644
--- a/tests/assert_test.cpp
+++ b/tests/assert_test.cpp
@@ -19,14 +19,18 @@
#undef NDEBUG
#include <assert.h>
+#include "BionicDeathTest.h"
+
+using assert_DeathTest = BionicDeathTest;
+
TEST(assert, assert_true) {
assert(true);
}
-TEST(assert, assert_false) {
+TEST_F(assert_DeathTest, assert_false) {
EXPECT_DEATH(assert(false),
"bionic/tests/assert_test.cpp:.*: "
- "virtual void assert_assert_false_Test::TestBody\\(\\): "
+ "virtual void assert_DeathTest_assert_false_Test::TestBody\\(\\): "
"assertion \"false\" failed");
}
diff --git a/tests/cfi_test.cpp b/tests/cfi_test.cpp
index e0ae3af..d3cd8d1 100644
--- a/tests/cfi_test.cpp
+++ b/tests/cfi_test.cpp
@@ -35,6 +35,8 @@
size_t __cfi_shadow_size();
}
+using cfi_test_DeathTest = BionicDeathTest;
+
static void f() {}
static void test_cfi_slowpath_with_alloc() {
@@ -45,7 +47,7 @@
}
}
-TEST(cfi_test, basic) {
+TEST_F(cfi_test_DeathTest, basic) {
#if defined(__BIONIC__)
void* handle;
handle = dlopen("libcfi-test.so", RTLD_NOW | RTLD_LOCAL);
diff --git a/tests/clang_fortify_tests.cpp b/tests/clang_fortify_tests.cpp
index 0d17284..0355170 100644
--- a/tests/clang_fortify_tests.cpp
+++ b/tests/clang_fortify_tests.cpp
@@ -99,37 +99,9 @@
#define CONCAT2(x, y) x##y
#define CONCAT(x, y) CONCAT2(x, y)
-#define FORTIFY_TEST_NAME CONCAT(clang_fortify_test_, _FORTIFY_SOURCE)
+#define FORTIFY_TEST_NAME CONCAT(CONCAT(clang_fortify_test_, _FORTIFY_SOURCE), _DeathTest)
-namespace {
-struct FORTIFY_TEST_NAME : BionicDeathTest {
- protected:
- void SetUp() override {
- stdin_saved = dup(STDIN_FILENO);
- if (stdin_saved < 0) err(1, "failed to dup stdin");
-
- int devnull = open("/dev/null", O_RDONLY);
- if (devnull < 0) err(1, "failed to open /dev/null");
-
- if (!dup2(devnull, STDIN_FILENO)) err(1, "failed to overwrite stdin");
- static_cast<void>(close(devnull));
-
- BionicDeathTest::SetUp();
- }
-
- void TearDown() override {
- if (stdin_saved == -1) return;
- if (!dup2(stdin_saved, STDIN_FILENO)) warn("failed to restore stdin");
-
- static_cast<void>(close(stdin_saved));
-
- BionicDeathTest::TearDown();
- }
-
- private:
- int stdin_saved = -1;
-};
-} // namespace
+using FORTIFY_TEST_NAME = BionicDeathTest;
template <typename Fn>
__attribute__((noreturn)) static void ExitAfter(Fn&& f) {
@@ -153,7 +125,7 @@
#define EXPECT_FORTIFY_DEATH_STRUCT EXPECT_NO_DEATH
#endif
-#define FORTIFY_TEST(test_name) TEST(FORTIFY_TEST_NAME, test_name)
+#define FORTIFY_TEST(test_name) TEST_F(FORTIFY_TEST_NAME, test_name)
#else // defined(COMPILATION_TESTS)
diff --git a/tests/fenv_test.cpp b/tests/fenv_test.cpp
index 89c7fd5..d495970 100644
--- a/tests/fenv_test.cpp
+++ b/tests/fenv_test.cpp
@@ -202,6 +202,7 @@
ASSERT_NE(-1, pid) << strerror(errno);
if (pid == 0) {
+ signal(SIGFPE, SIG_DFL); // Disable debuggerd.
feclearexcept(FE_ALL_EXCEPT);
ASSERT_EQ(0, fetestexcept(FE_ALL_EXCEPT));
ASSERT_EQ(0, feenableexcept(FE_INVALID));
diff --git a/tests/iconv_test.cpp b/tests/iconv_test.cpp
index 768b4fd..bd99000 100644
--- a/tests/iconv_test.cpp
+++ b/tests/iconv_test.cpp
@@ -451,5 +451,13 @@
EXPECT_EQ(0, errno);
EXPECT_EQ(sizeof(out_buf), out_bytes);
+ // Is a null pointer and so is in_bytes. This isn't specified by POSIX, but
+ // glibc and macOS both allow that, where Android historically didn't.
+ // https://issuetracker.google.com/180598400
+ errno = 0;
+ ASSERT_EQ(static_cast<size_t>(0), iconv(c, nullptr, nullptr, &out, &out_bytes));
+ EXPECT_EQ(0, errno);
+ EXPECT_EQ(sizeof(out_buf), out_bytes);
+
EXPECT_EQ(0, iconv_close(c));
}
diff --git a/tests/pthread_test.cpp b/tests/pthread_test.cpp
index d9ad3cc..1cbe3de 100644
--- a/tests/pthread_test.cpp
+++ b/tests/pthread_test.cpp
@@ -45,6 +45,8 @@
#include "SignalUtils.h"
#include "utils.h"
+using pthread_DeathTest = BionicDeathTest;
+
TEST(pthread, pthread_key_create) {
pthread_key_t key;
ASSERT_EQ(0, pthread_key_create(&key, nullptr));
@@ -352,9 +354,6 @@
// Even though this isn't really a death test, we have to say "DeathTest" here so gtest knows to
// run this test (which exits normally) in its own process.
-
-class pthread_DeathTest : public BionicDeathTest {};
-
TEST_F(pthread_DeathTest, pthread_bug_37410) {
// http://code.google.com/p/android/issues/detail?id=37410
ASSERT_EXIT(TestBug37410::main(), ::testing::ExitedWithCode(0), "");
@@ -2468,7 +2467,7 @@
#endif // __BIONIC__
}
-TEST(pthread, pthread_mutex_using_destroyed_mutex) {
+TEST_F(pthread_DeathTest, pthread_mutex_using_destroyed_mutex) {
#if defined(__BIONIC__)
pthread_mutex_t m;
ASSERT_EQ(0, pthread_mutex_init(&m, nullptr));
diff --git a/tests/semaphore_test.cpp b/tests/semaphore_test.cpp
index 6ec8b2a..ed0fcf1 100644
--- a/tests/semaphore_test.cpp
+++ b/tests/semaphore_test.cpp
@@ -23,8 +23,11 @@
#include <time.h>
#include <unistd.h>
-#include "private/bionic_constants.h"
+#include "BionicDeathTest.h"
#include "SignalUtils.h"
+#include "private/bionic_constants.h"
+
+using semaphore_DeathTest = BionicDeathTest;
TEST(semaphore, sem_init) {
sem_t s;
@@ -158,7 +161,7 @@
#endif // __BIONIC__
}
-TEST(semaphore_DeathTest, sem_timedwait_null_timeout) {
+TEST_F(semaphore_DeathTest, sem_timedwait_null_timeout) {
sem_t s;
ASSERT_EQ(0, sem_init(&s, 0, 0));
diff --git a/tests/setjmp_test.cpp b/tests/setjmp_test.cpp
index 2476704..e6b6819 100644
--- a/tests/setjmp_test.cpp
+++ b/tests/setjmp_test.cpp
@@ -19,8 +19,11 @@
#include <setjmp.h>
#include <stdlib.h>
+#include "BionicDeathTest.h"
#include "SignalUtils.h"
+using setjmp_DeathTest = BionicDeathTest;
+
TEST(setjmp, setjmp_smoke) {
int value;
jmp_buf jb;
@@ -226,7 +229,7 @@
#define __JB_SIGFLAG 8
#endif
-TEST(setjmp, setjmp_cookie) {
+TEST_F(setjmp_DeathTest, setjmp_cookie) {
jmp_buf jb;
int value = setjmp(jb);
ASSERT_EQ(0, value);
@@ -241,7 +244,7 @@
EXPECT_DEATH(longjmp(jb, 0), "");
}
-TEST(setjmp, setjmp_cookie_checksum) {
+TEST_F(setjmp_DeathTest, setjmp_cookie_checksum) {
jmp_buf jb;
int value = setjmp(jb);
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index afbbf26..5491589 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -56,8 +56,8 @@
using namespace std::string_literals;
-class stdio_DeathTest : public BionicDeathTest {};
-class stdio_nofortify_DeathTest : public BionicDeathTest {};
+using stdio_DeathTest = BionicDeathTest;
+using stdio_nofortify_DeathTest = BionicDeathTest;
static void SetFileTo(const char* path, const char* content) {
FILE* fp;
@@ -361,7 +361,7 @@
EXPECT_STREQ("<hi>", buf);
}
-TEST(STDIO_TEST, snprintf_n) {
+TEST_F(STDIO_DEATHTEST, snprintf_n) {
#if defined(__BIONIC__)
// http://b/14492135 and http://b/31832608.
char buf[32];
@@ -2425,7 +2425,7 @@
ASSERT_EQ(ENOENT, errno);
}
-TEST(STDIO_DEATHTEST, snprintf_30445072_known_buffer_size) {
+TEST_F(STDIO_DEATHTEST, snprintf_30445072_known_buffer_size) {
char buf[16];
ASSERT_EXIT(snprintf(buf, atol("-1"), "hello"),
testing::KilledBySignal(SIGABRT),
@@ -2437,7 +2437,7 @@
);
}
-TEST(STDIO_DEATHTEST, snprintf_30445072_unknown_buffer_size) {
+TEST_F(STDIO_DEATHTEST, snprintf_30445072_unknown_buffer_size) {
std::string buf = "world";
ASSERT_EXIT(snprintf(&buf[0], atol("-1"), "hello"),
testing::KilledBySignal(SIGABRT),
diff --git a/tests/time_test.cpp b/tests/time_test.cpp
index 93ba426..7c2c890 100644
--- a/tests/time_test.cpp
+++ b/tests/time_test.cpp
@@ -851,11 +851,11 @@
}
TEST(time, clock) {
- // clock(3) is hard to test, but a 1s sleep should cost less than 10ms.
+ // clock(3) is hard to test, but a 1s sleep should cost less than 20ms.
clock_t t0 = clock();
sleep(1);
clock_t t1 = clock();
- ASSERT_LT(t1 - t0, 10 * (CLOCKS_PER_SEC / 1000));
+ ASSERT_LT(t1 - t0, 20 * (CLOCKS_PER_SEC / 1000));
}
static pid_t GetInvalidPid() {