Merge "Move bionic test libraries to a default, for easy consumption in cts." into main
diff --git a/libc/bionic/android_unsafe_frame_pointer_chase.cpp b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
index 1a59718..58b7cd8 100644
--- a/libc/bionic/android_unsafe_frame_pointer_chase.cpp
+++ b/libc/bionic/android_unsafe_frame_pointer_chase.cpp
@@ -74,7 +74,9 @@
   while (1) {
 #if defined(__riscv)
     // Frame addresses seem to have been implemented incorrectly for RISC-V.
-    // See https://reviews.llvm.org/D87579.
+    // See https://reviews.llvm.org/D87579. We did at least manage to get this
+    // documented in the RISC-V psABI though:
+    // https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-cc.adoc#frame-pointer-convention
     auto* frame = reinterpret_cast<frame_record*>(begin - 16);
 #else
     auto* frame = reinterpret_cast<frame_record*>(begin);
diff --git a/libc/include/bits/elf_common.h b/libc/include/bits/elf_common.h
index b3c57a2..ac89dd6 100644
--- a/libc/include/bits/elf_common.h
+++ b/libc/include/bits/elf_common.h
@@ -1248,6 +1248,7 @@
 
 /*
  * RISC-V relocation types.
+ * https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc#relocations
  */
 
 /* Relocation types used by the dynamic linker. */
@@ -1304,6 +1305,9 @@
 #define	R_RISCV_SET32		56
 #define	R_RISCV_32_PCREL	57
 #define	R_RISCV_IRELATIVE	58
+#define	R_RISCV_PLT32		59
+#define	R_RISCV_SET_ULEB128	60
+#define	R_RISCV_SUB_ULEB128	61
 
 #define	R_SPARC_NONE		0
 #define	R_SPARC_8		1
diff --git a/libc/platform/bionic/page.h b/libc/platform/bionic/page.h
index a75b3ac..65faba4 100644
--- a/libc/platform/bionic/page.h
+++ b/libc/platform/bionic/page.h
@@ -27,11 +27,19 @@
 #if defined(PAGE_SIZE)
   return PAGE_SIZE;
 #else
-  static const size_t page_size = getauxval(PAGE_SIZE);
+  static const size_t page_size = getauxval(AT_PAGESZ);
   return page_size;
 #endif
 }
 
+constexpr size_t max_page_size() {
+#if defined(PAGE_SIZE)
+  return PAGE_SIZE;
+#else
+  return 65536;
+#endif
+}
+
 // Returns the address of the page containing address 'x'.
 inline uintptr_t page_start(uintptr_t x) {
   return x & ~(page_size() - 1);
diff --git a/libc/private/WriteProtected.h b/libc/private/WriteProtected.h
index 746f72a..2faaf77 100644
--- a/libc/private/WriteProtected.h
+++ b/libc/private/WriteProtected.h
@@ -25,15 +25,16 @@
 #include <async_safe/log.h>
 
 #include "platform/bionic/macros.h"
+#include "platform/bionic/page.h"
 
 template <typename T>
 union WriteProtectedContents {
   T value;
-  char padding[PAGE_SIZE];
+  char padding[max_page_size()];
 
   WriteProtectedContents() = default;
   BIONIC_DISALLOW_COPY_AND_ASSIGN(WriteProtectedContents);
-} __attribute__((aligned(PAGE_SIZE)));
+} __attribute__((aligned(max_page_size())));
 
 // Write protected wrapper class that aligns its contents to a page boundary,
 // and sets the memory protection to be non-writable, except when being modified
@@ -41,8 +42,8 @@
 template <typename T>
 class WriteProtected {
  public:
-  static_assert(sizeof(T) < PAGE_SIZE,
-                "WriteProtected only supports contents up to PAGE_SIZE");
+  static_assert(sizeof(T) < max_page_size(),
+                "WriteProtected only supports contents up to max_page_size()");
   static_assert(__is_pod(T), "WriteProtected only supports POD contents");
 
   WriteProtected() = default;
@@ -80,7 +81,7 @@
     // ourselves.
     addr = untag_address(addr);
 #endif
-    if (mprotect(reinterpret_cast<void*>(addr), PAGE_SIZE, prot) == -1) {
+    if (mprotect(reinterpret_cast<void*>(addr), max_page_size(), prot) == -1) {
       async_safe_fatal("WriteProtected mprotect %x failed: %s", prot, strerror(errno));
     }
   }