xref: /linux/arch/x86/include/asm/compat.h (revision 0715372a06ce17a9ba69bbec306ddf30c4bad99e)
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 #define __compat_uid_t	__compat_uid_t
19 typedef u16		__compat_uid_t;
20 typedef u16		__compat_gid_t;
21 
22 #define compat_dev_t	compat_dev_t
23 typedef u16		compat_dev_t;
24 
25 #define compat_ipc_pid_t compat_ipc_pid_t
26 typedef u16		 compat_ipc_pid_t;
27 
28 #define compat_statfs	compat_statfs
29 
30 #include <asm-generic/compat.h>
31 
32 #define COMPAT_UTS_MACHINE	"i686\0\0"
33 
34 typedef u16		compat_nlink_t;
35 
36 struct compat_stat {
37 	compat_dev_t	st_dev;
38 	u16		__pad1;
39 	compat_ino_t	st_ino;
40 	compat_mode_t	st_mode;
41 	compat_nlink_t	st_nlink;
42 	__compat_uid_t	st_uid;
43 	__compat_gid_t	st_gid;
44 	compat_dev_t	st_rdev;
45 	u16		__pad2;
46 	u32		st_size;
47 	u32		st_blksize;
48 	u32		st_blocks;
49 	u32		st_atime;
50 	u32		st_atime_nsec;
51 	u32		st_mtime;
52 	u32		st_mtime_nsec;
53 	u32		st_ctime;
54 	u32		st_ctime_nsec;
55 	u32		__unused4;
56 	u32		__unused5;
57 };
58 
59 /*
60  * IA32 uses 4 byte alignment for 64 bit quantities, so we need to pack the
61  * compat flock64 structure.
62  */
63 #define __ARCH_NEED_COMPAT_FLOCK64_PACKED
64 
65 struct compat_statfs {
66 	int		f_type;
67 	int		f_bsize;
68 	int		f_blocks;
69 	int		f_bfree;
70 	int		f_bavail;
71 	int		f_files;
72 	int		f_ffree;
73 	compat_fsid_t	f_fsid;
74 	int		f_namelen;	/* SunOS ignores this field. */
75 	int		f_frsize;
76 	int		f_flags;
77 	int		f_spare[4];
78 };
79 
80 #ifdef CONFIG_X86_X32_ABI
81 #define COMPAT_USE_64BIT_TIME \
82 	(!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT))
83 #endif
84 
85 static inline bool in_x32_syscall(void)
86 {
87 #ifdef CONFIG_X86_X32_ABI
88 	if (task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)
89 		return true;
90 #endif
91 	return false;
92 }
93 
94 static inline bool in_32bit_syscall(void)
95 {
96 	return in_ia32_syscall() || in_x32_syscall();
97 }
98 
99 #ifdef CONFIG_COMPAT
100 static inline bool in_compat_syscall(void)
101 {
102 	return in_32bit_syscall();
103 }
104 #define in_compat_syscall in_compat_syscall	/* override the generic impl */
105 #define compat_need_64bit_alignment_fixup in_ia32_syscall
106 #endif
107 
108 struct compat_siginfo;
109 
110 #ifdef CONFIG_X86_X32_ABI
111 int copy_siginfo_to_user32(struct compat_siginfo __user *to,
112 		const kernel_siginfo_t *from);
113 #define copy_siginfo_to_user32 copy_siginfo_to_user32
114 #endif /* CONFIG_X86_X32_ABI */
115 
116 #endif /* _ASM_X86_COMPAT_H */
117