Код: Выделить всё
#ifdef UEFI
#include "uefi/uefi.h"
#else
#include
#include
#include
#endif
register void* rsp __asm__("rsp");
#define setsp(sp) __asm__("mov %0, %%rsp\n" \
: \
: "r" (sp))
#define getsp(sp) __asm__("mov %%rsp, %0\n" \
: "=r" (sp)\
: )
char* sp;
char* sp2;
char* sp3;
char* sp4;
int setstack(int a)
{
char* oldsp;
etsp(oldsp);
char* stack = malloc(2000);
memcpy(stack + 1000, oldsp, 64);
sp2 = stack + 1000;
setsp(sp2);
getsp(sp3);
printf("rsp in function %p\n", sp3);
printf("register rsp in function %p\n", rsp);
return 0;
}
int main(int argc, char** argv)
{
getsp(sp);
printf("rsp before function %p\n", sp);
printf("register rsp before function %p\n", rsp);
setstack(5);
getsp(sp4);
printf("rsp after function %p\n", sp4);
printf("register rsp after function %p\n", rsp);
while(1);
return 0;
}
Код: Выделить всё
cc -fomit-frame-pointer test.c -o test
Код: Выделить всё
rsp before function 0x7fff1f989a70
register rsp before function 0x7fff1f989a70
rsp in function 0x565084e6ba98
register rsp in function 0x565084e6ba98
rsp after function 0x565084e6bac8
register rsp after function 0x565084e6bac8
В posix-uefi я компилирую это следующим образом:
Код: Выделить всё
clang -Wall -Wextra --ansi -O2 -DUEFI=1 -DELF64 -Wno-unused-parameter -fomit-frame-pointer -I./include -I/usr/include/x86_64-linux-gnu/ -fshort-wchar -fno-strict-aliasing -ffreestanding -fno-stack-protector -fno-stack-check -I. -I./uefi -I/usr/include -I/usr/include/efi -I/usr/include/efi/protocol -I/usr/include/efi/x86_64 -D__x86_64__ -DHAVE_USE_MS_ABI -mno-red-zone --target=x86_64-pc-win32-coff -Wno-builtin-requires-header -Wno-in compatible-library-redeclaration -Wno-long-long -c test.c -o test.o
lld -flavor link -subsystem:efi_application -nodefaultlib -dll -entry:uefi_init uefi/*.o test.o -out:testsp.efi
Код: Выделить всё
rsp before function 000000007fefa3a0
register rsp before function 000000007fefa3a0
rsp in function 000000007fefa3a0
register rsp in function 000000007df6b480
rsp after function 000000007fefa3a0
register rsp after function 000000007df6b480
Подробнее здесь: https://stackoverflow.com/questions/791 ... iffer-from