Skip to content

Commit 5917ea1

Browse files
Leonardo Braspalmer-dabbelt
authored andcommitted
riscv: Introduce is_compat_thread() into compat.h
task_user_regset_view() makes use of a function very similar to is_compat_task(), but pointing to a any thread. In arm64 asm/compat.h there is a function very similar to that: is_compat_thread(struct thread_info *thread) Copy this function to riscv asm/compat.h and make use of it into task_user_regset_view(). Also, introduce a compile-time test for CONFIG_COMPAT and simplify the function code by removing the #ifdef. Signed-off-by: Leonardo Bras <leobras@redhat.com> Reviewed-by: Guo Ren <guoren@kernel.org> Reviewed-by: Andy Chiu <andy.chiu@sifive.com> Link: https://lore.kernel.org/r/20240103160024.70305-6-leobras@redhat.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 4c0b5a4 commit 5917ea1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

arch/riscv/include/asm/compat.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ static inline int is_compat_task(void)
2020
return test_thread_flag(TIF_32BIT);
2121
}
2222

23+
static inline int is_compat_thread(struct thread_info *thread)
24+
{
25+
if (!IS_ENABLED(CONFIG_COMPAT))
26+
return 0;
27+
28+
return test_ti_thread_flag(thread, TIF_32BIT);
29+
}
30+
2331
struct compat_user_regs_struct {
2432
compat_ulong_t pc;
2533
compat_ulong_t ra;

arch/riscv/kernel/ptrace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,14 +374,14 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
374374

375375
return ret;
376376
}
377+
#else
378+
static const struct user_regset_view compat_riscv_user_native_view = {};
377379
#endif /* CONFIG_COMPAT */
378380

379381
const struct user_regset_view *task_user_regset_view(struct task_struct *task)
380382
{
381-
#ifdef CONFIG_COMPAT
382-
if (test_tsk_thread_flag(task, TIF_32BIT))
383+
if (is_compat_thread(&task->thread_info))
383384
return &compat_riscv_user_native_view;
384385
else
385-
#endif
386386
return &riscv_user_native_view;
387387
}

0 commit comments

Comments
 (0)