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