4848#include <asm/sigframe.h>
4949#include <asm/signal.h>
5050
51+ static inline int is_ia32_compat_frame (struct ksignal * ksig )
52+ {
53+ return IS_ENABLED (CONFIG_IA32_EMULATION ) &&
54+ ksig -> ka .sa .sa_flags & SA_IA32_ABI ;
55+ }
56+
57+ static inline int is_ia32_frame (struct ksignal * ksig )
58+ {
59+ return IS_ENABLED (CONFIG_X86_32 ) || is_ia32_compat_frame (ksig );
60+ }
61+
62+ static inline int is_x32_frame (struct ksignal * ksig )
63+ {
64+ return IS_ENABLED (CONFIG_X86_X32_ABI ) &&
65+ ksig -> ka .sa .sa_flags & SA_X32_ABI ;
66+ }
67+
5168#ifdef CONFIG_X86_64
5269/*
5370 * If regs->ss will cause an IRET fault, change it. Otherwise leave it
@@ -223,24 +240,12 @@ do { \
223240/*
224241 * Determine which stack to use..
225242 */
226- static unsigned long align_sigframe (unsigned long sp )
227- {
228- #ifdef CONFIG_X86_32
229- /*
230- * Align the stack pointer according to the i386 ABI,
231- * i.e. so that on function entry ((sp + 4) & 15) == 0.
232- */
233- sp = ((sp + 4 ) & - FRAME_ALIGNMENT ) - 4 ;
234- #else /* !CONFIG_X86_32 */
235- sp = round_down (sp , FRAME_ALIGNMENT ) - 8 ;
236- #endif
237- return sp ;
238- }
239-
240- static void __user *
241- get_sigframe (struct k_sigaction * ka , struct pt_regs * regs , size_t frame_size ,
243+ void __user *
244+ get_sigframe (struct ksignal * ksig , struct pt_regs * regs , size_t frame_size ,
242245 void __user * * fpstate )
243246{
247+ struct k_sigaction * ka = & ksig -> ka ;
248+ int ia32_frame = is_ia32_frame (ksig );
244249 /* Default to using normal stack */
245250 bool nested_altstack = on_sig_stack (regs -> sp );
246251 bool entering_altstack = false;
@@ -249,7 +254,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
249254 unsigned long buf_fx = 0 ;
250255
251256 /* redzone */
252- if (IS_ENABLED ( CONFIG_X86_64 ) )
257+ if (! ia32_frame )
253258 sp -= 128 ;
254259
255260 /* This is the X/Open sanctioned signal stack switching. */
@@ -263,7 +268,7 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
263268 sp = current -> sas_ss_sp + current -> sas_ss_size ;
264269 entering_altstack = true;
265270 }
266- } else if (IS_ENABLED ( CONFIG_X86_32 ) &&
271+ } else if (ia32_frame &&
267272 !nested_altstack &&
268273 regs -> ss != __USER_DS &&
269274 !(ka -> sa .sa_flags & SA_RESTORER ) &&
@@ -273,11 +278,19 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
273278 entering_altstack = true;
274279 }
275280
276- sp = fpu__alloc_mathframe (sp , IS_ENABLED (CONFIG_X86_32 ),
277- & buf_fx , & math_size );
281+ sp = fpu__alloc_mathframe (sp , ia32_frame , & buf_fx , & math_size );
278282 * fpstate = (void __user * )sp ;
279283
280- sp = align_sigframe (sp - frame_size );
284+ sp -= frame_size ;
285+
286+ if (ia32_frame )
287+ /*
288+ * Align the stack pointer according to the i386 ABI,
289+ * i.e. so that on function entry ((sp + 4) & 15) == 0.
290+ */
291+ sp = ((sp + 4 ) & - FRAME_ALIGNMENT ) - 4 ;
292+ else
293+ sp = round_down (sp , FRAME_ALIGNMENT ) - 8 ;
281294
282295 /*
283296 * If we are on the alternate signal stack and would overflow it, don't.
@@ -331,7 +344,7 @@ __setup_frame(struct ksignal *ksig, struct pt_regs *regs)
331344 void __user * restorer ;
332345 void __user * fp = NULL ;
333346
334- frame = get_sigframe (& ksig -> ka , regs , sizeof (* frame ), & fp );
347+ frame = get_sigframe (ksig , regs , sizeof (* frame ), & fp );
335348
336349 if (!user_access_begin (frame , sizeof (* frame )))
337350 return - EFAULT ;
@@ -386,7 +399,7 @@ static int __setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
386399 void __user * restorer ;
387400 void __user * fp = NULL ;
388401
389- frame = get_sigframe (& ksig -> ka , regs , sizeof (* frame ), & fp );
402+ frame = get_sigframe (ksig , regs , sizeof (* frame ), & fp );
390403
391404 if (!user_access_begin (frame , sizeof (* frame )))
392405 return - EFAULT ;
@@ -469,7 +482,7 @@ static int __setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
469482 if (!(ksig -> ka .sa .sa_flags & SA_RESTORER ))
470483 return - EFAULT ;
471484
472- frame = get_sigframe (& ksig -> ka , regs , sizeof (struct rt_sigframe ), & fp );
485+ frame = get_sigframe (ksig , regs , sizeof (struct rt_sigframe ), & fp );
473486 uc_flags = frame_uc_flags (regs );
474487
475488 if (!user_access_begin (frame , sizeof (* frame )))
@@ -572,7 +585,7 @@ static int x32_setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
572585 if (!(ksig -> ka .sa .sa_flags & SA_RESTORER ))
573586 return - EFAULT ;
574587
575- frame = get_sigframe (& ksig -> ka , regs , sizeof (* frame ), & fp );
588+ frame = get_sigframe (ksig , regs , sizeof (* frame ), & fp );
576589
577590 uc_flags = frame_uc_flags (regs );
578591
@@ -742,23 +755,6 @@ unsigned long get_sigframe_size(void)
742755 return max_frame_size ;
743756}
744757
745- static inline int is_ia32_compat_frame (struct ksignal * ksig )
746- {
747- return IS_ENABLED (CONFIG_IA32_EMULATION ) &&
748- ksig -> ka .sa .sa_flags & SA_IA32_ABI ;
749- }
750-
751- static inline int is_ia32_frame (struct ksignal * ksig )
752- {
753- return IS_ENABLED (CONFIG_X86_32 ) || is_ia32_compat_frame (ksig );
754- }
755-
756- static inline int is_x32_frame (struct ksignal * ksig )
757- {
758- return IS_ENABLED (CONFIG_X86_X32_ABI ) &&
759- ksig -> ka .sa .sa_flags & SA_X32_ABI ;
760- }
761-
762758static int
763759setup_rt_frame (struct ksignal * ksig , struct pt_regs * regs )
764760{
0 commit comments