Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1JFWyK-0001Ku-Va for mharc-grub-devel@gnu.org; Thu, 17 Jan 2008 10:48:05 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JFWyJ-0001KU-1s for grub-devel@gnu.org; Thu, 17 Jan 2008 10:48:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JFWyH-0001Jo-JB for grub-devel@gnu.org; Thu, 17 Jan 2008 10:48:02 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JFWyH-0001Jk-BZ for grub-devel@gnu.org; Thu, 17 Jan 2008 10:48:01 -0500 Received: from nz-out-0506.google.com ([64.233.162.228]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JFWyH-0004Rf-16 for grub-devel@gnu.org; Thu, 17 Jan 2008 10:48:01 -0500 Received: by nz-out-0506.google.com with SMTP id f1so526214nzc.21 for ; Thu, 17 Jan 2008 07:47:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=zytnD4gKhI1gJRiTubtspY4YFXkhUnjge6w6DeTZCZg=; b=CPnpwxx3Jl7c0v6XO4XkulEtQoK66O7D5kq32qdNSuZyC0B45/CbMFuHBaa1j8P+ysvgnSQDOwQcf4iQTlD7qTdDzKDaeQVUrm8Ll83cw0yokT06zTQx6FW0eXEC2WTloSAaJ+MlQQmGwQ7RAXgYnwVjwef1GQ7rGsvj8yutuZM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ljdu2ErqXbja5ChA95NYYPE3azigwYAhB8F5+lu5350aItC4q4x+qCv6XSQ1zwg1vzstclKSecVMmbrkxMacoFvnQNk9cqqmhzplbEbQ/UTNB/qvEGd0ZIidzU1gaRVEK2h+QvWTMIU9IjabNXJJgU1bqJLw3U3vCxxt7sc/Q+8= Received: by 10.110.31.5 with SMTP id e5mr1138722tie.37.1200584870757; Thu, 17 Jan 2008 07:47:50 -0800 (PST) Received: by 10.110.20.10 with HTTP; Thu, 17 Jan 2008 07:47:50 -0800 (PST) Message-ID: Date: Thu, 17 Jan 2008 23:47:50 +0800 From: Bean To: "The development of GRUB 2" In-Reply-To: <20080117122130.GB2399@thorin> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20080116230529.GA28677@thorin> <20080117122130.GB2399@thorin> X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: Re: nested functions used by multiboot2 loader corrupt stack X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2008 15:48:03 -0000 On Jan 17, 2008 8:21 PM, Robert Millan wrote: > On Thu, Jan 17, 2008 at 04:15:23PM +0800, Bean wrote: > > > > You need to add NESTED_FUNC_ATTR to nested callback function that use > > local variable. here is the patch: > > Glad to see you found the reason! > > But I don't get it. I see that: > > #define NESTED_FUNC_ATTR __attribute__ ((__regparm__ (2))) > > so does this mean in one of the calls the caller and callee disagreed about > how the third param is passed? > > Also, we have a lot of nested functions without this macro. How does one > distinguish the ones that need it from the ones that don't? Embedded function used %ecx to store the pointer to it's parent's stack. However, the program is compiled using option -mregparm=3, which means it can use up to 3 registry to pass parameter.In grub_elf32_load_segment, there are three parameter elf, phdr and hook, which will take up %eax, %edx and %ecx. The value of %ecx, hook, will be overwritten. Use NESTED_FUNC_ATTR ensure that only the first two parameter will be passed using registry This problem can occur when the following conditions are true: 1, Use embedded function as callback. 2, The embedded function use local variable in it's parent's stack. 3, The embedded function has at least three parameters. -- Bean