stack pointer of a given ucontext - Aix

This is a discussion on stack pointer of a given ucontext - Aix ; Hi, May I know how to obtain the current stack pointer (i.e. the top of the stack) for a given "ucontext" in AIX? I am not sure if ucontext.uc_stack.ss_sp points to the "current stack pointer". Because in LINUX it does ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: stack pointer of a given ucontext

  1. stack pointer of a given ucontext

    Hi,

    May I know how to obtain the current stack pointer (i.e. the top of
    the stack) for a given "ucontext" in AIX?

    I am not sure if ucontext.uc_stack.ss_sp points to the "current stack
    pointer". Because in LINUX it does not. So, in LINUX I use
    ucontext.uc_mcontext.gregs[REG_ESP] to get the current SP of a given
    ucontext variable.

    If I use a similar mechanism for AIX that is running in Power5
    (ucontext.uc_mcontext.jmp_context.gpr[1]), my program later crashes .I
    think I am accessing a wrong stack pointer value. Is gpr[1] the stack
    pointer in AIX (under Power5)?

    Can someone help me to find the current stack pointer value for a
    ucontext?

    --Ganesh



  2. Re: stack pointer of a given ucontext

    Ganesh writes:

    > May I know how to obtain the current stack pointer (i.e. the top of
    > the stack) for a given "ucontext" in AIX?


    You can answer most of your questions by running a simple test case
    under gdb, and asking it to print $r1, ucontext.uc_stack.ss_sp, etc.

    > I am not sure if ucontext.uc_stack.ss_sp points to the "current stack
    > pointer".


    It doesn't. It points to the low end of the stack region.

    > If I use a similar mechanism for AIX that is running in Power5
    > (ucontext.uc_mcontext.jmp_context.gpr[1]), my program later crashes.


    There is a bug in it ...

    Note that AIX calling convention is different from x86 one.
    In particular (IIRC), *caller* must reserve space for "register
    save area", should callee need to spill any registers to memory.

    Judging by your previous posts to gnu.gcc.help, you might be doing
    stack switching, and you likely didn't do it correctly for AIX.

    > think I am accessing a wrong stack pointer value. Is gpr[1] the stack
    > pointer in AIX (under Power5)?


    Yes.

    > Can someone help me to find the current stack pointer value for a
    > ucontext?


    You may wish to re-read the
    http://catb.org/esr/faqs/smart-questions.html
    you'll likely get better answers.

    Cheers,
    --
    In order to understand recursion you must first understand recursion.
    Remove /-nsp/ for email.

  3. Re: stack pointer of a given ucontext

    >
    > Note that AIX calling convention is different from x86 one.
    > In particular (IIRC), *caller* must reserve space for "register
    > save area", should callee need to spill any registers to memory.
    >
    > Judging by your previous posts to gnu.gcc.help, you might be doing
    > stack switching, and you likely didn't do it correctly for AIX.
    >
    > > think I am accessing a wrong stack pointer value. Is gpr[1] the stack
    > > pointer in AIX (under Power5)?

    >


    Yes. I am tryting to switch stack and I am successfuly in LINUX, but
    not in AIX yet.
    I will try out your suggestions.

+ Reply to Thread