linux-mips
[Top] [All Lists]

Re: [PATCH 7/7] Allow unwind_stack() to return ra for leaf function

To: vagabon.xyz@gmail.com
Subject: Re: [PATCH 7/7] Allow unwind_stack() to return ra for leaf function
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
Date: Wed, 02 Aug 2006 00:48:48 +0900 (JST)
Cc: ralf@linux-mips.org, linux-mips@linux-mips.org
In-reply-to: <1154424439969-git-send-email-vagabon.xyz@gmail.com>
Original-recipient: rfc822;linux-mips@linux-mips.org
References: <11544244373398-git-send-email-vagabon.xyz@gmail.com> <1154424439969-git-send-email-vagabon.xyz@gmail.com>
Sender: linux-mips-bounce@linux-mips.org
On Tue,  1 Aug 2006 11:27:17 +0200, Franck Bui-Huu <vagabon.xyz@gmail.com> 
wrote:
> Since get_frame_info() is more robust, unwind_stack() can
> returns ra value for leaf functions.

I think it is still fragile.  The get_frame_info() might misdetect
nested function as leaf.  For example, I can craft this code:

int nestfunc(int arg)
{
        if (arg)
                return 0;
        func();
        return 1;
}

        .set noreorder
nestfunc:
        beqz    a0, 1f
         nop
        jr      ra
         move   v0, zero
1:
        addiu   sp, sp, -24
        sw      ra, 16(sp)
        jal     func
         nop
        lw      ra, 16(sp)
        li      v0, 1
        jr      ra
         addiu  sp, sp, 24

(Though it seems a bit artificial, who believe gcc never do it same?)

The get_frame_info() will think this is a leaf.  With your patch,
unwind_stack() might fall into endless loop at worst (if the "func"
was leaf and an exception happened in the "func").

I think you should ensure unwind_stack() never use regs->regs[31]
elsewhere than top of the stack.

---
Atsushi Nemoto

<Prev in Thread] Current Thread [Next in Thread>