Commit | Line | Data |
---|---|---|
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 | |
0f78ff17 | 19 | typedef long (*sys_call_ptr_t)(const struct pt_regs *); |
1599e8fc | 20 | extern const sys_call_ptr_t sys_call_table[]; |
e7b8e675 | 21 | |
034042cc AL |
22 | #if defined(CONFIG_X86_32) |
23 | #define ia32_sys_call_table sys_call_table | |
dce0aa3b PAI |
24 | #else |
25 | /* | |
26 | * These may not exist, but still put the prototypes in so we | |
27 | * can use IS_ENABLED(). | |
28 | */ | |
034042cc | 29 | extern const sys_call_ptr_t ia32_sys_call_table[]; |
6365b842 AL |
30 | extern const sys_call_ptr_t x32_sys_call_table[]; |
31 | #endif | |
32 | ||
18c1e2c8 RM |
33 | /* |
34 | * Only the low 32 bits of orig_ax are meaningful, so we return int. | |
35 | * This importantly ignores the high bits on 64-bit, so comparisons | |
36 | * sign-extend the low 32 bits. | |
37 | */ | |
38 | static inline int syscall_get_nr(struct task_struct *task, struct pt_regs *regs) | |
68bd0f4e | 39 | { |
8b4b9f27 | 40 | return regs->orig_ax; |
68bd0f4e RM |
41 | } |
42 | ||
43 | static inline void syscall_rollback(struct task_struct *task, | |
44 | struct pt_regs *regs) | |
45 | { | |
8b4b9f27 | 46 | regs->ax = regs->orig_ax; |
68bd0f4e RM |
47 | } |
48 | ||
49 | static inline long syscall_get_error(struct task_struct *task, | |
50 | struct pt_regs *regs) | |
51 | { | |
52 | unsigned long error = regs->ax; | |
53 | #ifdef CONFIG_IA32_EMULATION | |
54 | /* | |
55 | * TS_COMPAT is set for 32-bit syscall entries and then | |
56 | * remains set until we return to user mode. | |
57 | */ | |
37a8f7c3 | 58 | if (task->thread_info.status & (TS_COMPAT|TS_I386_REGS_POKED)) |
68bd0f4e RM |
59 | /* |
60 | * Sign-extend the value so (int)-EFOO becomes (long)-EFOO | |
61 | * and will match correctly in comparisons. | |
62 | */ | |
63 | error = (long) (int) error; | |
64 | #endif | |
4ab4ba32 | 65 | return IS_ERR_VALUE(error) ? error : 0; |
68bd0f4e RM |
66 | } |
67 | ||
68 | static inline long syscall_get_return_value(struct task_struct *task, | |
69 | struct pt_regs *regs) | |
70 | { | |
71 | return regs->ax; | |
72 | } | |
73 | ||
74 | static inline void syscall_set_return_value(struct task_struct *task, | |
75 | struct pt_regs *regs, | |
76 | int error, long val) | |
77 | { | |
78 | regs->ax = (long) error ?: val; | |
79 | } | |
80 | ||
81 | #ifdef CONFIG_X86_32 | |
82 | ||
83 | static inline void syscall_get_arguments(struct task_struct *task, | |
84 | struct pt_regs *regs, | |
68bd0f4e RM |
85 | unsigned long *args) |
86 | { | |
b35f549d | 87 | memcpy(args, ®s->bx, 6 * sizeof(args[0])); |
68bd0f4e RM |
88 | } |
89 | ||
16add411 | 90 | static inline int syscall_get_arch(struct task_struct *task) |
b7456536 WD |
91 | { |
92 | return AUDIT_ARCH_I386; | |
93 | } | |
94 | ||
68bd0f4e RM |
95 | #else /* CONFIG_X86_64 */ |
96 | ||
97 | static inline void syscall_get_arguments(struct task_struct *task, | |
98 | struct pt_regs *regs, | |
68bd0f4e RM |
99 | unsigned long *args) |
100 | { | |
101 | # ifdef CONFIG_IA32_EMULATION | |
b35f549d SRRH |
102 | if (task->thread_info.status & TS_COMPAT) { |
103 | *args++ = regs->bx; | |
104 | *args++ = regs->cx; | |
105 | *args++ = regs->dx; | |
106 | *args++ = regs->si; | |
107 | *args++ = regs->di; | |
108 | *args = regs->bp; | |
109 | } else | |
68bd0f4e | 110 | # endif |
b35f549d SRRH |
111 | { |
112 | *args++ = regs->di; | |
113 | *args++ = regs->si; | |
114 | *args++ = regs->dx; | |
115 | *args++ = regs->r10; | |
116 | *args++ = regs->r8; | |
117 | *args = regs->r9; | |
118 | } | |
68bd0f4e RM |
119 | } |
120 | ||
16add411 | 121 | static inline int syscall_get_arch(struct task_struct *task) |
b7456536 | 122 | { |
b9d989c7 | 123 | /* x32 tasks should be considered AUDIT_ARCH_X86_64. */ |
16add411 DL |
124 | return (IS_ENABLED(CONFIG_IA32_EMULATION) && |
125 | task->thread_info.status & TS_COMPAT) | |
126 | ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64; | |
b7456536 | 127 | } |
99ce3255 | 128 | |
ca282b48 | 129 | bool do_syscall_64(struct pt_regs *regs, int nr); |
99ce3255 | 130 | |
68bd0f4e RM |
131 | #endif /* CONFIG_X86_32 */ |
132 | ||
f34f0d3c | 133 | void do_int80_syscall_32(struct pt_regs *regs); |
0d3109ad BG |
134 | bool do_fast_syscall_32(struct pt_regs *regs); |
135 | bool do_SYSENTER_32(struct pt_regs *regs); | |
f34f0d3c | 136 | |
5e1b0075 | 137 | #endif /* _ASM_X86_SYSCALL_H */ |