Re: [kvm-unit-tests PATCH 2/2] x86: realmode: use inline asm to get stack pointer

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

 



On Sat, Oct 12, 2019 at 4:59 PM Bill Wendling <morbo@xxxxxxxxxx> wrote:
>
> It's fragile to try to retrieve the stack pointer by taking the address
> of a variable on the stack. For instance, clang reserves more stack
> space than gcc here, indicating that the variable may not be at the
> start of the stack. Instead of relying upon this to work, retrieve the
> "%rbp" value, which contains the value of "%rsp" before stack
> allocation.
>
> Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
> ---
>  x86/realmode.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/x86/realmode.c b/x86/realmode.c
> index cf45fd6..7c89dd1 100644
> --- a/x86/realmode.c
> +++ b/x86/realmode.c
> @@ -518,11 +518,12 @@ extern void retf_imm(void);
>
>  static void test_call(void)
>  {
> -       u32 esp[16];
>         u32 addr;
>
>         inregs = (struct regs){ 0 };
> -       inregs.esp = (u32)esp;
> +
> +       // At this point the original stack pointer is in %ebp.
> +       asm volatile ("mov %%ebp, %0" : "=rm"(inregs.esp));

I don't think we should assume the existence of frame pointers.
Moreover, I think %esp is actually the value that should be saved
here, regardless of how large the current frame is.

>         MK_INSN(call1, "mov $test_function, %eax \n\t"
>                        "call *%eax\n\t");
> --
> 2.23.0.700.g56cf767bdb-goog
>



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux