Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-block.git] / arch / x86 / include / asm / syscall.h
CommitLineData
2522fe45 1/* SPDX-License-Identifier: GPL-2.0-only */
68bd0f4e
RM
2/*
3 * Access to user system call parameters and results
4 *
18c1e2c8 5 * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
68bd0f4e 6 *
68bd0f4e
RM
7 * See asm-generic/syscall.h for descriptions of what we must do here.
8 */
9
5e1b0075
PA
10#ifndef _ASM_X86_SYSCALL_H
11#define _ASM_X86_SYSCALL_H
68bd0f4e 12
579ec9e1 13#include <uapi/linux/audit.h>
68bd0f4e 14#include <linux/sched.h>
4ab4ba32 15#include <linux/err.h>
b7456536 16#include <asm/thread_info.h> /* for TS_COMPAT */
fca460f9 17#include <asm/unistd.h>
68bd0f4e 18
1e3ad783 19/* This is used purely for kernel/trace/trace_syscalls.c */
0f78ff17 20typedef long (*sys_call_ptr_t)(const struct pt_regs *);
1599e8fc 21extern const sys_call_ptr_t sys_call_table[];
e7b8e675 22
dce0aa3b
PAI
23/*
24 * These may not exist, but still put the prototypes in so we
25 * can use IS_ENABLED().
26 */
1e3ad783
LT
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);
6365b842 30
18c1e2c8
RM
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)
68bd0f4e 37{
8b4b9f27 38 return regs->orig_ax;
68bd0f4e
RM
39}
40
cc662273
DL
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
68bd0f4e
RM
48static inline void syscall_rollback(struct task_struct *task,
49 struct pt_regs *regs)
50{
8b4b9f27 51 regs->ax = regs->orig_ax;
68bd0f4e
RM
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 */
37a8f7c3 63 if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED))
68bd0f4e
RM
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
4ab4ba32 70 return IS_ERR_VALUE(error) ? error : 0;
68bd0f4e
RM
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,
68bd0f4e
RM
90 unsigned long *args)
91{
d19d638b
KC
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;
68bd0f4e
RM
98}
99
17fc7b8f
DL
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
16add411 112static inline int syscall_get_arch(struct task_struct *task)
b7456536
WD
113{
114 return AUDIT_ARCH_I386;
115}
116
68bd0f4e
RM
117#else /* CONFIG_X86_64 */
118
119static inline void syscall_get_arguments(struct task_struct *task,
120 struct pt_regs *regs,
68bd0f4e
RM
121 unsigned long *args)
122{
123# ifdef CONFIG_IA32_EMULATION
b35f549d
SRRH
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
68bd0f4e 132# endif
b35f549d
SRRH
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 }
68bd0f4e
RM
141}
142
17fc7b8f
DL
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
16add411 167static inline int syscall_get_arch(struct task_struct *task)
b7456536 168{
b9d989c7 169 /* x32 tasks should be considered AUDIT_ARCH_X86_64. */
16add411
DL
170 return (IS_ENABLED(CONFIG_IA32_EMULATION) &&
171 task->thread_info.status & TS_COMPAT)
172 ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
b7456536 173}
99ce3255 174
ca282b48 175bool do_syscall_64(struct pt_regs *regs, int nr);
7390db8a 176void do_int80_emulation(struct pt_regs *regs);
99ce3255 177
68bd0f4e
RM
178#endif /* CONFIG_X86_32 */
179
f34f0d3c 180void do_int80_syscall_32(struct pt_regs *regs);
0d3109ad
BG
181bool do_fast_syscall_32(struct pt_regs *regs);
182bool do_SYSENTER_32(struct pt_regs *regs);
f34f0d3c 183
5e1b0075 184#endif /* _ASM_X86_SYSCALL_H */