<div dir="auto">Hey, can you please remove me from your mailing list? </div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Uddeshya</div><div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 10 Feb 2025 at 5:05 PM, Dmitry V. Levin <<a href="mailto:ldv@strace.io">ldv@strace.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Similar to syscall_set_arguments() that complements<br>
syscall_get_arguments(), introduce syscall_set_nr()<br>
that complements syscall_get_nr().<br>
<br>
syscall_set_nr() is going to be needed along with<br>
syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK<br>
architectures to implement PTRACE_SET_SYSCALL_INFO API.<br>
<br>
Signed-off-by: Dmitry V. Levin <<a href="mailto:ldv@strace.io" target="_blank">ldv@strace.io</a>><br>
Tested-by: Charlie Jenkins <<a href="mailto:charlie@rivosinc.com" target="_blank">charlie@rivosinc.com</a>><br>
Reviewed-by: Charlie Jenkins <<a href="mailto:charlie@rivosinc.com" target="_blank">charlie@rivosinc.com</a>><br>
Acked-by: Helge Deller <<a href="mailto:deller@gmx.de" target="_blank">deller@gmx.de</a>> # parisc<br>
---<br>
arch/arc/include/asm/syscall.h | 11 +++++++++++<br>
arch/arm/include/asm/syscall.h | 24 ++++++++++++++++++++++++<br>
arch/arm64/include/asm/syscall.h | 16 ++++++++++++++++<br>
arch/hexagon/include/asm/syscall.h | 7 +++++++<br>
arch/loongarch/include/asm/syscall.h | 7 +++++++<br>
arch/m68k/include/asm/syscall.h | 7 +++++++<br>
arch/microblaze/include/asm/syscall.h | 7 +++++++<br>
arch/mips/include/asm/syscall.h | 14 ++++++++++++++<br>
arch/nios2/include/asm/syscall.h | 5 +++++<br>
arch/openrisc/include/asm/syscall.h | 6 ++++++<br>
arch/parisc/include/asm/syscall.h | 7 +++++++<br>
arch/powerpc/include/asm/syscall.h | 10 ++++++++++<br>
arch/riscv/include/asm/syscall.h | 7 +++++++<br>
arch/s390/include/asm/syscall.h | 12 ++++++++++++<br>
arch/sh/include/asm/syscall_32.h | 12 ++++++++++++<br>
arch/sparc/include/asm/syscall.h | 12 ++++++++++++<br>
arch/um/include/asm/syscall-generic.h | 5 +++++<br>
arch/x86/include/asm/syscall.h | 7 +++++++<br>
arch/xtensa/include/asm/syscall.h | 7 +++++++<br>
include/asm-generic/syscall.h | 14 ++++++++++++++<br>
20 files changed, 197 insertions(+)<br>
<br>
diff --git a/arch/arc/include/asm/syscall.h b/arch/arc/include/asm/syscall.h<br>
index 89c1e1736356..728d625a10f1 100644<br>
--- a/arch/arc/include/asm/syscall.h<br>
+++ b/arch/arc/include/asm/syscall.h<br>
@@ -23,6 +23,17 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return -1;<br>
}<br>
<br>
+static inline void<br>
+syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)<br>
+{<br>
+ /*<br>
+ * Unlike syscall_get_nr(), syscall_set_nr() can be called only when<br>
+ * the target task is stopped for tracing on entering syscall, so<br>
+ * there is no need to have the same check syscall_get_nr() has.<br>
+ */<br>
+ regs->r8 = nr;<br>
+}<br>
+<br>
static inline void<br>
syscall_rollback(struct task_struct *task, struct pt_regs *regs)<br>
{<br>
diff --git a/arch/arm/include/asm/syscall.h b/arch/arm/include/asm/syscall.h<br>
index 21927fa0ae2b..18b102a30741 100644<br>
--- a/arch/arm/include/asm/syscall.h<br>
+++ b/arch/arm/include/asm/syscall.h<br>
@@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task,<br>
regs->ARM_r0 = (long) error ? error : val;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ if (nr == -1) {<br>
+ task_thread_info(task)->abi_syscall = -1;<br>
+ /*<br>
+ * When the syscall number is set to -1, the syscall will be<br>
+ * skipped. In this case the syscall return value has to be<br>
+ * set explicitly, otherwise the first syscall argument is<br>
+ * returned as the syscall return value.<br>
+ */<br>
+ syscall_set_return_value(task, regs, -ENOSYS, 0);<br>
+ return;<br>
+ }<br>
+ if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) {<br>
+ task_thread_info(task)->abi_syscall = nr;<br>
+ return;<br>
+ }<br>
+ task_thread_info(task)->abi_syscall =<br>
+ (task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) |<br>
+ (nr & __NR_SYSCALL_MASK);<br>
+}<br>
+<br>
#define SYSCALL_MAX_ARGS 7<br>
<br>
static inline void syscall_get_arguments(struct task_struct *task,<br>
diff --git a/arch/arm64/include/asm/syscall.h b/arch/arm64/include/asm/syscall.h<br>
index 76020b66286b..712daa90e643 100644<br>
--- a/arch/arm64/include/asm/syscall.h<br>
+++ b/arch/arm64/include/asm/syscall.h<br>
@@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task,<br>
regs->regs[0] = val;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->syscallno = nr;<br>
+ if (nr == -1) {<br>
+ /*<br>
+ * When the syscall number is set to -1, the syscall will be<br>
+ * skipped. In this case the syscall return value has to be<br>
+ * set explicitly, otherwise the first syscall argument is<br>
+ * returned as the syscall return value.<br>
+ */<br>
+ syscall_set_return_value(task, regs, -ENOSYS, 0);<br>
+ }<br>
+}<br>
+<br>
#define SYSCALL_MAX_ARGS 6<br>
<br>
static inline void syscall_get_arguments(struct task_struct *task,<br>
diff --git a/arch/hexagon/include/asm/syscall.h b/arch/hexagon/include/asm/syscall.h<br>
index 1024a6548d78..70637261817a 100644<br>
--- a/arch/hexagon/include/asm/syscall.h<br>
+++ b/arch/hexagon/include/asm/syscall.h<br>
@@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return regs->r06;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->r06 = nr;<br>
+}<br>
+<br>
static inline void syscall_get_arguments(struct task_struct *task,<br>
struct pt_regs *regs,<br>
unsigned long *args)<br>
diff --git a/arch/loongarch/include/asm/syscall.h b/arch/loongarch/include/asm/syscall.h<br>
index ff415b3c0a8e..81d2733f7b94 100644<br>
--- a/arch/loongarch/include/asm/syscall.h<br>
+++ b/arch/loongarch/include/asm/syscall.h<br>
@@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return regs->regs[11];<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->regs[11] = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/m68k/include/asm/syscall.h b/arch/m68k/include/asm/syscall.h<br>
index d1453e850cdd..bf84b160c2eb 100644<br>
--- a/arch/m68k/include/asm/syscall.h<br>
+++ b/arch/m68k/include/asm/syscall.h<br>
@@ -14,6 +14,13 @@ static inline int syscall_get_nr(struct task_struct *task,<br>
return regs->orig_d0;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->orig_d0 = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/microblaze/include/asm/syscall.h b/arch/microblaze/include/asm/syscall.h<br>
index 5eb3f624cc59..b5b6b91fae3e 100644<br>
--- a/arch/microblaze/include/asm/syscall.h<br>
+++ b/arch/microblaze/include/asm/syscall.h<br>
@@ -14,6 +14,13 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return regs->r12;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->r12 = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h<br>
index 2dcc1d01b405..1cd25306cc13 100644<br>
--- a/arch/mips/include/asm/syscall.h<br>
+++ b/arch/mips/include/asm/syscall.h<br>
@@ -41,6 +41,20 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return task_thread_info(task)->syscall;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ /*<br>
+ * New syscall number has to be assigned to regs[2] because<br>
+ * syscall_trace_entry() loads it from there unconditionally.<br>
+ *<br>
+ * Consequently, if the syscall was indirect and nr != __NR_syscall,<br>
+ * then after this assignment the syscall will cease to be indirect.<br>
+ */<br>
+ task_thread_info(task)->syscall = regs->regs[2] = nr;<br>
+}<br>
+<br>
static inline void mips_syscall_update_nr(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/nios2/include/asm/syscall.h b/arch/nios2/include/asm/syscall.h<br>
index 526449edd768..8e3eb1d689bb 100644<br>
--- a/arch/nios2/include/asm/syscall.h<br>
+++ b/arch/nios2/include/asm/syscall.h<br>
@@ -15,6 +15,11 @@ static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return regs->r2;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)<br>
+{<br>
+ regs->r2 = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/openrisc/include/asm/syscall.h b/arch/openrisc/include/asm/syscall.h<br>
index e6383be2a195..5e037d9659c5 100644<br>
--- a/arch/openrisc/include/asm/syscall.h<br>
+++ b/arch/openrisc/include/asm/syscall.h<br>
@@ -25,6 +25,12 @@ syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return regs->orig_gpr11;<br>
}<br>
<br>
+static inline void<br>
+syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)<br>
+{<br>
+ regs->orig_gpr11 = nr;<br>
+}<br>
+<br>
static inline void<br>
syscall_rollback(struct task_struct *task, struct pt_regs *regs)<br>
{<br>
diff --git a/arch/parisc/include/asm/syscall.h b/arch/parisc/include/asm/syscall.h<br>
index b146d0ae4c77..c11222798ab2 100644<br>
--- a/arch/parisc/include/asm/syscall.h<br>
+++ b/arch/parisc/include/asm/syscall.h<br>
@@ -17,6 +17,13 @@ static inline long syscall_get_nr(struct task_struct *tsk,<br>
return regs->gr[20];<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *tsk,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->gr[20] = nr;<br>
+}<br>
+<br>
static inline void syscall_get_arguments(struct task_struct *tsk,<br>
struct pt_regs *regs,<br>
unsigned long *args)<br>
diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h<br>
index 521f279e6b33..7505dcfed247 100644<br>
--- a/arch/powerpc/include/asm/syscall.h<br>
+++ b/arch/powerpc/include/asm/syscall.h<br>
@@ -39,6 +39,16 @@ static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return -1;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)<br>
+{<br>
+ /*<br>
+ * Unlike syscall_get_nr(), syscall_set_nr() can be called only when<br>
+ * the target task is stopped for tracing on entering syscall, so<br>
+ * there is no need to have the same check syscall_get_nr() has.<br>
+ */<br>
+ regs->gpr[0] = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h<br>
index 8d389ba995c8..a5281cdf2b10 100644<br>
--- a/arch/riscv/include/asm/syscall.h<br>
+++ b/arch/riscv/include/asm/syscall.h<br>
@@ -30,6 +30,13 @@ static inline int syscall_get_nr(struct task_struct *task,<br>
return regs->a7;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->a7 = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h<br>
index 0e3296a32e6a..db6ca55564ff 100644<br>
--- a/arch/s390/include/asm/syscall.h<br>
+++ b/arch/s390/include/asm/syscall.h<br>
@@ -24,6 +24,18 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
(regs->int_code & 0xffff) : -1;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ /*<br>
+ * Unlike syscall_get_nr(), syscall_set_nr() can be called only when<br>
+ * the target task is stopped for tracing on entering syscall, so<br>
+ * there is no need to have the same check syscall_get_nr() has.<br>
+ */<br>
+ regs->int_code = (regs->int_code & ~0xffff) | (nr & 0xffff);<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/sh/include/asm/syscall_32.h b/arch/sh/include/asm/syscall_32.h<br>
index cb51a7528384..7027d87d901d 100644<br>
--- a/arch/sh/include/asm/syscall_32.h<br>
+++ b/arch/sh/include/asm/syscall_32.h<br>
@@ -15,6 +15,18 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return (regs->tra >= 0) ? regs->regs[3] : -1L;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ /*<br>
+ * Unlike syscall_get_nr(), syscall_set_nr() can be called only when<br>
+ * the target task is stopped for tracing on entering syscall, so<br>
+ * there is no need to have the same check syscall_get_nr() has.<br>
+ */<br>
+ regs->regs[3] = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/sparc/include/asm/syscall.h b/arch/sparc/include/asm/syscall.h<br>
index 62a5a78804c4..b0233924d323 100644<br>
--- a/arch/sparc/include/asm/syscall.h<br>
+++ b/arch/sparc/include/asm/syscall.h<br>
@@ -25,6 +25,18 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return (syscall_p ? regs->u_regs[UREG_G1] : -1L);<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ /*<br>
+ * Unlike syscall_get_nr(), syscall_set_nr() can be called only when<br>
+ * the target task is stopped for tracing on entering syscall, so<br>
+ * there is no need to have the same check syscall_get_nr() has.<br>
+ */<br>
+ regs->u_regs[UREG_G1] = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/um/include/asm/syscall-generic.h b/arch/um/include/asm/syscall-generic.h<br>
index 2984feb9d576..bcd73bcfe577 100644<br>
--- a/arch/um/include/asm/syscall-generic.h<br>
+++ b/arch/um/include/asm/syscall-generic.h<br>
@@ -21,6 +21,11 @@ static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return PT_REGS_SYSCALL_NR(regs);<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)<br>
+{<br>
+ PT_REGS_SYSCALL_NR(regs) = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/x86/include/asm/syscall.h b/arch/x86/include/asm/syscall.h<br>
index b9c249dd9e3d..c10dbb74cd00 100644<br>
--- a/arch/x86/include/asm/syscall.h<br>
+++ b/arch/x86/include/asm/syscall.h<br>
@@ -38,6 +38,13 @@ static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)<br>
return regs->orig_ax;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->orig_ax = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/arch/xtensa/include/asm/syscall.h b/arch/xtensa/include/asm/syscall.h<br>
index f9a671cbf933..7db3b489c8ad 100644<br>
--- a/arch/xtensa/include/asm/syscall.h<br>
+++ b/arch/xtensa/include/asm/syscall.h<br>
@@ -28,6 +28,13 @@ static inline long syscall_get_nr(struct task_struct *task,<br>
return regs->syscall;<br>
}<br>
<br>
+static inline void syscall_set_nr(struct task_struct *task,<br>
+ struct pt_regs *regs,<br>
+ int nr)<br>
+{<br>
+ regs->syscall = nr;<br>
+}<br>
+<br>
static inline void syscall_rollback(struct task_struct *task,<br>
struct pt_regs *regs)<br>
{<br>
diff --git a/include/asm-generic/syscall.h b/include/asm-generic/syscall.h<br>
index 292b412f4e9a..c5a3ad53beec 100644<br>
--- a/include/asm-generic/syscall.h<br>
+++ b/include/asm-generic/syscall.h<br>
@@ -37,6 +37,20 @@ struct pt_regs;<br>
*/<br>
int syscall_get_nr(struct task_struct *task, struct pt_regs *regs);<br>
<br>
+/**<br>
+ * syscall_set_nr - change the system call a task is executing<br>
+ * @task: task of interest, must be blocked<br>
+ * @regs: task_pt_regs() of @task<br>
+ * @nr: system call number<br>
+ *<br>
+ * Changes the system call number @task is about to execute.<br>
+ *<br>
+ * It's only valid to call this when @task is stopped for tracing on<br>
+ * entry to a system call, due to %SYSCALL_WORK_SYSCALL_TRACE or<br>
+ * %SYSCALL_WORK_SYSCALL_AUDIT.<br>
+ */<br>
+void syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr);<br>
+<br>
/**<br>
* syscall_rollback - roll back registers after an aborted system call<br>
* @task: task of interest, must be in system call exit tracing<br>
-- <br>
ldv<br>
-- <br>
Strace-devel mailing list<br>
<a href="mailto:Strace-devel@lists.strace.io" target="_blank">Strace-devel@lists.strace.io</a><br>
<a href="https://lists.strace.io/mailman/listinfo/strace-devel" rel="noreferrer" target="_blank">https://lists.strace.io/mailman/listinfo/strace-devel</a><br>
</blockquote></div></div>