[RFC PATCH V2 30/38] riscv: s64ilp32: Add u32ilp32 ptrace support

From: guoren
Date: Sun Nov 12 2023 - 01:19:28 EST


From: Guo Ren <guoren@xxxxxxxxxxxxxxxxx>

The s64ilp32 supports both u64ilp32 and u32ilp32 ABIs, and their pt_regs
differ. So introduce the compat feature to help u32ilp32 ABI. Now
u64ilp32 and u32ilp32 applications could work with the s64ilp32 Linux
ptrace concurrently.

Signed-off-by: Guo Ren <guoren@xxxxxxxxxxxxxxxxx>
Signed-off-by: Guo Ren <guoren@xxxxxxxxxx>
---
arch/riscv/include/asm/elf.h | 2 +-
arch/riscv/kernel/ptrace.c | 6 ++++--
2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/riscv/include/asm/elf.h b/arch/riscv/include/asm/elf.h
index 5b2bf1a7cb59..58c2e5ef2b7a 100644
--- a/arch/riscv/include/asm/elf.h
+++ b/arch/riscv/include/asm/elf.h
@@ -143,13 +143,13 @@ do { if ((ex).e_ident[EI_CLASS] == ELFCLASS32) \
(current->personality & (~PER_MASK))); \
} while (0)

-#ifdef CONFIG_COMPAT
#define COMPAT_ELF_ET_DYN_BASE ((TASK_SIZE_32 / 3) * 2)

/* rv32 registers */
typedef compat_ulong_t compat_elf_greg_t;
typedef compat_elf_greg_t compat_elf_gregset_t[ELF_NGREG];

+#ifdef CONFIG_COMPAT
extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
int uses_interp);
#define compat_arch_setup_additional_pages \
diff --git a/arch/riscv/kernel/ptrace.c b/arch/riscv/kernel/ptrace.c
index 5471b12127da..1078c0f454c1 100644
--- a/arch/riscv/kernel/ptrace.c
+++ b/arch/riscv/kernel/ptrace.c
@@ -295,7 +295,7 @@ long arch_ptrace(struct task_struct *child, long request,
return ret;
}

-#ifdef CONFIG_COMPAT
+#if IS_ENABLED(CONFIG_COMPAT) || IS_ENABLED(CONFIG_ARCH_RV64ILP32)
static int compat_riscv_gpr_get(struct task_struct *target,
const struct user_regset *regset,
struct membuf to)
@@ -350,7 +350,9 @@ static const struct user_regset_view compat_riscv_user_native_view = {
.regsets = compat_riscv_user_regset,
.n = ARRAY_SIZE(compat_riscv_user_regset),
};
+#endif

+#ifdef CONFIG_COMPAT
long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
compat_ulong_t caddr, compat_ulong_t cdata)
{
@@ -368,7 +370,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,

const struct user_regset_view *task_user_regset_view(struct task_struct *task)
{
-#ifdef CONFIG_COMPAT
+#if IS_ENABLED(CONFIG_COMPAT) || IS_ENABLED(CONFIG_ARCH_RV64ILP32)
if (test_tsk_thread_flag(task, TIF_32BIT) &&
!test_tsk_thread_flag(task, TIF_64ILP32))
return &compat_riscv_user_native_view;
--
2.36.1