From: Ben Dooks <ben.dooks@codethink.co.uk>
To: linux-riscv@lists.infradead.org
Cc: ajones@ventanamicro.com, palmer@dabbelt.com,
Ben Dooks <ben.dooks@codethink.co.uk>
Subject: [PATCH v2 1/3] riscv: ptrace: add regs_set_register()
Date: Sun, 1 Dec 2024 10:27:57 +0000 [thread overview]
Message-ID: <20241201102759.221176-2-ben.dooks@codethink.co.uk> (raw)
In-Reply-To: <20241201102759.221176-1-ben.dooks@codethink.co.uk>
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@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.
+ * @value: value to set register to
+ *
+ * regs_set_register sets the value @to to a register whose offset from @regs.
+ * 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
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2024-12-01 10:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-01 10:27 Updates for asm/ptrace/insn code Ben Dooks
2024-12-01 10:27 ` Ben Dooks [this message]
2024-12-02 9:02 ` [PATCH v2 1/3] riscv: ptrace: add regs_set_register() Andrew Jones
2024-12-02 17:09 ` Björn Töpel
2024-12-01 10:27 ` [PATCH v2 2/3] riscv: traps: make insn fetch common in unknown instruction Ben Dooks
2024-12-02 9:16 ` Andrew Jones
2024-12-02 9:23 ` Ben Dooks
2024-12-02 17:30 ` Björn Töpel
2024-12-01 10:27 ` [PATCH v2 3/3] riscv: insn: add RV_EXTRACT_FUNCT3() Ben Dooks
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241201102759.221176-2-ben.dooks@codethink.co.uk \
--to=ben.dooks@codethink.co.uk \
--cc=ajones@ventanamicro.com \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox