Linux Audio

Check our new training course

Loading...
v5.4
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  linux/arch/x86_64/ia32/ia32_signal.c
  4 *
  5 *  Copyright (C) 1991, 1992  Linus Torvalds
  6 *
  7 *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
  8 *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
  9 *  2000-12-*   x86-64 compatibility mode signal handling by Andi Kleen
 10 */
 11
 12#include <linux/sched.h>
 13#include <linux/sched/task_stack.h>
 14#include <linux/mm.h>
 15#include <linux/smp.h>
 16#include <linux/kernel.h>
 17#include <linux/errno.h>
 18#include <linux/wait.h>
 19#include <linux/unistd.h>
 20#include <linux/stddef.h>
 21#include <linux/personality.h>
 22#include <linux/compat.h>
 23#include <linux/binfmts.h>
 
 24#include <asm/ucontext.h>
 25#include <linux/uaccess.h>
 26#include <asm/fpu/internal.h>
 27#include <asm/fpu/signal.h>
 28#include <asm/ptrace.h>
 29#include <asm/ia32_unistd.h>
 30#include <asm/user32.h>
 31#include <uapi/asm/sigcontext.h>
 32#include <asm/proto.h>
 33#include <asm/vdso.h>
 34#include <asm/sigframe.h>
 35#include <asm/sighandling.h>
 36#include <asm/smap.h>
 37
 38/*
 39 * Do a signal return; undo the signal stack.
 40 */
 41#define loadsegment_gs(v)	load_gs_index(v)
 42#define loadsegment_fs(v)	loadsegment(fs, v)
 43#define loadsegment_ds(v)	loadsegment(ds, v)
 44#define loadsegment_es(v)	loadsegment(es, v)
 45
 46#define get_user_seg(seg)	({ unsigned int v; savesegment(seg, v); v; })
 47#define set_user_seg(seg, v)	loadsegment_##seg(v)
 48
 49#define COPY(x)			{		\
 50	get_user_ex(regs->x, &sc->x);		\
 51}
 52
 53#define GET_SEG(seg)		({			\
 54	unsigned short tmp;				\
 55	get_user_ex(tmp, &sc->seg);			\
 56	tmp;						\
 57})
 58
 59#define COPY_SEG_CPL3(seg)	do {			\
 60	regs->seg = GET_SEG(seg) | 3;			\
 61} while (0)
 62
 63#define RELOAD_SEG(seg)		{		\
 64	unsigned int pre = (seg) | 3;		\
 65	unsigned int cur = get_user_seg(seg);	\
 66	if (pre != cur)				\
 67		set_user_seg(seg, pre);		\
 68}
 69
 
 
 
 70static int ia32_restore_sigcontext(struct pt_regs *regs,
 71				   struct sigcontext_32 __user *sc)
 72{
 73	unsigned int tmpflags, err = 0;
 74	u16 gs, fs, es, ds;
 75	void __user *buf;
 76	u32 tmp;
 77
 78	/* Always make any pending restarted system calls return -EINTR */
 79	current->restart_block.fn = do_no_restart_syscall;
 80
 81	get_user_try {
 82		gs = GET_SEG(gs);
 83		fs = GET_SEG(fs);
 84		ds = GET_SEG(ds);
 85		es = GET_SEG(es);
 86
 87		COPY(di); COPY(si); COPY(bp); COPY(sp); COPY(bx);
 88		COPY(dx); COPY(cx); COPY(ip); COPY(ax);
 89		/* Don't touch extended registers */
 90
 91		COPY_SEG_CPL3(cs);
 92		COPY_SEG_CPL3(ss);
 93
 94		get_user_ex(tmpflags, &sc->flags);
 95		regs->flags = (regs->flags & ~FIX_EFLAGS) | (tmpflags & FIX_EFLAGS);
 96		/* disable syscall checks */
 97		regs->orig_ax = -1;
 98
 99		get_user_ex(tmp, &sc->fpstate);
100		buf = compat_ptr(tmp);
101	} get_user_catch(err);
102
103	/*
104	 * Reload fs and gs if they have changed in the signal
105	 * handler.  This does not handle long fs/gs base changes in
106	 * the handler, but does not clobber them at least in the
107	 * normal case.
108	 */
109	RELOAD_SEG(gs);
110	RELOAD_SEG(fs);
111	RELOAD_SEG(ds);
112	RELOAD_SEG(es);
113
114	err |= fpu__restore_sig(buf, 1);
115
116	force_iret();
117
118	return err;
119}
120
121asmlinkage long sys32_sigreturn(void)
122{
123	struct pt_regs *regs = current_pt_regs();
124	struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
125	sigset_t set;
126
127	if (!access_ok(frame, sizeof(*frame)))
128		goto badframe;
129	if (__get_user(set.sig[0], &frame->sc.oldmask)
130	    || (_COMPAT_NSIG_WORDS > 1
131		&& __copy_from_user((((char *) &set.sig) + 4),
132				    &frame->extramask,
133				    sizeof(frame->extramask))))
134		goto badframe;
135
136	set_current_blocked(&set);
137
138	if (ia32_restore_sigcontext(regs, &frame->sc))
139		goto badframe;
140	return regs->ax;
141
142badframe:
143	signal_fault(regs, frame, "32bit sigreturn");
144	return 0;
145}
146
147asmlinkage long sys32_rt_sigreturn(void)
148{
149	struct pt_regs *regs = current_pt_regs();
150	struct rt_sigframe_ia32 __user *frame;
151	sigset_t set;
152
153	frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
154
155	if (!access_ok(frame, sizeof(*frame)))
156		goto badframe;
157	if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
158		goto badframe;
159
160	set_current_blocked(&set);
161
162	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
163		goto badframe;
164
165	if (compat_restore_altstack(&frame->uc.uc_stack))
166		goto badframe;
167
168	return regs->ax;
169
170badframe:
171	signal_fault(regs, frame, "32bit rt sigreturn");
172	return 0;
173}
174
175/*
176 * Set up a signal frame.
177 */
178
179static int ia32_setup_sigcontext(struct sigcontext_32 __user *sc,
180				 void __user *fpstate,
181				 struct pt_regs *regs, unsigned int mask)
182{
183	int err = 0;
184
185	put_user_try {
186		put_user_ex(get_user_seg(gs), (unsigned int __user *)&sc->gs);
187		put_user_ex(get_user_seg(fs), (unsigned int __user *)&sc->fs);
188		put_user_ex(get_user_seg(ds), (unsigned int __user *)&sc->ds);
189		put_user_ex(get_user_seg(es), (unsigned int __user *)&sc->es);
190
191		put_user_ex(regs->di, &sc->di);
192		put_user_ex(regs->si, &sc->si);
193		put_user_ex(regs->bp, &sc->bp);
194		put_user_ex(regs->sp, &sc->sp);
195		put_user_ex(regs->bx, &sc->bx);
196		put_user_ex(regs->dx, &sc->dx);
197		put_user_ex(regs->cx, &sc->cx);
198		put_user_ex(regs->ax, &sc->ax);
199		put_user_ex(current->thread.trap_nr, &sc->trapno);
200		put_user_ex(current->thread.error_code, &sc->err);
201		put_user_ex(regs->ip, &sc->ip);
202		put_user_ex(regs->cs, (unsigned int __user *)&sc->cs);
203		put_user_ex(regs->flags, &sc->flags);
204		put_user_ex(regs->sp, &sc->sp_at_signal);
205		put_user_ex(regs->ss, (unsigned int __user *)&sc->ss);
206
207		put_user_ex(ptr_to_compat(fpstate), &sc->fpstate);
208
209		/* non-iBCS2 extensions.. */
210		put_user_ex(mask, &sc->oldmask);
211		put_user_ex(current->thread.cr2, &sc->cr2);
212	} put_user_catch(err);
 
 
 
 
213
214	return err;
 
215}
216
 
 
 
 
 
 
217/*
218 * Determine which stack to use..
219 */
220static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
221				 size_t frame_size,
222				 void __user **fpstate)
223{
224	unsigned long sp, fx_aligned, math_size;
225
226	/* Default to using normal stack */
227	sp = regs->sp;
228
229	/* This is the X/Open sanctioned signal stack switching.  */
230	if (ksig->ka.sa.sa_flags & SA_ONSTACK)
231		sp = sigsp(sp, ksig);
232	/* This is the legacy signal stack switching. */
233	else if (regs->ss != __USER32_DS &&
234		!(ksig->ka.sa.sa_flags & SA_RESTORER) &&
235		 ksig->ka.sa.sa_restorer)
236		sp = (unsigned long) ksig->ka.sa.sa_restorer;
237
238	sp = fpu__alloc_mathframe(sp, 1, &fx_aligned, &math_size);
239	*fpstate = (struct _fpstate_32 __user *) sp;
240	if (copy_fpstate_to_sigframe(*fpstate, (void __user *)fx_aligned,
241				     math_size) < 0)
242		return (void __user *) -1L;
243
244	sp -= frame_size;
245	/* Align the stack pointer according to the i386 ABI,
246	 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
247	sp = ((sp + 4) & -16ul) - 4;
248	return (void __user *) sp;
249}
250
251int ia32_setup_frame(int sig, struct ksignal *ksig,
252		     compat_sigset_t *set, struct pt_regs *regs)
253{
254	struct sigframe_ia32 __user *frame;
255	void __user *restorer;
256	int err = 0;
257	void __user *fpstate = NULL;
258
259	/* copy_to_user optimizes that into a single 8 byte store */
260	static const struct {
261		u16 poplmovl;
262		u32 val;
263		u16 int80;
264	} __attribute__((packed)) code = {
265		0xb858,		 /* popl %eax ; movl $...,%eax */
266		__NR_ia32_sigreturn,
267		0x80cd,		/* int $0x80 */
268	};
269
270	frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
271
272	if (!access_ok(frame, sizeof(*frame)))
273		return -EFAULT;
274
275	if (__put_user(sig, &frame->sig))
276		return -EFAULT;
277
278	if (ia32_setup_sigcontext(&frame->sc, fpstate, regs, set->sig[0]))
279		return -EFAULT;
280
281	if (_COMPAT_NSIG_WORDS > 1) {
282		if (__copy_to_user(frame->extramask, &set->sig[1],
283				   sizeof(frame->extramask)))
284			return -EFAULT;
285	}
286
287	if (ksig->ka.sa.sa_flags & SA_RESTORER) {
288		restorer = ksig->ka.sa.sa_restorer;
289	} else {
290		/* Return stub is in 32bit vsyscall page */
291		if (current->mm->context.vdso)
292			restorer = current->mm->context.vdso +
293				vdso_image_32.sym___kernel_sigreturn;
294		else
295			restorer = &frame->retcode;
296	}
297
298	put_user_try {
299		put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
300
301		/*
302		 * These are actually not used anymore, but left because some
303		 * gdb versions depend on them as a marker.
304		 */
305		put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
306	} put_user_catch(err);
307
308	if (err)
309		return -EFAULT;
310
 
 
 
 
 
 
 
 
 
 
 
311	/* Set up registers for signal handler */
312	regs->sp = (unsigned long) frame;
313	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
314
315	/* Make -mregparm=3 work */
316	regs->ax = sig;
317	regs->dx = 0;
318	regs->cx = 0;
319
320	loadsegment(ds, __USER32_DS);
321	loadsegment(es, __USER32_DS);
322
323	regs->cs = __USER32_CS;
324	regs->ss = __USER32_DS;
325
326	return 0;
 
 
 
327}
328
329int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
330			compat_sigset_t *set, struct pt_regs *regs)
331{
332	struct rt_sigframe_ia32 __user *frame;
333	void __user *restorer;
334	int err = 0;
335	void __user *fpstate = NULL;
336
337	/* __copy_to_user optimizes that into a single 8 byte store */
338	static const struct {
339		u8 movl;
340		u32 val;
341		u16 int80;
342		u8  pad;
343	} __attribute__((packed)) code = {
344		0xb8,
345		__NR_ia32_rt_sigreturn,
346		0x80cd,
347		0,
348	};
349
350	frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
351
352	if (!access_ok(frame, sizeof(*frame)))
353		return -EFAULT;
354
355	put_user_try {
356		put_user_ex(sig, &frame->sig);
357		put_user_ex(ptr_to_compat(&frame->info), &frame->pinfo);
358		put_user_ex(ptr_to_compat(&frame->uc), &frame->puc);
359
360		/* Create the ucontext.  */
361		if (static_cpu_has(X86_FEATURE_XSAVE))
362			put_user_ex(UC_FP_XSTATE, &frame->uc.uc_flags);
363		else
364			put_user_ex(0, &frame->uc.uc_flags);
365		put_user_ex(0, &frame->uc.uc_link);
366		compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
367
368		if (ksig->ka.sa.sa_flags & SA_RESTORER)
369			restorer = ksig->ka.sa.sa_restorer;
370		else
371			restorer = current->mm->context.vdso +
372				vdso_image_32.sym___kernel_rt_sigreturn;
373		put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
374
375		/*
376		 * Not actually used anymore, but left because some gdb
377		 * versions need it.
378		 */
379		put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
380	} put_user_catch(err);
381
382	err |= __copy_siginfo_to_user32(&frame->info, &ksig->info, false);
383	err |= ia32_setup_sigcontext(&frame->uc.uc_mcontext, fpstate,
384				     regs, set->sig[0]);
385	err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
386
387	if (err)
388		return -EFAULT;
389
390	/* Set up registers for signal handler */
391	regs->sp = (unsigned long) frame;
392	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
393
394	/* Make -mregparm=3 work */
395	regs->ax = sig;
396	regs->dx = (unsigned long) &frame->info;
397	regs->cx = (unsigned long) &frame->uc;
398
399	loadsegment(ds, __USER32_DS);
400	loadsegment(es, __USER32_DS);
401
402	regs->cs = __USER32_CS;
403	regs->ss = __USER32_DS;
404
405	return 0;
 
 
 
406}
v5.9
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  3 *  linux/arch/x86_64/ia32/ia32_signal.c
  4 *
  5 *  Copyright (C) 1991, 1992  Linus Torvalds
  6 *
  7 *  1997-11-28  Modified for POSIX.1b signals by Richard Henderson
  8 *  2000-06-20  Pentium III FXSR, SSE support by Gareth Hughes
  9 *  2000-12-*   x86-64 compatibility mode signal handling by Andi Kleen
 10 */
 11
 12#include <linux/sched.h>
 13#include <linux/sched/task_stack.h>
 14#include <linux/mm.h>
 15#include <linux/smp.h>
 16#include <linux/kernel.h>
 17#include <linux/errno.h>
 18#include <linux/wait.h>
 19#include <linux/unistd.h>
 20#include <linux/stddef.h>
 21#include <linux/personality.h>
 22#include <linux/compat.h>
 23#include <linux/binfmts.h>
 24#include <linux/syscalls.h>
 25#include <asm/ucontext.h>
 26#include <linux/uaccess.h>
 27#include <asm/fpu/internal.h>
 28#include <asm/fpu/signal.h>
 29#include <asm/ptrace.h>
 30#include <asm/ia32_unistd.h>
 31#include <asm/user32.h>
 32#include <uapi/asm/sigcontext.h>
 33#include <asm/proto.h>
 34#include <asm/vdso.h>
 35#include <asm/sigframe.h>
 36#include <asm/sighandling.h>
 37#include <asm/smap.h>
 38
 39static inline void reload_segments(struct sigcontext_32 *sc)
 40{
 41	unsigned int cur;
 
 
 
 
 
 
 
 
 
 
 
 42
 43	savesegment(gs, cur);
 44	if ((sc->gs | 0x03) != cur)
 45		load_gs_index(sc->gs | 0x03);
 46	savesegment(fs, cur);
 47	if ((sc->fs | 0x03) != cur)
 48		loadsegment(fs, sc->fs | 0x03);
 49	savesegment(ds, cur);
 50	if ((sc->ds | 0x03) != cur)
 51		loadsegment(ds, sc->ds | 0x03);
 52	savesegment(es, cur);
 53	if ((sc->es | 0x03) != cur)
 54		loadsegment(es, sc->es | 0x03);
 
 
 
 55}
 56
 57/*
 58 * Do a signal return; undo the signal stack.
 59 */
 60static int ia32_restore_sigcontext(struct pt_regs *regs,
 61				   struct sigcontext_32 __user *usc)
 62{
 63	struct sigcontext_32 sc;
 
 
 
 64
 65	/* Always make any pending restarted system calls return -EINTR */
 66	current->restart_block.fn = do_no_restart_syscall;
 67
 68	if (unlikely(copy_from_user(&sc, usc, sizeof(sc))))
 69		return -EFAULT;
 70
 71	/* Get only the ia32 registers. */
 72	regs->bx = sc.bx;
 73	regs->cx = sc.cx;
 74	regs->dx = sc.dx;
 75	regs->si = sc.si;
 76	regs->di = sc.di;
 77	regs->bp = sc.bp;
 78	regs->ax = sc.ax;
 79	regs->sp = sc.sp;
 80	regs->ip = sc.ip;
 81
 82	/* Get CS/SS and force CPL3 */
 83	regs->cs = sc.cs | 0x03;
 84	regs->ss = sc.ss | 0x03;
 85
 86	regs->flags = (regs->flags & ~FIX_EFLAGS) | (sc.flags & FIX_EFLAGS);
 87	/* disable syscall checks */
 88	regs->orig_ax = -1;
 89
 90	/*
 91	 * Reload fs and gs if they have changed in the signal
 92	 * handler.  This does not handle long fs/gs base changes in
 93	 * the handler, but does not clobber them at least in the
 94	 * normal case.
 95	 */
 96	reload_segments(&sc);
 97	return fpu__restore_sig(compat_ptr(sc.fpstate), 1);
 
 
 
 
 
 
 
 
 98}
 99
100COMPAT_SYSCALL_DEFINE0(sigreturn)
101{
102	struct pt_regs *regs = current_pt_regs();
103	struct sigframe_ia32 __user *frame = (struct sigframe_ia32 __user *)(regs->sp-8);
104	sigset_t set;
105
106	if (!access_ok(frame, sizeof(*frame)))
107		goto badframe;
108	if (__get_user(set.sig[0], &frame->sc.oldmask)
109	    || __get_user(((__u32 *)&set)[1], &frame->extramask[0]))
 
 
 
110		goto badframe;
111
112	set_current_blocked(&set);
113
114	if (ia32_restore_sigcontext(regs, &frame->sc))
115		goto badframe;
116	return regs->ax;
117
118badframe:
119	signal_fault(regs, frame, "32bit sigreturn");
120	return 0;
121}
122
123COMPAT_SYSCALL_DEFINE0(rt_sigreturn)
124{
125	struct pt_regs *regs = current_pt_regs();
126	struct rt_sigframe_ia32 __user *frame;
127	sigset_t set;
128
129	frame = (struct rt_sigframe_ia32 __user *)(regs->sp - 4);
130
131	if (!access_ok(frame, sizeof(*frame)))
132		goto badframe;
133	if (__get_user(set.sig[0], (__u64 __user *)&frame->uc.uc_sigmask))
134		goto badframe;
135
136	set_current_blocked(&set);
137
138	if (ia32_restore_sigcontext(regs, &frame->uc.uc_mcontext))
139		goto badframe;
140
141	if (compat_restore_altstack(&frame->uc.uc_stack))
142		goto badframe;
143
144	return regs->ax;
145
146badframe:
147	signal_fault(regs, frame, "32bit rt sigreturn");
148	return 0;
149}
150
151/*
152 * Set up a signal frame.
153 */
154
155#define get_user_seg(seg)	({ unsigned int v; savesegment(seg, v); v; })
 
 
 
 
156
157static __always_inline int
158__unsafe_setup_sigcontext32(struct sigcontext_32 __user *sc,
159			    void __user *fpstate,
160			    struct pt_regs *regs, unsigned int mask)
161{
162	unsafe_put_user(get_user_seg(gs), (unsigned int __user *)&sc->gs, Efault);
163	unsafe_put_user(get_user_seg(fs), (unsigned int __user *)&sc->fs, Efault);
164	unsafe_put_user(get_user_seg(ds), (unsigned int __user *)&sc->ds, Efault);
165	unsafe_put_user(get_user_seg(es), (unsigned int __user *)&sc->es, Efault);
166
167	unsafe_put_user(regs->di, &sc->di, Efault);
168	unsafe_put_user(regs->si, &sc->si, Efault);
169	unsafe_put_user(regs->bp, &sc->bp, Efault);
170	unsafe_put_user(regs->sp, &sc->sp, Efault);
171	unsafe_put_user(regs->bx, &sc->bx, Efault);
172	unsafe_put_user(regs->dx, &sc->dx, Efault);
173	unsafe_put_user(regs->cx, &sc->cx, Efault);
174	unsafe_put_user(regs->ax, &sc->ax, Efault);
175	unsafe_put_user(current->thread.trap_nr, &sc->trapno, Efault);
176	unsafe_put_user(current->thread.error_code, &sc->err, Efault);
177	unsafe_put_user(regs->ip, &sc->ip, Efault);
178	unsafe_put_user(regs->cs, (unsigned int __user *)&sc->cs, Efault);
179	unsafe_put_user(regs->flags, &sc->flags, Efault);
180	unsafe_put_user(regs->sp, &sc->sp_at_signal, Efault);
181	unsafe_put_user(regs->ss, (unsigned int __user *)&sc->ss, Efault);
182
183	unsafe_put_user(ptr_to_compat(fpstate), &sc->fpstate, Efault);
184
185	/* non-iBCS2 extensions.. */
186	unsafe_put_user(mask, &sc->oldmask, Efault);
187	unsafe_put_user(current->thread.cr2, &sc->cr2, Efault);
188	return 0;
189
190Efault:
191	return -EFAULT;
192}
193
194#define unsafe_put_sigcontext32(sc, fp, regs, set, label)		\
195do {									\
196	if (__unsafe_setup_sigcontext32(sc, fp, regs, set->sig[0]))	\
197		goto label;						\
198} while(0)
199
200/*
201 * Determine which stack to use..
202 */
203static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
204				 size_t frame_size,
205				 void __user **fpstate)
206{
207	unsigned long sp, fx_aligned, math_size;
208
209	/* Default to using normal stack */
210	sp = regs->sp;
211
212	/* This is the X/Open sanctioned signal stack switching.  */
213	if (ksig->ka.sa.sa_flags & SA_ONSTACK)
214		sp = sigsp(sp, ksig);
215	/* This is the legacy signal stack switching. */
216	else if (regs->ss != __USER32_DS &&
217		!(ksig->ka.sa.sa_flags & SA_RESTORER) &&
218		 ksig->ka.sa.sa_restorer)
219		sp = (unsigned long) ksig->ka.sa.sa_restorer;
220
221	sp = fpu__alloc_mathframe(sp, 1, &fx_aligned, &math_size);
222	*fpstate = (struct _fpstate_32 __user *) sp;
223	if (copy_fpstate_to_sigframe(*fpstate, (void __user *)fx_aligned,
224				     math_size) < 0)
225		return (void __user *) -1L;
226
227	sp -= frame_size;
228	/* Align the stack pointer according to the i386 ABI,
229	 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
230	sp = ((sp + 4) & -16ul) - 4;
231	return (void __user *) sp;
232}
233
234int ia32_setup_frame(int sig, struct ksignal *ksig,
235		     compat_sigset_t *set, struct pt_regs *regs)
236{
237	struct sigframe_ia32 __user *frame;
238	void __user *restorer;
239	void __user *fp = NULL;
 
240
241	/* copy_to_user optimizes that into a single 8 byte store */
242	static const struct {
243		u16 poplmovl;
244		u32 val;
245		u16 int80;
246	} __attribute__((packed)) code = {
247		0xb858,		 /* popl %eax ; movl $...,%eax */
248		__NR_ia32_sigreturn,
249		0x80cd,		/* int $0x80 */
250	};
251
252	frame = get_sigframe(ksig, regs, sizeof(*frame), &fp);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
254	if (ksig->ka.sa.sa_flags & SA_RESTORER) {
255		restorer = ksig->ka.sa.sa_restorer;
256	} else {
257		/* Return stub is in 32bit vsyscall page */
258		if (current->mm->context.vdso)
259			restorer = current->mm->context.vdso +
260				vdso_image_32.sym___kernel_sigreturn;
261		else
262			restorer = &frame->retcode;
263	}
264
265	if (!user_access_begin(frame, sizeof(*frame)))
 
 
 
 
 
 
 
 
 
 
266		return -EFAULT;
267
268	unsafe_put_user(sig, &frame->sig, Efault);
269	unsafe_put_sigcontext32(&frame->sc, fp, regs, set, Efault);
270	unsafe_put_user(set->sig[1], &frame->extramask[0], Efault);
271	unsafe_put_user(ptr_to_compat(restorer), &frame->pretcode, Efault);
272	/*
273	 * These are actually not used anymore, but left because some
274	 * gdb versions depend on them as a marker.
275	 */
276	unsafe_put_user(*((u64 *)&code), (u64 __user *)frame->retcode, Efault);
277	user_access_end();
278
279	/* Set up registers for signal handler */
280	regs->sp = (unsigned long) frame;
281	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
282
283	/* Make -mregparm=3 work */
284	regs->ax = sig;
285	regs->dx = 0;
286	regs->cx = 0;
287
288	loadsegment(ds, __USER32_DS);
289	loadsegment(es, __USER32_DS);
290
291	regs->cs = __USER32_CS;
292	regs->ss = __USER32_DS;
293
294	return 0;
295Efault:
296	user_access_end();
297	return -EFAULT;
298}
299
300int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
301			compat_sigset_t *set, struct pt_regs *regs)
302{
303	struct rt_sigframe_ia32 __user *frame;
304	void __user *restorer;
305	void __user *fp = NULL;
 
306
307	/* unsafe_put_user optimizes that into a single 8 byte store */
308	static const struct {
309		u8 movl;
310		u32 val;
311		u16 int80;
312		u8  pad;
313	} __attribute__((packed)) code = {
314		0xb8,
315		__NR_ia32_rt_sigreturn,
316		0x80cd,
317		0,
318	};
319
320	frame = get_sigframe(ksig, regs, sizeof(*frame), &fp);
321
322	if (!user_access_begin(frame, sizeof(*frame)))
323		return -EFAULT;
324
325	unsafe_put_user(sig, &frame->sig, Efault);
326	unsafe_put_user(ptr_to_compat(&frame->info), &frame->pinfo, Efault);
327	unsafe_put_user(ptr_to_compat(&frame->uc), &frame->puc, Efault);
328
329	/* Create the ucontext.  */
330	if (static_cpu_has(X86_FEATURE_XSAVE))
331		unsafe_put_user(UC_FP_XSTATE, &frame->uc.uc_flags, Efault);
332	else
333		unsafe_put_user(0, &frame->uc.uc_flags, Efault);
334	unsafe_put_user(0, &frame->uc.uc_link, Efault);
335	unsafe_compat_save_altstack(&frame->uc.uc_stack, regs->sp, Efault);
 
336
337	if (ksig->ka.sa.sa_flags & SA_RESTORER)
338		restorer = ksig->ka.sa.sa_restorer;
339	else
340		restorer = current->mm->context.vdso +
341			vdso_image_32.sym___kernel_rt_sigreturn;
342	unsafe_put_user(ptr_to_compat(restorer), &frame->pretcode, Efault);
343
344	/*
345	 * Not actually used anymore, but left because some gdb
346	 * versions need it.
347	 */
348	unsafe_put_user(*((u64 *)&code), (u64 __user *)frame->retcode, Efault);
349	unsafe_put_sigcontext32(&frame->uc.uc_mcontext, fp, regs, set, Efault);
350	unsafe_put_user(*(__u64 *)set, (__u64 *)&frame->uc.uc_sigmask, Efault);
351	user_access_end();
 
 
 
352
353	if (__copy_siginfo_to_user32(&frame->info, &ksig->info))
354		return -EFAULT;
355
356	/* Set up registers for signal handler */
357	regs->sp = (unsigned long) frame;
358	regs->ip = (unsigned long) ksig->ka.sa.sa_handler;
359
360	/* Make -mregparm=3 work */
361	regs->ax = sig;
362	regs->dx = (unsigned long) &frame->info;
363	regs->cx = (unsigned long) &frame->uc;
364
365	loadsegment(ds, __USER32_DS);
366	loadsegment(es, __USER32_DS);
367
368	regs->cs = __USER32_CS;
369	regs->ss = __USER32_DS;
370
371	return 0;
372Efault:
373	user_access_end();
374	return -EFAULT;
375}