public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Andrew Fish <afish@apple.com>
To: Laszlo Ersek <lersek@redhat.com>
Cc: Jordan Justen <jordan.l.justen@intel.com>,
	Mike Kinney <michael.d.kinney@intel.com>,
	Liu Yu <pedroa.liu@outlook.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Leif Lindholm <leif.lindholm@linaro.org>
Subject: Re: EmulatorPkg Unix Host Segmentation fault.
Date: Mon, 19 Nov 2018 15:39:02 -0800	[thread overview]
Message-ID: <157B5519-8953-4710-B7E8-20289DBCD7A8@apple.com> (raw)
In-Reply-To: <69b2d50f-3aec-186e-61ae-b8f7ab8f143e@redhat.com>



> On Nov 19, 2018, at 2:12 PM, Laszlo Ersek <lersek@redhat.com> wrote:
> 
> Jordan wrote:
> 
>>>> So, is it safe to adjust rbp? Unknown. It may not be if rbp is not
>>>> used as a frame pointer. Is it safe to *not* adjust rbp and
>>>> potentially allow the old temp ram stack to be used? Unknown.
> 
> Andrew wrote:
> 
>> Looks like OvmfPkg uses SetJump()/LongJump() to change the stack. 
>> 
>>  //
>>  // Use SetJump()/LongJump() to switch to a new stack.
>>  // 
>>  if (SetJump (&JumpBuffer) == 0) {
>> #if defined (MDE_CPU_IA32)
>>    JumpBuffer.Esp = JumpBuffer.Esp + DebugAgentContext.StackMigrateOffset;
>>    JumpBuffer.Ebp = JumpBuffer.Ebp + DebugAgentContext.StackMigrateOffset;
>> #endif    
>> #if defined (MDE_CPU_X64)
>>    JumpBuffer.Rsp = JumpBuffer.Rsp + DebugAgentContext.StackMigrateOffset;
>>    JumpBuffer.Rbp = JumpBuffer.Rbp + DebugAgentContext.StackMigrateOffset;
>> #endif    
>>    LongJump (&JumpBuffer, (UINTN)-1);
>>  }
>> 
>>  SaveAndSetDebugTimerInterrupt (OldStatus);
>> 
>>  return EFI_SUCCESS;
>> }
>> 
>> But given the above code is C code RBP is going to be restored on return. This would seem to imply that the adjusting of the callers RBP is not required? [...]
> 
> The Ebp/Rbp assignments were added in a separate bugfix, namely
> 
>  https://github.com/tianocore/edk2/commit/89796c69d9fd
> 

Laszlo,

This makes sense since as the post-amble when using frame pointers is either:

	addq	$288, %rsp              ## imm = 0x120
	popq	%rbp
	retq

or 

>    0x00000000fffcd42f <+403>:	c9	leaveq
>    0x00000000fffcd430 <+404>:	c3	retq

I've noticed that clang does not seem to be a big fan of the leave function and it adjusts the stack pointer using math rather than using %rbp. 

The stack unwind algorithm implies that the frame point, %rbp in our case, is valid while the function is running. Even for the clang code gen not switching the frame point would break the stack unwind. 

Thanks,

Andrew Fish 



> Laszlo



  reply	other threads:[~2018-11-19 23:40 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-18  4:51 EmulatorPkg Unix Host Segmentation fault Liu Yu
2018-11-18  9:27 ` Jordan Justen
2018-11-18 12:07   ` Liu Yu
2018-11-18 22:37     ` Andrew Fish
2018-11-19  1:13       ` Jordan Justen
2018-11-19 19:16         ` Jordan Justen
2018-11-19 21:22           ` Andrew Fish
2018-11-19 22:12             ` Laszlo Ersek
2018-11-19 23:39               ` Andrew Fish [this message]
2018-11-19 22:29             ` Jordan Justen
2018-11-20  0:54               ` Andrew Fish
2018-11-20  8:57               ` Laszlo Ersek
2019-02-16  7:29 ` Ni, Ray
2019-02-16  7:40 ` Ni, Ray
2019-02-16 20:23   ` Andrew Fish
2019-02-16  7:43 ` Ni, Ray
2019-02-16  8:05   ` Ni, Ray
2019-02-16  9:11     ` Jordan Justen
2019-02-18  2:25       ` Ni, Ray
2019-02-18  2:45         ` Jordan Justen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=157B5519-8953-4710-B7E8-20289DBCD7A8@apple.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox