Make aligned_alloc match the standard.

Jemalloc does not verify that the size parameter is a multiple of
alignment. Fix this since it only went into P.

Fix the unit tests, and fix malloc debug/malloc hooks to handle this
new restrictive behavior.

Bug: 126944692

Test: Ran bionic unit tests.
Test: Ran bionic unit tests with malloc hooks enabled (no new tests fail).
Test: Ran bionic unit tests with malloc debug enabled (no new tests fail).
Test: Ran malloc debug unit tests.
Change-Id: I4d50785928815679c781ca729f998454d76b9192
diff --git a/tests/stdlib_test.cpp b/tests/stdlib_test.cpp
index 408a9c7..ff4cb71 100644
--- a/tests/stdlib_test.cpp
+++ b/tests/stdlib_test.cpp
@@ -272,11 +272,11 @@
   for (size_t align = 1; align <= 2048; align <<= 1) {
     // Try all of the non power of 2 values from the last until this value.
     for (size_t fail_align = last_align + 1; fail_align < align; fail_align++) {
-      ASSERT_TRUE(aligned_alloc(fail_align, 256) == nullptr)
+      ASSERT_TRUE(aligned_alloc(fail_align, fail_align) == nullptr)
           << "Unexpected success at align " << fail_align;
       ASSERT_EQ(EINVAL, errno) << "Unexpected errno at align " << fail_align;
     }
-    void* ptr = aligned_alloc(align, 256);
+    void* ptr = aligned_alloc(align, 2 * align);
     ASSERT_TRUE(ptr != nullptr) << "Unexpected failure at align " << align;
     ASSERT_EQ(0U, reinterpret_cast<uintptr_t>(ptr) & (align - 1))
         << "Did not return a valid aligned ptr " << ptr << " expected alignment " << align;
@@ -292,11 +292,11 @@
 
 TEST(stdlib, aligned_alloc_size_not_multiple_of_alignment) {
   SKIP_WITH_HWASAN;
-  for (size_t size = 1; size <= 2048; size++) {
-    void* ptr = aligned_alloc(2048, size);
-    ASSERT_TRUE(ptr != nullptr) << "Failed at size " << std::to_string(size);
-    free(ptr);
-  }
+
+  ASSERT_TRUE(aligned_alloc(2048, 1) == nullptr);
+  ASSERT_TRUE(aligned_alloc(4, 3) == nullptr);
+  ASSERT_TRUE(aligned_alloc(4, 7) == nullptr);
+  ASSERT_TRUE(aligned_alloc(16, 8) == nullptr);
 }
 
 TEST(stdlib, realpath__NULL_filename) {