xref: /freebsd/sys/x86/linux/linux_x86_sigframe.h (revision cbbac560)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 2004 Tim J. Robbins
5  * Copyright (c) 2001 Doug Rabson
6  * Copyright (c) 1994-1996 Søren Schmidt
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer
14  *    in this position and unchanged.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  *
32  * $FreeBSD$
33  */
34 
35 #ifndef _X86_LINUX_SIGFRAME_H_
36 #define	_X86_LINUX_SIGFRAME_H_
37 
38 #define	LINUX_UC_FP_XSTATE		0x1
39 
40 #define	LINUX_FP_XSTATE_MAGIC1		0x46505853U
41 #define	LINUX_FP_XSTATE_MAGIC2		0x46505845U
42 #define	LINUX_FP_XSTATE_MAGIC2_SIZE	sizeof(uint32_t)
43 
44 struct l_fpx_sw_bytes {
45 	uint32_t	magic1;
46 	uint32_t	extended_size;
47 	uint64_t	xfeatures;
48 	uint32_t	xstate_size;
49 	uint32_t	padding[7];
50 };
51 
52 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
53 
54 /* The Linux sigcontext, pretty much a standard 386 trapframe. */
55 struct l_sigcontext {
56 	l_uint		sc_gs;
57 	l_uint		sc_fs;
58 	l_uint		sc_es;
59 	l_uint		sc_ds;
60 	l_uint		sc_edi;
61 	l_uint		sc_esi;
62 	l_uint		sc_ebp;
63 	l_uint		sc_esp;
64 	l_uint		sc_ebx;
65 	l_uint		sc_edx;
66 	l_uint		sc_ecx;
67 	l_uint		sc_eax;
68 	l_uint		sc_trapno;
69 	l_uint		sc_err;
70 	l_uint		sc_eip;
71 	l_uint		sc_cs;
72 	l_uint		sc_eflags;
73 	l_uint		sc_esp_at_signal;
74 	l_uint		sc_ss;
75 	l_uint		sc_387;
76 	l_uint		sc_mask;
77 	l_uint		sc_cr2;
78 };
79 
80 struct l_ucontext {
81 	l_ulong		uc_flags;
82 	l_uintptr_t	uc_link;
83 	l_stack_t	uc_stack;
84 	struct l_sigcontext	uc_mcontext;
85 	l_sigset_t	uc_sigmask;
86 } __packed;
87 
88 struct l_fpreg {
89 	u_int16_t	significand[4];
90 	u_int16_t	exponent;
91 };
92 
93 struct l_fpxreg {
94 	u_int16_t	significand[4];
95 	u_int16_t	exponent;
96 	u_int16_t	padding[3];
97 };
98 
99 struct l_xmmreg {
100 	u_int32_t	element[4];
101 };
102 
103 struct l_fpstate {
104 	/* Regular FPU environment */
105 	u_int32_t		cw;
106 	u_int32_t		sw;
107 	u_int32_t		tag;
108 	u_int32_t		ipoff;
109 	u_int32_t		cssel;
110 	u_int32_t		dataoff;
111 	u_int32_t		datasel;
112 	struct l_fpreg		_st[8];
113 	u_int16_t		status;
114 	u_int16_t		magic;		/* 0xffff = regular FPU data */
115 
116 	/* FXSR FPU environment */
117 	u_int32_t		_fxsr_env[6];	/* env is ignored. */
118 	u_int32_t		mxcsr;
119 	u_int32_t		reserved;
120 	struct l_fpxreg		_fxsr_st[8];	/* reg data is ignored. */
121 	struct l_xmmreg		_xmm[8];
122 	u_int32_t		padding[56];
123 };
124 
125 /*
126  * We make the stack look like Linux expects it when calling a signal
127  * handler, but use the BSD way of calling the handler and sigreturn().
128  */
129 struct l_sigframe {
130 	l_int			sf_sig;
131 	struct l_sigcontext	sf_sc;
132 	struct l_fpstate	sf_fpstate;
133 	sigset_t		sf_sigmask;
134 };
135 
136 struct l_rt_sigframe {
137 	l_int			sf_sig;
138 	l_uintptr_t		sf_siginfo;
139 	l_uintptr_t		sf_ucontext;
140 	l_siginfo_t		sf_si;
141 	struct l_ucontext	sf_uc;
142 };
143 
144 #else
145 
146 struct l_fpstate {
147 	u_int16_t cwd;
148 	u_int16_t swd;
149 	u_int16_t twd;
150 	u_int16_t fop;
151 	u_int64_t rip;
152 	u_int64_t rdp;
153 	u_int32_t mxcsr;
154 	u_int32_t mxcsr_mask;
155 	u_int8_t st[8][16];
156 	u_int8_t xmm[16][16];
157 	u_int32_t reserved2[12];
158 	union {
159 		u_int32_t		reserved3[12];
160 		struct l_fpx_sw_bytes	sw_reserved;
161 	};
162 } __aligned(16);
163 
164 struct l_sigcontext {
165 	l_ulong		sc_r8;
166 	l_ulong		sc_r9;
167 	l_ulong		sc_r10;
168 	l_ulong		sc_r11;
169 	l_ulong		sc_r12;
170 	l_ulong		sc_r13;
171 	l_ulong		sc_r14;
172 	l_ulong		sc_r15;
173 	l_ulong		sc_rdi;
174 	l_ulong		sc_rsi;
175 	l_ulong		sc_rbp;
176 	l_ulong		sc_rbx;
177 	l_ulong		sc_rdx;
178 	l_ulong		sc_rax;
179 	l_ulong		sc_rcx;
180 	l_ulong		sc_rsp;
181 	l_ulong		sc_rip;
182 	l_ulong		sc_rflags;
183 	l_ushort	sc_cs;
184 	l_ushort	sc_gs;
185 	l_ushort	sc_fs;
186 	l_ushort	sc___pad0;
187 	l_ulong		sc_err;
188 	l_ulong		sc_trapno;
189 	l_sigset_t	sc_mask;
190 	l_ulong		sc_cr2;
191 	/*
192 	 * On Linux sc_fpstate is (struct l_fpstate *) or (struct l_xstate *)
193 	 * depending on the FP_XSTATE_MAGIC1 encoded in the sw_reserved
194 	 * bytes of (struct l_fpstate) and FP_XSTATE_MAGIC2 present at the end
195 	 * of extended memory layout.
196 	 */
197 	l_uintptr_t	sc_fpstate;
198 	l_ulong		sc_reserved1[8];
199 };
200 
201 struct l_ucontext {
202 	l_ulong		uc_flags;
203 	l_uintptr_t	uc_link;
204 	l_stack_t	uc_stack;
205 	struct l_sigcontext	uc_mcontext;
206 	l_sigset_t	uc_sigmask;
207 };
208 
209 /*
210  * We make the stack look like Linux expects it when calling a signal
211  * handler, but use the BSD way of calling the handler and sigreturn().
212  */
213 struct l_rt_sigframe {
214 	struct l_ucontext	sf_uc;
215 	struct l_siginfo	sf_si;
216 };
217 
218 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
219 
220 #endif /* !_X86_LINUX_SIGFRAME_H_ */
221