From 287f48e6e5cdabecefc7a88e35b1a7beca88493a Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Tue, 11 Oct 2022 00:01:35 +0000 Subject: [PATCH] riscv64: more . 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 appropriately. Signed-off-by: Mao Han Signed-off-by: Xia Lifang Signed-off-by: Chen Guoyin Signed-off-by: Wang Chen Signed-off-by: Lu Xufan Test: treehugger Change-Id: If1d079afef0d5953aa22d9b0e049cfb0119c7718 --- libc/bionic/android_profiling_dynamic.cpp | 8 +++++--- libc/include/sys/ucontext.h | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/libc/bionic/android_profiling_dynamic.cpp b/libc/bionic/android_profiling_dynamic.cpp index 3460a6d54..8c9127ecc 100644 --- a/libc/bionic/android_profiling_dynamic.cpp +++ b/libc/bionic/android_profiling_dynamic.cpp @@ -204,12 +204,14 @@ static void HandleSigsysSeccompOverride(int /*signal_number*/, siginfo_t* info, auto ret = -ENOSYS; ucontext_t* ctx = reinterpret_cast(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 b000914ad..68b218ea1 100644 --- a/libc/include/sys/ucontext.h +++ b/libc/include/sys/ucontext.h @@ -320,6 +320,7 @@ typedef struct ucontext { #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 @@ typedef struct mcontext_t { union __riscv_mc_fp_state __fpregs; } mcontext_t; -#include -typedef struct ucontext ucontext_t; +/* This matches the kernel 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