xref: /openbmc/linux/arch/x86/include/asm/compat.h (revision 84a0c977)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
21965aae3SH. Peter Anvin #ifndef _ASM_X86_COMPAT_H
31965aae3SH. Peter Anvin #define _ASM_X86_COMPAT_H
4bb898558SAl Viro 
5bb898558SAl Viro /*
6bb898558SAl Viro  * Architecture specific compatibility types
7bb898558SAl Viro  */
8bb898558SAl Viro #include <linux/types.h>
9bb898558SAl Viro #include <linux/sched.h>
10d375cf15SAndy Lutomirski #include <linux/sched/task_stack.h>
11d1a797f3SH. Peter Anvin #include <asm/processor.h>
12bb898558SAl Viro #include <asm/user32.h>
13fca460f9SH. Peter Anvin #include <asm/unistd.h>
14bb898558SAl Viro 
151a33b18bSArnd Bergmann #define compat_mode_t	compat_mode_t
161a33b18bSArnd Bergmann typedef u16		compat_mode_t;
171a33b18bSArnd Bergmann 
18*84a0c977SGuo Ren #define __compat_uid_t	__compat_uid_t
19bb898558SAl Viro typedef u16		__compat_uid_t;
20bb898558SAl Viro typedef u16		__compat_gid_t;
21*84a0c977SGuo Ren 
22*84a0c977SGuo Ren #define compat_dev_t	compat_dev_t
23bb898558SAl Viro typedef u16		compat_dev_t;
24*84a0c977SGuo Ren 
25*84a0c977SGuo Ren #define compat_ipc_pid_t compat_ipc_pid_t
26bb898558SAl Viro typedef u16		 compat_ipc_pid_t;
27*84a0c977SGuo Ren 
28*84a0c977SGuo Ren #define compat_statfs	compat_statfs
29*84a0c977SGuo Ren 
30*84a0c977SGuo Ren #include <asm-generic/compat.h>
31*84a0c977SGuo Ren 
32*84a0c977SGuo Ren #define COMPAT_UTS_MACHINE	"i686\0\0"
33*84a0c977SGuo Ren 
34*84a0c977SGuo Ren typedef u16		compat_nlink_t;
35bb898558SAl Viro 
36bb898558SAl Viro struct compat_stat {
37bb898558SAl Viro 	u32		st_dev;
38bb898558SAl Viro 	compat_ino_t	st_ino;
39bb898558SAl Viro 	compat_mode_t	st_mode;
40bb898558SAl Viro 	compat_nlink_t	st_nlink;
41bb898558SAl Viro 	__compat_uid_t	st_uid;
42bb898558SAl Viro 	__compat_gid_t	st_gid;
43bb898558SAl Viro 	u32		st_rdev;
44bb898558SAl Viro 	u32		st_size;
45bb898558SAl Viro 	u32		st_blksize;
46bb898558SAl Viro 	u32		st_blocks;
47bb898558SAl Viro 	u32		st_atime;
48bb898558SAl Viro 	u32		st_atime_nsec;
49bb898558SAl Viro 	u32		st_mtime;
50bb898558SAl Viro 	u32		st_mtime_nsec;
51bb898558SAl Viro 	u32		st_ctime;
52bb898558SAl Viro 	u32		st_ctime_nsec;
53bb898558SAl Viro 	u32		__unused4;
54bb898558SAl Viro 	u32		__unused5;
55bb898558SAl Viro };
56bb898558SAl Viro 
57bb898558SAl Viro /*
58bb898558SAl Viro  * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the
59bb898558SAl Viro  * compat flock64 structure.
603ce0f237SChristoph Hellwig  */
613ce0f237SChristoph Hellwig #define __ARCH_NEED_COMPAT_FLOCK64_PACKED
62bb898558SAl Viro 
633ce0f237SChristoph Hellwig struct compat_statfs {
64bb898558SAl Viro 	int		f_type;
65bb898558SAl Viro 	int		f_bsize;
66bb898558SAl Viro 	int		f_blocks;
67bb898558SAl Viro 	int		f_bfree;
68bb898558SAl Viro 	int		f_bavail;
69bb898558SAl Viro 	int		f_files;
70bb898558SAl Viro 	int		f_ffree;
71bb898558SAl Viro 	compat_fsid_t	f_fsid;
72bb898558SAl Viro 	int		f_namelen;	/* SunOS ignores this field. */
73bb898558SAl Viro 	int		f_frsize;
74bb898558SAl Viro 	int		f_flags;
75bb898558SAl Viro 	int		f_spare[4];
761448c721SEric W. Biederman };
771448c721SEric W. Biederman 
78bb898558SAl Viro #ifdef CONFIG_X86_X32_ABI
79bb898558SAl Viro #define COMPAT_USE_64BIT_TIME \
807b2dd368SDmitry Safonov 	(!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
81d1a797f3SH. Peter Anvin #endif
82d1a797f3SH. Peter Anvin 
in_x32_syscall(void)83d1a797f3SH. Peter Anvin static inline bool in_x32_syscall(void)
84bb898558SAl Viro {
85abfb9498SDmitry Safonov #ifdef CONFIG_X86_X32_ABI
86a628b684SH. Peter Anvin 	if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
87fca460f9SH. Peter Anvin 		return true;
88fca460f9SH. Peter Anvin #endif
89fca460f9SH. Peter Anvin 	return false;
90fca460f9SH. Peter Anvin }
91fca460f9SH. Peter Anvin 
in_32bit_syscall(void)92bb898558SAl Viro static inline bool in_32bit_syscall(void)
93bb898558SAl Viro {
94a846446bSDmitry Safonov 	return in_ia32_syscall() || in_x32_syscall();
95a628b684SH. Peter Anvin }
96abfb9498SDmitry Safonov 
97a628b684SH. Peter Anvin #ifdef CONFIG_COMPAT
in_compat_syscall(void)98a846446bSDmitry Safonov static inline bool in_compat_syscall(void)
99a846446bSDmitry Safonov {
100a846446bSDmitry Safonov 	return in_32bit_syscall();
101a846446bSDmitry Safonov }
102a846446bSDmitry Safonov #define in_compat_syscall in_compat_syscall	/* override the generic impl */
103a846446bSDmitry Safonov #define compat_need_64bit_alignment_fixup in_ia32_syscall
104f970165bSAndy Lutomirski #endif
105527c4125SChristoph Hellwig 
106a846446bSDmitry Safonov struct compat_siginfo;
107a628b684SH. Peter Anvin 
108ea64d5acSEric W. Biederman #ifdef CONFIG_X86_X32_ABI
109c3b3f524SChristoph Hellwig int copy_siginfo_to_user32(struct compat_siginfo __user *to,
110c3b3f524SChristoph Hellwig 		const kernel_siginfo_t *from);
111c3b3f524SChristoph Hellwig #define copy_siginfo_to_user32 copy_siginfo_to_user32
112c3b3f524SChristoph Hellwig #endif /* CONFIG_X86_X32_ABI */
113c3b3f524SChristoph Hellwig 
114c3b3f524SChristoph Hellwig #endif /* _ASM_X86_COMPAT_H */
115ea64d5acSEric W. Biederman