xref: /freebsd/sys/compat/ia32/ia32_signal.h (revision 4f29da19bd44f0e99f021510460a81bf754c21d2)
1 /*-
2  * Copyright (c) 1999 Marcel Moolenaar
3  * Copyright (c) 2003 Peter Wemm
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer
11  *    in this position and unchanged.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28  *
29  * $FreeBSD$
30  */
31 
32 struct ia32_sigaltstack {
33 	u_int32_t	ss_sp;		/* signal stack base */
34 	u_int32_t	ss_size;	/* signal stack length */
35 	int		ss_flags;	/* SS_DISABLE and/or SS_ONSTACK */
36 };
37 
38 struct ia32_mcontext {
39 	u_int32_t	mc_onstack;		/* XXX - sigcontext compat. */
40 	u_int32_t	mc_gs;			/* machine state (struct trapframe) */
41 	u_int32_t	mc_fs;
42 	u_int32_t	mc_es;
43 	u_int32_t	mc_ds;
44 	u_int32_t	mc_edi;
45 	u_int32_t	mc_esi;
46 	u_int32_t	mc_ebp;
47 	u_int32_t	mc_isp;
48 	u_int32_t	mc_ebx;
49 	u_int32_t	mc_edx;
50 	u_int32_t	mc_ecx;
51 	u_int32_t	mc_eax;
52 	u_int32_t	mc_trapno;
53 	u_int32_t	mc_err;
54 	u_int32_t	mc_eip;
55 	u_int32_t	mc_cs;
56 	u_int32_t	mc_eflags;
57 	u_int32_t	mc_esp;
58 	u_int32_t	mc_ss;
59 	u_int32_t	mc_len;			/* sizeof(struct ia32_mcontext) */
60 	/* We use the same values for fpformat and ownedfp */
61 	u_int32_t	mc_fpformat;
62 	u_int32_t	mc_ownedfp;
63 	u_int32_t	mc_spare1[1];		/* align next field to 16 bytes */
64 	/*
65 	 * See <i386/include/npx.h> for the internals of mc_fpstate[].
66 	 */
67 	u_int32_t	mc_fpstate[128] __aligned(16);
68 	u_int32_t	mc_spare2[8];
69 };
70 
71 struct ia32_ucontext {
72 	sigset_t		uc_sigmask;
73 	struct ia32_mcontext	uc_mcontext;
74 	u_int32_t		uc_link;
75 	struct ia32_sigaltstack	uc_stack;
76 	u_int32_t		uc_flags;
77 	u_int32_t		__spare__[4];
78 };
79 
80 
81 #if defined(COMPAT_FREEBSD4)
82 struct ia32_mcontext4 {
83 	u_int32_t	mc_onstack;		/* XXX - sigcontext compat. */
84 	u_int32_t	mc_gs;			/* machine state (struct trapframe) */
85 	u_int32_t	mc_fs;
86 	u_int32_t	mc_es;
87 	u_int32_t	mc_ds;
88 	u_int32_t	mc_edi;
89 	u_int32_t	mc_esi;
90 	u_int32_t	mc_ebp;
91 	u_int32_t	mc_isp;
92 	u_int32_t	mc_ebx;
93 	u_int32_t	mc_edx;
94 	u_int32_t	mc_ecx;
95 	u_int32_t	mc_eax;
96 	u_int32_t	mc_trapno;
97 	u_int32_t	mc_err;
98 	u_int32_t	mc_eip;
99 	u_int32_t	mc_cs;
100 	u_int32_t	mc_eflags;
101 	u_int32_t	mc_esp;
102 	u_int32_t	mc_ss;
103 	u_int32_t	mc_fpregs[28];
104 	u_int32_t	__spare__[17];
105 };
106 
107 struct ia32_ucontext4 {
108 	sigset_t		uc_sigmask;
109 	struct ia32_mcontext4	uc_mcontext;
110 	u_int32_t		uc_link;
111 	struct ia32_sigaltstack	uc_stack;
112 	u_int32_t		__spare__[8];
113 };
114 #endif
115 
116 #ifdef COMPAT_FREEBSD3
117 struct ia32_sigcontext3 {
118 	u_int32_t	sc_onstack;
119 	u_int32_t	sc_mask;
120 	u_int32_t	sc_esp;
121 	u_int32_t	sc_ebp;
122 	u_int32_t	sc_isp;
123 	u_int32_t	sc_eip;
124 	u_int32_t	sc_eflags;
125 	u_int32_t	sc_es;
126 	u_int32_t	sc_ds;
127 	u_int32_t	sc_cs;
128 	u_int32_t	sc_ss;
129 	u_int32_t	sc_edi;
130 	u_int32_t	sc_esi;
131 	u_int32_t	sc_ebx;
132 	u_int32_t	sc_edx;
133 	u_int32_t	sc_ecx;
134 	u_int32_t	sc_eax;
135 	u_int32_t	sc_gs;
136 	u_int32_t	sc_fs;
137 	u_int32_t	sc_trapno;
138 	u_int32_t	sc_err;
139 };
140 #endif
141 
142 /*
143  * Signal frames, arguments passed to application signal handlers.
144  */
145 union ia32_sigval {
146 	int			sigval_int;
147 	u_int32_t		sigval_ptr;
148 };
149 struct ia32_siginfo {
150 	int			si_signo;	/* signal number */
151 	int			si_errno;	/* errno association */
152 	int			si_code;	/* signal code */
153 	int32_t			si_pid;		/* sending process */
154 	u_int32_t		si_uid;		/* sender's ruid */
155 	int			si_status;	/* exit value */
156 	u_int32_t		si_addr;	/* faulting instruction */
157 	union ia32_sigval	si_value;	/* signal value */
158 	union	{
159 		struct {
160 			int	_trapno;/* machine specific trap code */
161 		} _fault;
162 		struct {
163 			int	_timerid;
164 			int	_overrun;
165 		} _timer;
166 		struct {
167 			int	_mqd;
168 		} _mesgq;
169 		struct {
170 			int	_band;		/* band event for SIGPOLL */
171 		} _poll;			/* was this ever used ? */
172 		struct {
173 			int	__spare1__;
174 			int	__spare2__[7];
175 		} __spare__;
176 	} _reason;
177 };
178 
179 #ifdef COMPAT_FREEBSD4
180 struct ia32_sigframe4 {
181 	u_int32_t		sf_signum;
182 	u_int32_t		sf_siginfo;	/* code or pointer to sf_si */
183 	u_int32_t		sf_ucontext;	/* points to sf_uc */
184 	u_int32_t		sf_addr;	/* undocumented 4th arg */
185 	u_int32_t		sf_ah;		/* action/handler pointer */
186 	struct ia32_ucontext4	sf_uc;		/* = *sf_ucontext */
187 	struct ia32_siginfo	sf_si;		/* = *sf_siginfo (SA_SIGINFO case) */
188 };
189 #endif
190 
191 struct ia32_sigframe {
192 	u_int32_t		sf_signum;
193 	u_int32_t		sf_siginfo;	/* code or pointer to sf_si */
194 	u_int32_t		sf_ucontext;	/* points to sf_uc */
195 	u_int32_t		sf_addr;	/* undocumented 4th arg */
196 	u_int32_t		sf_ah;		/* action/handler pointer */
197 	/* Beware, hole due to ucontext being 16 byte aligned! */
198 	struct ia32_ucontext	sf_uc;		/* = *sf_ucontext */
199 	struct ia32_siginfo	sf_si;		/* = *sf_siginfo (SA_SIGINFO case) */
200 };
201 
202 #ifdef COMPAT_FREEBSD3
203 struct ia32_siginfo3 {
204 	struct ia32_sigcontext3 si_sc;
205 	int			si_signo;
206 	int			si_code;
207 	union ia32_sigval si_value;
208 };
209 struct ia32_sigframe3 {
210 	int			sf_signum;
211 	u_int32_t		sf_arg2;	/* int or siginfo_t */
212 	u_int32_t		sf_scp;
213 	u_int32_t		sf_addr;
214 	u_int32_t		sf_ah;		/* action/handler pointer */
215 	struct ia32_siginfo3	sf_siginfo;
216 };
217 #endif
218 
219 struct ksiginfo;
220 extern char ia32_sigcode[];
221 extern char freebsd4_ia32_sigcode[];
222 extern int sz_ia32_sigcode;
223 extern int sz_freebsd4_ia32_sigcode;
224 extern void ia32_sendsig(sig_t, struct ksiginfo *, sigset_t *);
225 extern void ia32_setregs(struct thread *td, u_long entry, u_long stack,
226     u_long ps_strings);
227 extern void siginfo_to_ia32siginfo(siginfo_t *src, struct ia32_siginfo *dst);
228