xref: /openbmc/linux/arch/x86/include/asm/compat.h (revision 773ca67f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_COMPAT_H
3 #define _ASM_X86_COMPAT_H
4 
5 /*
6  * Architecture specific compatibility types
7  */
8 #include <linux/types.h>
9 #include <linux/sched.h>
10 #include <linux/sched/task_stack.h>
11 #include <asm/processor.h>
12 #include <asm/user32.h>
13 #include <asm/unistd.h>
14 
15 #define compat_mode_t	compat_mode_t
16 typedef u16		compat_mode_t;
17 
18 #include <asm-generic/compat.h>
19 
20 #define COMPAT_USER_HZ		100
21 #define COMPAT_UTS_MACHINE	"i686\0\0"
22 
23 typedef u16		__compat_uid_t;
24 typedef u16		__compat_gid_t;
25 typedef u16		compat_dev_t;
26 typedef u16		compat_nlink_t;
27 typedef u16		compat_ipc_pid_t;
28 typedef __kernel_fsid_t	compat_fsid_t;
29 
30 struct compat_stat {
31 	u32		st_dev;
32 	compat_ino_t	st_ino;
33 	compat_mode_t	st_mode;
34 	compat_nlink_t	st_nlink;
35 	__compat_uid_t	st_uid;
36 	__compat_gid_t	st_gid;
37 	u32		st_rdev;
38 	u32		st_size;
39 	u32		st_blksize;
40 	u32		st_blocks;
41 	u32		st_atime;
42 	u32		st_atime_nsec;
43 	u32		st_mtime;
44 	u32		st_mtime_nsec;
45 	u32		st_ctime;
46 	u32		st_ctime_nsec;
47 	u32		__unused4;
48 	u32		__unused5;
49 };
50 
51 struct compat_flock {
52 	short		l_type;
53 	short		l_whence;
54 	compat_off_t	l_start;
55 	compat_off_t	l_len;
56 	compat_pid_t	l_pid;
57 };
58 
59 #define F_GETLK64	12	/*  using 'struct flock64' */
60 #define F_SETLK64	13
61 #define F_SETLKW64	14
62 
63 /*
64  * IA32 uses 4 byte alignment for 64 bit quantities,
65  * so we need to pack this structure.
66  */
67 struct compat_flock64 {
68 	short		l_type;
69 	short		l_whence;
70 	compat_loff_t	l_start;
71 	compat_loff_t	l_len;
72 	compat_pid_t	l_pid;
73 } __attribute__((packed));
74 
75 struct compat_statfs {
76 	int		f_type;
77 	int		f_bsize;
78 	int		f_blocks;
79 	int		f_bfree;
80 	int		f_bavail;
81 	int		f_files;
82 	int		f_ffree;
83 	compat_fsid_t	f_fsid;
84 	int		f_namelen;	/* SunOS ignores this field. */
85 	int		f_frsize;
86 	int		f_flags;
87 	int		f_spare[4];
88 };
89 
90 #define COMPAT_RLIM_INFINITY		0xffffffff
91 
92 #define COMPAT_OFF_T_MAX	0x7fffffff
93 
94 struct compat_ipc64_perm {
95 	compat_key_t key;
96 	__compat_uid32_t uid;
97 	__compat_gid32_t gid;
98 	__compat_uid32_t cuid;
99 	__compat_gid32_t cgid;
100 	unsigned short mode;
101 	unsigned short __pad1;
102 	unsigned short seq;
103 	unsigned short __pad2;
104 	compat_ulong_t unused1;
105 	compat_ulong_t unused2;
106 };
107 
108 struct compat_semid64_ds {
109 	struct compat_ipc64_perm sem_perm;
110 	compat_ulong_t sem_otime;
111 	compat_ulong_t sem_otime_high;
112 	compat_ulong_t sem_ctime;
113 	compat_ulong_t sem_ctime_high;
114 	compat_ulong_t sem_nsems;
115 	compat_ulong_t __unused3;
116 	compat_ulong_t __unused4;
117 };
118 
119 struct compat_msqid64_ds {
120 	struct compat_ipc64_perm msg_perm;
121 	compat_ulong_t msg_stime;
122 	compat_ulong_t msg_stime_high;
123 	compat_ulong_t msg_rtime;
124 	compat_ulong_t msg_rtime_high;
125 	compat_ulong_t msg_ctime;
126 	compat_ulong_t msg_ctime_high;
127 	compat_ulong_t msg_cbytes;
128 	compat_ulong_t msg_qnum;
129 	compat_ulong_t msg_qbytes;
130 	compat_pid_t   msg_lspid;
131 	compat_pid_t   msg_lrpid;
132 	compat_ulong_t __unused4;
133 	compat_ulong_t __unused5;
134 };
135 
136 struct compat_shmid64_ds {
137 	struct compat_ipc64_perm shm_perm;
138 	compat_size_t  shm_segsz;
139 	compat_ulong_t shm_atime;
140 	compat_ulong_t shm_atime_high;
141 	compat_ulong_t shm_dtime;
142 	compat_ulong_t shm_dtime_high;
143 	compat_ulong_t shm_ctime;
144 	compat_ulong_t shm_ctime_high;
145 	compat_pid_t   shm_cpid;
146 	compat_pid_t   shm_lpid;
147 	compat_ulong_t shm_nattch;
148 	compat_ulong_t __unused4;
149 	compat_ulong_t __unused5;
150 };
151 
152 #ifdef CONFIG_X86_X32_ABI
153 #define COMPAT_USE_64BIT_TIME \
154 	(!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
155 #endif
156 
157 static inline bool in_x32_syscall(void)
158 {
159 #ifdef CONFIG_X86_X32_ABI
160 	if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
161 		return true;
162 #endif
163 	return false;
164 }
165 
166 static inline bool in_32bit_syscall(void)
167 {
168 	return in_ia32_syscall() || in_x32_syscall();
169 }
170 
171 #ifdef CONFIG_COMPAT
172 static inline bool in_compat_syscall(void)
173 {
174 	return in_32bit_syscall();
175 }
176 #define in_compat_syscall in_compat_syscall	/* override the generic impl */
177 #define compat_need_64bit_alignment_fixup in_ia32_syscall
178 #endif
179 
180 struct compat_siginfo;
181 
182 #ifdef CONFIG_X86_X32_ABI
183 int copy_siginfo_to_user32(struct compat_siginfo __user *to,
184 		const kernel_siginfo_t *from);
185 #define copy_siginfo_to_user32 copy_siginfo_to_user32
186 #endif /* CONFIG_X86_X32_ABI */
187 
188 #endif /* _ASM_X86_COMPAT_H */
189