Commit cc662273 authored by Dmitry V. Levin's avatar Dmitry V. Levin Committed by Andrew Morton
Browse files

syscall.h: introduce syscall_set_nr()

Similar to syscall_set_arguments() that complements
syscall_get_arguments(), introduce syscall_set_nr() that complements
syscall_get_nr().

syscall_set_nr() is going to be needed along with syscall_set_arguments()
on all HAVE_ARCH_TRACEHOOK architectures to implement
PTRACE_SET_SYSCALL_INFO API.

Link: https://lkml.kernel.org/r/20250303112020.GD24170@strace.io


Signed-off-by: default avatarDmitry V. Levin <ldv@strace.io>
Tested-by: default avatarCharlie Jenkins <charlie@rivosinc.com>
Reviewed-by: default avatarCharlie Jenkins <charlie@rivosinc.com>
Acked-by: Helge Deller <deller@gmx.de> # parisc
Reviewed-by: Maciej W. Rozycki <macro@orcam.me.uk> # mips
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexey Gladkov (Intel) <legion@kernel.org>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: anton ivanov <anton.ivanov@cambridgegreys.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Brian Cain <bcain@quicinc.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Zankel <chris@zankel.net>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Davide Berardi <berardi.dav@gmail.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@kernel.org>
Cc: Eugene Syromiatnikov <esyr@redhat.com>
Cc: Eugene Syromyatnikov <evgsyr@gmail.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Guo Ren <guoren@kernel.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Huacai Chen <chenhuacai@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Johannes Berg <johannes@sipsolutions.net>
Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: Jonas Bonn <jonas@southpole.se>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Max Filippov <jcmvbkbc@gmail.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Simek <monstr@monstr.eu>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Naveen N Rao <naveen@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Renzo Davoi <renzo@cs.unibo.it>
Cc: Richard Weinberger <richard@nod.at>
Cc: Rich Felker <dalias@libc.org>
Cc: Russel King <linux@armlinux.org.uk>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Stafford Horne <shorne@gmail.com>
Cc: Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vineet Gupta <vgupta@kernel.org>
Cc: WANG Xuerui <kernel@xen0n.name>
Cc: Will Deacon <will@kernel.org>
Cc: Yoshinori Sato <ysato@users.sourceforge.jp>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 17fc7b8f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -23,6 +23,17 @@ 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->r8 = nr;
}

static inline void
syscall_rollback(struct task_struct *task, struct pt_regs *regs)
{
+24 −0
Original line number Diff line number Diff line
@@ -68,6 +68,30 @@ static inline void syscall_set_return_value(struct task_struct *task,
	regs->ARM_r0 = (long) error ? error : val;
}

static inline void syscall_set_nr(struct task_struct *task,
				  struct pt_regs *regs,
				  int nr)
{
	if (nr == -1) {
		task_thread_info(task)->abi_syscall = -1;
		/*
		 * When the syscall number is set to -1, the syscall will be
		 * skipped.  In this case the syscall return value has to be
		 * set explicitly, otherwise the first syscall argument is
		 * returned as the syscall return value.
		 */
		syscall_set_return_value(task, regs, -ENOSYS, 0);
		return;
	}
	if ((IS_ENABLED(CONFIG_AEABI) && !IS_ENABLED(CONFIG_OABI_COMPAT))) {
		task_thread_info(task)->abi_syscall = nr;
		return;
	}
	task_thread_info(task)->abi_syscall =
		(task_thread_info(task)->abi_syscall & ~__NR_SYSCALL_MASK) |
		(nr & __NR_SYSCALL_MASK);
}

#define SYSCALL_MAX_ARGS 7

static inline void syscall_get_arguments(struct task_struct *task,
+16 −0
Original line number Diff line number Diff line
@@ -61,6 +61,22 @@ static inline void syscall_set_return_value(struct task_struct *task,
	regs->regs[0] = val;
}

static inline void syscall_set_nr(struct task_struct *task,
				  struct pt_regs *regs,
				  int nr)
{
	regs->syscallno = nr;
	if (nr == -1) {
		/*
		 * When the syscall number is set to -1, the syscall will be
		 * skipped.  In this case the syscall return value has to be
		 * set explicitly, otherwise the first syscall argument is
		 * returned as the syscall return value.
		 */
		syscall_set_return_value(task, regs, -ENOSYS, 0);
	}
}

#define SYSCALL_MAX_ARGS 6

static inline void syscall_get_arguments(struct task_struct *task,
+7 −0
Original line number Diff line number Diff line
@@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task,
	return regs->r06;
}

static inline void syscall_set_nr(struct task_struct *task,
				  struct pt_regs *regs,
				  int nr)
{
	regs->r06 = nr;
}

static inline void syscall_get_arguments(struct task_struct *task,
					 struct pt_regs *regs,
					 unsigned long *args)
+7 −0
Original line number Diff line number Diff line
@@ -26,6 +26,13 @@ static inline long syscall_get_nr(struct task_struct *task,
	return regs->regs[11];
}

static inline void syscall_set_nr(struct task_struct *task,
				  struct pt_regs *regs,
				  int nr)
{
	regs->regs[11] = nr;
}

static inline void syscall_rollback(struct task_struct *task,
				    struct pt_regs *regs)
{
Loading