riscv64: more <sys/ucontext.h>.

Actually, we don't want to reuse the kernel struct ucontext because its
uc_mcontext has the wrong type, which means the fields within that end
up with the wrong names. Add the call site that made that evident, and
update <sys/ucontext.h> appropriately.

Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: treehugger
Change-Id: If1d079afef0d5953aa22d9b0e049cfb0119c7718
diff --git a/libc/bionic/android_profiling_dynamic.cpp b/libc/bionic/android_profiling_dynamic.cpp
index 3460a6d..8c9127e 100644
--- a/libc/bionic/android_profiling_dynamic.cpp
+++ b/libc/bionic/android_profiling_dynamic.cpp
@@ -204,12 +204,14 @@
   auto ret = -ENOSYS;
   ucontext_t* ctx = reinterpret_cast<ucontext_t*>(void_context);
 
-#if defined(__arm__)
+#if defined(__aarch64__)
+  ctx->uc_mcontext.regs[0] = ret;
+#elif defined(__arm__)
   ctx->uc_mcontext.arm_r0 = ret;
-#elif defined(__aarch64__)
-  ctx->uc_mcontext.regs[0] = ret;  // x0
 #elif defined(__i386__)
   ctx->uc_mcontext.gregs[REG_EAX] = ret;
+#elif defined(__riscv)
+  ctx->uc_mcontext.__gregs[REG_A0] = ret;
 #elif defined(__x86_64__)
   ctx->uc_mcontext.gregs[REG_RAX] = ret;
 #else
diff --git a/libc/include/sys/ucontext.h b/libc/include/sys/ucontext.h
index b000914..68b218e 100644
--- a/libc/include/sys/ucontext.h
+++ b/libc/include/sys/ucontext.h
@@ -320,6 +320,7 @@
 #define REG_RA 1
 #define REG_SP 2
 #define REG_TP 4
+#define REG_A0 10
 
 typedef unsigned long __riscv_mc_gp_state[NGREG];
 
@@ -358,8 +359,17 @@
   union __riscv_mc_fp_state __fpregs;
 } mcontext_t;
 
-#include <asm/ucontext.h>
-typedef struct ucontext ucontext_t;
+/* This matches the kernel <asm/ucontext.h> but using mcontext_t. */
+
+typedef struct ucontext_t {
+  unsigned long uc_flags;
+  struct ucontext_t* uc_link;
+  stack_t uc_stack;
+  sigset_t uc_sigmask;
+  /* The kernel adds extra padding here to allow sigset_t to grow. */
+  char __padding[128 - sizeof(sigset_t)];
+  mcontext_t uc_mcontext;
+} ucontext_t;
 
 #endif