[PATCH v2 1/3] riscv: ptrace: add regs_set_register()
Andrew Jones
ajones at ventanamicro.com
Mon Dec 2 01:02:39 PST 2024
On Sun, Dec 01, 2024 at 10:27:57AM +0000, Ben Dooks wrote:
> Since we have regs_get_register() and we could use the set counterpart
> for things like fixing up traps, add regs_set_register() to set a pt_regs
> value from offset.
>
> Signed-off-by: Ben Dooks <ben.dooks at codethink.co.uk>
> ---
> v2:
> - fixed Andrew Jones' suggestions for comments
> ---
> arch/riscv/include/asm/ptrace.h | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/arch/riscv/include/asm/ptrace.h b/arch/riscv/include/asm/ptrace.h
> index b5b0adcc85c1..45c503b592c8 100644
> --- a/arch/riscv/include/asm/ptrace.h
> +++ b/arch/riscv/include/asm/ptrace.h
> @@ -143,6 +143,26 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
> return *(unsigned long *)((unsigned long)regs + offset);
> }
>
> +/**
> + * regs_set_register() - set register value at its offset
> + * @regs: pt_regs to which register value is set
> + * @offset: offset of the register.
drop the '.'
> + * @value: value to set register to
> + *
> + * regs_set_register sets the value @to to a register whose offset from @regs.
^ @value
but just write regs_set_register sets @value...
also
s/whose/which is/
> + * The @offset is the offset of the register in struct pt_regs.
> + * If @offset is bigger than MAX_REG_OFFSET, this will ignore the write.
> + */
> +static inline void regs_set_register(struct pt_regs *regs,
> + unsigned int offset,
> + unsigned long value)
> +{
> + if (unlikely(offset > MAX_REG_OFFSET))
> + return;
> +
> + *(unsigned long *)((unsigned long)regs + offset) = value;
> +}
> +
> /**
> * regs_get_kernel_argument() - get Nth function argument in kernel
> * @regs: pt_regs of that context
> --
> 2.37.2.352.g3c44437643
>
Otherwise,
Reviewed-by: Andrew Jones <ajones at ventanamicro.com>
More information about the linux-riscv
mailing list