File Index
Files and directories
Sign in
FILE

syscall.h

File preview with syntax highlighting.

linux-6.19.14/arch/x86/include/asm/syscall.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Access to user system call parameters and results
  4 *
  5 * Copyright (C) 2008-2009 Red Hat, Inc.  All rights reserved.
  6 *
  7 * See asm-generic/syscall.h for descriptions of what we must do here.
  8 */
  9
 10#ifndef _ASM_X86_SYSCALL_H
 11#define _ASM_X86_SYSCALL_H
 12
 13#include <uapi/linux/audit.h>
 14#include <linux/sched.h>
 15#include <linux/err.h>
 16#include <asm/thread_info.h>	/* for TS_COMPAT */
 17#include <asm/unistd.h>
 18
 19/* This is used purely for kernel/trace/trace_syscalls.c */
 20typedef long (*sys_call_ptr_t)(const struct pt_regs *);
 21extern const sys_call_ptr_t sys_call_table[];
 22
 23/*
 24 * These may not exist, but still put the prototypes in so we
 25 * can use IS_ENABLED().
 26 */
 27extern long ia32_sys_call(const struct pt_regs *, unsigned int nr);
 28extern long x32_sys_call(const struct pt_regs *, unsigned int nr);
 29extern long x64_sys_call(const struct pt_regs *, unsigned int nr);
 30
 31/*
 32 * Only the low 32 bits of orig_ax are meaningful, so we return int.
 33 * This importantly ignores the high bits on 64-bit, so comparisons
 34 * sign-extend the low 32 bits.
 35 */
 36static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs)
 37{
 38	return regs->orig_ax;
 39}
 40
 41static inline void syscall_set_nr(struct task_struct *task,
 42				  struct pt_regs *regs,
 43				  int nr)
 44{
 45	regs->orig_ax = nr;
 46}
 47
 48static inline void syscall_rollback(struct task_struct *task,
 49				    struct pt_regs *regs)
 50{
 51	regs->ax = regs->orig_ax;
 52}
 53
 54static inline long syscall_get_error(struct task_struct *task,
 55				     struct pt_regs *regs)
 56{
 57	unsigned long error = regs->ax;
 58#ifdef CONFIG_IA32_EMULATION
 59	/*
 60	 * TS_COMPAT is set for 32-bit syscall entries and then
 61	 * remains set until we return to user mode.
 62	 */
 63	if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
 64		/*
 65		 * Sign-extend the value so (int)-EFOO becomes (long)-EFOO
 66		 * and will match correctly in comparisons.
 67		 */
 68		error = (long) (int) error;
 69#endif
 70	return IS_ERR_VALUE(error) ? error : 0;
 71}
 72
 73static inline long syscall_get_return_value(struct task_struct *task,
 74					    struct pt_regs *regs)
 75{
 76	return regs->ax;
 77}
 78
 79static inline void syscall_set_return_value(struct task_struct *task,
 80					    struct pt_regs *regs,
 81					    int error, long val)
 82{
 83	regs->ax = (long) error ?: val;
 84}
 85
 86#ifdef CONFIG_X86_32
 87
 88static inline void syscall_get_arguments(struct task_struct *task,
 89					 struct pt_regs *regs,
 90					 unsigned long *args)
 91{
 92	args[0] = regs->bx;
 93	args[1] = regs->cx;
 94	args[2] = regs->dx;
 95	args[3] = regs->si;
 96	args[4] = regs->di;
 97	args[5] = regs->bp;
 98}
 99
100static inline void syscall_set_arguments(struct task_struct *task,
101					 struct pt_regs *regs,
102					 const unsigned long *args)
103{
104	regs->bx = args[0];
105	regs->cx = args[1];
106	regs->dx = args[2];
107	regs->si = args[3];
108	regs->di = args[4];
109	regs->bp = args[5];
110}
111
112static inline int syscall_get_arch(struct task_struct *task)
113{
114	return AUDIT_ARCH_I386;
115}
116
117#else	 /* CONFIG_X86_64 */
118
119static inline void syscall_get_arguments(struct task_struct *task,
120					 struct pt_regs *regs,
121					 unsigned long *args)
122{
123# ifdef CONFIG_IA32_EMULATION
124	if (task->thread_info.status & TS_COMPAT) {
125		*args++ = regs->bx;
126		*args++ = regs->cx;
127		*args++ = regs->dx;
128		*args++ = regs->si;
129		*args++ = regs->di;
130		*args   = regs->bp;
131	} else
132# endif
133	{
134		*args++ = regs->di;
135		*args++ = regs->si;
136		*args++ = regs->dx;
137		*args++ = regs->r10;
138		*args++ = regs->r8;
139		*args   = regs->r9;
140	}
141}
142
143static inline void syscall_set_arguments(struct task_struct *task,
144					 struct pt_regs *regs,
145					 const unsigned long *args)
146{
147# ifdef CONFIG_IA32_EMULATION
148	if (task->thread_info.status & TS_COMPAT) {
149		regs->bx = *args++;
150		regs->cx = *args++;
151		regs->dx = *args++;
152		regs->si = *args++;
153		regs->di = *args++;
154		regs->bp = *args;
155	} else
156# endif
157	{
158		regs->di = *args++;
159		regs->si = *args++;
160		regs->dx = *args++;
161		regs->r10 = *args++;
162		regs->r8 = *args++;
163		regs->r9 = *args;
164	}
165}
166
167static inline int syscall_get_arch(struct task_struct *task)
168{
169	/* x32 tasks should be considered AUDIT_ARCH_X86_64. */
170	return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
171		task->thread_info.status & TS_COMPAT)
172		? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
173}
174
175bool do_syscall_64(struct pt_regs *regs, int nr);
176void do_int80_emulation(struct pt_regs *regs);
177
178#endif	/* CONFIG_X86_32 */
179
180void do_int80_syscall_32(struct pt_regs *regs);
181bool do_fast_syscall_32(struct pt_regs *regs);
182bool do_SYSENTER_32(struct pt_regs *regs);
183
184#endif	/* _ASM_X86_SYSCALL_H */
~/ Read-only file preview.