Re: [PATCH] i386: fix stack alignment for signal handlers (ia64)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tony,

Luck, Tony wrote:
I've just realized that this patch probably should also be applied for the ia64 arch - but I cannot test it due to lack of hardware.

Markus,

Sorry for not picking this up sooner.  Do you have a simple test
program that I can run (I do have the hardware :-)

I've attached the test program I had originally sent to LKML to demonstrate the problem. The correct i386 output would be some alignment like this (and I expect that currently the sighandler is mis-aligned on IA64):

in main      : sp = 0xff9d0140
in test      : sp = 0xff9d0130
in sighandler: sp = 0xff9cfe30
All done.

~Markus



-Tony



--
Markus Oberhumer, <markus@xxxxxxxxxxxxx>, http://www.oberhumer.com/
/* test signal stack alignment (sigframe)
 *
 * a small user-space demo program to show that the signal stack
 * is currently mis-aligned on i386-linux
 *
 * Markus F.X.J. Oberhumer <markus@xxxxxxxxxxxxx>
 */

#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

void sighandler(int);
void test(void);

volatile unsigned long sp = 0;

/* assembler prologue code that stores the stack pointer into 'sp'
 * and then jumps to the real function */
#if defined(__i386__)
asm(
    ".text\n"
"sighandler:\n"
    "lea    4(%esp), %eax\n"
    "mov    %eax, (sp)\n"
    "jmp    do_sighandler\n"
"test:\n"
    "lea    4(%esp), %eax\n"
    "mov    %eax, (sp)\n"
    "jmp    do_test\n"
".globl main\n"
"main:\n"
    "lea    4(%esp), %eax\n"
    "mov    %eax, (sp)\n"
    "jmp    do_main\n"
);
#elif defined(__x86_64__)
asm(
    ".text\n"
"sighandler:\n"
    "lea    8(%rsp), %rax\n"
    "mov    %rax, sp(%rip)\n"
    "jmp    do_sighandler\n"
"test:\n"
    "lea    8(%rsp), %rax\n"
    "mov    %rax, sp(%rip)\n"
    "jmp    do_test\n"
".globl main\n"
"main:\n"
    "lea    8(%rsp), %rax\n"
    "mov    %rax, sp(%rip)\n"
    "jmp    do_main\n"
);
#else
#error "arch not supported - please insert your code here"
#endif


void do_sighandler(void)
{
    printf("in sighandler: sp = 0x%lx\n", sp);
}

void do_test(void)
{
    printf("in test      : sp = 0x%lx\n", sp);
    signal(SIGUSR1, sighandler);
    raise(SIGUSR1);
}

int do_main(void)
{
    printf("in main      : sp = 0x%lx\n", sp);
    test();
    printf("All done.\n");
    return 0;
}


/* vim:set ts=4 et: */

[Index of Archives]     [Linux Kernel]     [Sparc Linux]     [DCCP]     [Linux ARM]     [Yosemite News]     [Linux SCSI]     [Linux x86_64]     [Linux for Ham Radio]

  Powered by Linux