Add riscv64 implementation of __get_bionic_tcb_for_thread().

Bug: http://b/339287219
Change-Id: I2b6f2603cd34e1575d575565c369663bfcdf9be1
diff --git a/libc/bionic/sys_thread_properties.cpp b/libc/bionic/sys_thread_properties.cpp
index d1a73b7..d7188f5 100644
--- a/libc/bionic/sys_thread_properties.cpp
+++ b/libc/bionic/sys_thread_properties.cpp
@@ -77,35 +77,9 @@
 
   // Find the thread-pointer register for the given thread.
   void** tp_reg = nullptr;
-#if defined(__x86_64__)
-  {
-    ErrnoRestorer errno_restorer;
-    errno = 0;
-    uintptr_t fs_base = ptrace(PTRACE_PEEKUSER, tid, offsetof(user_regs_struct, fs_base), nullptr);
-    if (errno == 0) {
-      tp_reg = reinterpret_cast<void**>(fs_base);
-    }
-  }
-#elif defined(__i386__)
-  struct user_regs_struct regs;
-  struct iovec pt_iov = {
-      .iov_base = &regs,
-      .iov_len = sizeof(regs),
-  };
-
-  if (ptrace(PTRACE_GETREGSET, tid, NT_PRSTATUS, &pt_iov) == 0) {
-    struct user_desc u_info;
-    u_info.entry_number = regs.xgs >> 3;
-    if (ptrace(PTRACE_GET_THREAD_AREA, tid, u_info.entry_number, &u_info) == 0) {
-      tp_reg = reinterpret_cast<void**>(u_info.base_addr);
-    }
-  }
-#elif defined(__aarch64__)
+#if defined(__aarch64__)
   uint64_t reg;
-  struct iovec pt_iov {
-    .iov_base = &reg, .iov_len = sizeof(reg),
-  };
-
+  struct iovec pt_iov { .iov_base = &reg, .iov_len = sizeof(reg) };
   if (ptrace(PTRACE_GETREGSET, tid, NT_ARM_TLS, &pt_iov) == 0) {
     tp_reg = reinterpret_cast<void**>(reg);
   }
@@ -114,6 +88,31 @@
     // Reset the tp_reg if ptrace was unsuccessful.
     tp_reg = nullptr;
   }
+#elif defined(__i386__)
+  struct user_regs_struct regs;
+  struct iovec pt_iov = { .iov_base = &regs, .iov_len = sizeof(regs) };
+  if (ptrace(PTRACE_GETREGSET, tid, NT_PRSTATUS, &pt_iov) == 0) {
+    struct user_desc u_info;
+    u_info.entry_number = regs.xgs >> 3;
+    if (ptrace(PTRACE_GET_THREAD_AREA, tid, u_info.entry_number, &u_info) == 0) {
+      tp_reg = reinterpret_cast<void**>(u_info.base_addr);
+    }
+  }
+#elif defined(__riscv)
+  struct user_regs_struct regs;
+  struct iovec pt_iov = { .iov_base = &regs, .iov_len = sizeof(regs) };
+  if (ptrace(PTRACE_GETREGSET, tid, NT_PRSTATUS, &pt_iov) == 0) {
+    tp_reg = reinterpret_cast<void**>(regs.tp);
+  }
+#elif defined(__x86_64__)
+  {
+    ErrnoRestorer errno_restorer;
+    errno = 0;
+    uintptr_t fs_base = ptrace(PTRACE_PEEKUSER, tid, offsetof(user_regs_struct, fs_base), nullptr);
+    if (errno == 0) {
+      tp_reg = reinterpret_cast<void**>(fs_base);
+    }
+  }
 #endif
 
   if (tp_reg == nullptr) {