Re: [PATCH v2 3/7] syscall.h: add syscall_set_arguments() and syscall_set_return_value()

2025-01-15 Thread Charlie Jenkins
/include/asm/syscall.h
> index fff52205fb65..526449edd768 100644
> --- a/arch/nios2/include/asm/syscall.h
> +++ b/arch/nios2/include/asm/syscall.h
> @@ -58,6 +58,17 @@ static inline void syscall_get_arguments(struct 
> task_struct *task,
>   *args   = regs->r9;
>  }
>  
> +static inline void syscall_set_arguments(struct task_struct *task,
> + struct pt_regs *regs, const unsigned long *args)
> +{
> + regs->r4 = *args++;
> + regs->r5 = *args++;
> + regs->r6 = *args++;
> + regs->r7 = *args++;
> + regs->r8 = *args++;
> + regs->r9 = *args;
> +}
> +
>  static inline int syscall_get_arch(struct task_struct *task)
>  {
>   return AUDIT_ARCH_NIOS2;
> diff --git a/arch/openrisc/include/asm/syscall.h 
> b/arch/openrisc/include/asm/syscall.h
> index 903ed882bdec..e6383be2a195 100644
> --- a/arch/openrisc/include/asm/syscall.h
> +++ b/arch/openrisc/include/asm/syscall.h
> @@ -57,6 +57,13 @@ syscall_get_arguments(struct task_struct *task, struct 
> pt_regs *regs,
>   memcpy(args, ®s->gpr[3], 6 * sizeof(args[0]));
>  }
>  
> +static inline void
> +syscall_set_arguments(struct task_struct *task, struct pt_regs *regs,
> +   const unsigned long *args)
> +{
> + memcpy(®s->gpr[3], args, 6 * sizeof(args[0]));
> +}
> +
>  static inline int syscall_get_arch(struct task_struct *task)
>  {
>   return AUDIT_ARCH_OPENRISC;
> diff --git a/arch/parisc/include/asm/syscall.h 
> b/arch/parisc/include/asm/syscall.h
> index 00b127a5e09b..b146d0ae4c77 100644
> --- a/arch/parisc/include/asm/syscall.h
> +++ b/arch/parisc/include/asm/syscall.h
> @@ -29,6 +29,18 @@ static inline void syscall_get_arguments(struct 
> task_struct *tsk,
>   args[0] = regs->gr[26];
>  }
>  
> +static inline void syscall_set_arguments(struct task_struct *tsk,
> +  struct pt_regs *regs,
> +  unsigned long *args)
> +{
> + regs->gr[21] = args[5];
> + regs->gr[22] = args[4];
> + regs->gr[23] = args[3];
> + regs->gr[24] = args[2];
> + regs->gr[25] = args[1];
> + regs->gr[26] = args[0];
> +}
> +
>  static inline long syscall_get_error(struct task_struct *task,
>struct pt_regs *regs)
>  {
> diff --git a/arch/powerpc/include/asm/syscall.h 
> b/arch/powerpc/include/asm/syscall.h
> index 422d7735ace6..521f279e6b33 100644
> --- a/arch/powerpc/include/asm/syscall.h
> +++ b/arch/powerpc/include/asm/syscall.h
> @@ -114,6 +114,16 @@ static inline void syscall_get_arguments(struct 
> task_struct *task,
>   }
>  }
>  
> +static inline void syscall_set_arguments(struct task_struct *task,
> +          struct pt_regs *regs,
> +  const unsigned long *args)
> +{
> + memcpy(®s->gpr[3], args, 6 * sizeof(args[0]));
> +
> + /* Also copy the first argument into orig_gpr3 */
> + regs->orig_gpr3 = args[0];
> +}
> +
>  static inline int syscall_get_arch(struct task_struct *task)
>  {
>   if (is_tsk_32bit_task(task))
> diff --git a/arch/riscv/include/asm/syscall.h 
> b/arch/riscv/include/asm/syscall.h
> index 121fff429dce..8d389ba995c8 100644
> --- a/arch/riscv/include/asm/syscall.h
> +++ b/arch/riscv/include/asm/syscall.h
> @@ -66,6 +66,15 @@ static inline void syscall_get_arguments(struct 
> task_struct *task,
>   memcpy(args, ®s->a1, 5 * sizeof(args[0]));
>  }
>  
> +static inline void syscall_set_arguments(struct task_struct *task,
> +  struct pt_regs *regs,
> +  const unsigned long *args)
> +{
> + regs->orig_a0 = args[0];
> + args++;
> + memcpy(®s->a1, args, 5 * sizeof(regs->a1));
> +}

Looks good for riscv.

Tested-by: Charlie Jenkins 
Reviewed-by: Charlie Jenkins  +
>  static inline int syscall_get_arch(struct task_struct *task)
>  {
>  #ifdef CONFIG_64BIT
> diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
> index 27e3d804b311..b3dd883699e7 100644
> --- a/arch/s390/include/asm/syscall.h
> +++ b/arch/s390/include/asm/syscall.h
> @@ -78,6 +78,18 @@ static inline void syscall_get_arguments(struct 
> task_struct *task,
>   args[0] = regs->orig_gpr2 & mask;
>  }
>  
> +static inline void syscall_set_arguments(struct task_struct *task,
> +  struct pt_regs *regs,
> +  const unsigned long *args)
> +{
> + unsigned int n = 6;
> +
> + while (n-- > 0)
> + 

Re: [PATCH v2 4/7] syscall.h: introduce syscall_set_nr()

2025-01-15 Thread Charlie Jenkins
gt;  static inline void syscall_rollback(struct task_struct *task,
>   struct pt_regs *regs)
>  {
> diff --git a/arch/openrisc/include/asm/syscall.h 
> b/arch/openrisc/include/asm/syscall.h
> index e6383be2a195..5e037d9659c5 100644
> --- a/arch/openrisc/include/asm/syscall.h
> +++ b/arch/openrisc/include/asm/syscall.h
> @@ -25,6 +25,12 @@ syscall_get_nr(struct task_struct *task, struct pt_regs 
> *regs)
>   return regs->orig_gpr11;
>  }
>  
> +static inline void
> +syscall_set_nr(struct task_struct *task, struct pt_regs *regs, int nr)
> +{
> + regs->orig_gpr11 = nr;
> +}
> +
>  static inline void
>  syscall_rollback(struct task_struct *task, struct pt_regs *regs)
>  {
> diff --git a/arch/parisc/include/asm/syscall.h 
> b/arch/parisc/include/asm/syscall.h
> index b146d0ae4c77..c11222798ab2 100644
> --- a/arch/parisc/include/asm/syscall.h
> +++ b/arch/parisc/include/asm/syscall.h
> @@ -17,6 +17,13 @@ static inline long syscall_get_nr(struct task_struct *tsk,
>   return regs->gr[20];
>  }
>  
> +static inline void syscall_set_nr(struct task_struct *tsk,
> +   struct pt_regs *regs,
> +   int nr)
> +{
> + regs->gr[20] = nr;
> +}
> +
>  static inline void syscall_get_arguments(struct task_struct *tsk,
>struct pt_regs *regs,
>unsigned long *args)
> diff --git a/arch/powerpc/include/asm/syscall.h 
> b/arch/powerpc/include/asm/syscall.h
> index 521f279e6b33..7505dcfed247 100644
> --- a/arch/powerpc/include/asm/syscall.h
> +++ b/arch/powerpc/include/asm/syscall.h
> @@ -39,6 +39,16 @@ static inline int syscall_get_nr(struct task_struct *task, 
> struct pt_regs *regs)
>   return -1;
>  }
>  
> +static inline void syscall_set_nr(struct task_struct *task, struct pt_regs 
> *regs, int nr)
> +{
> + /*
> +  * Unlike syscall_get_nr(), syscall_set_nr() can be called only when
> +  * the target task is stopped for tracing on entering syscall, so
> +  * there is no need to have the same check syscall_get_nr() has.
> +  */
> + regs->gpr[0] = nr;
> +}
> +
>  static inline void syscall_rollback(struct task_struct *task,
>   struct pt_regs *regs)
>  {
> diff --git a/arch/riscv/include/asm/syscall.h 
> b/arch/riscv/include/asm/syscall.h
> index 8d389ba995c8..a5281cdf2b10 100644
> --- a/arch/riscv/include/asm/syscall.h
> +++ b/arch/riscv/include/asm/syscall.h
> @@ -30,6 +30,13 @@ static inline int syscall_get_nr(struct task_struct *task,
>   return regs->a7;
>  }
>  
> +static inline void syscall_set_nr(struct task_struct *task,
> +   struct pt_regs *regs,
> +   int nr)
> +{
> + regs->a7 = nr;
> +}

Looks good for riscv.

Tested-by: Charlie Jenkins 
Reviewed-by: Charlie Jenkins 

> +
>  static inline void syscall_rollback(struct task_struct *task,
>   struct pt_regs *regs)
>  {
> diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
> index b3dd883699e7..12cd0c60c07b 100644
> --- a/arch/s390/include/asm/syscall.h
> +++ b/arch/s390/include/asm/syscall.h
> @@ -24,6 +24,18 @@ static inline long syscall_get_nr(struct task_struct *task,
>   (regs->int_code & 0x) : -1;
>  }
>  
> +static inline void syscall_set_nr(struct task_struct *task,
> +   struct pt_regs *regs,
> +   int nr)
> +{
> + /*
> +  * Unlike syscall_get_nr(), syscall_set_nr() can be called only when
> +  * the target task is stopped for tracing on entering syscall, so
> +  * there is no need to have the same check syscall_get_nr() has.
> +  */
> + regs->int_code = (regs->int_code & ~0x) | (nr & 0x);
> +}
> +
>  static inline void syscall_rollback(struct task_struct *task,
>   struct pt_regs *regs)
>  {
> diff --git a/arch/sh/include/asm/syscall_32.h 
> b/arch/sh/include/asm/syscall_32.h
> index cb51a7528384..7027d87d901d 100644
> --- a/arch/sh/include/asm/syscall_32.h
> +++ b/arch/sh/include/asm/syscall_32.h
> @@ -15,6 +15,18 @@ static inline long syscall_get_nr(struct task_struct *task,
>   return (regs->tra >= 0) ? regs->regs[3] : -1L;
>  }
>  
> +static inline void syscall_set_nr(struct task_struct *task,
> +   struct pt_regs *regs,
> +   int nr)
> +{
> + /*
> +  * Unlike syscall_get_nr(), syscall_set_nr(