Creating a new stack for loading a statically linked ELF

Viewed 29

I have been trying to create a loader to load statically linked ELF executables. I must create a stack for the new program before jumping to the entry point of the program. In that process, I created a new memory for the stack using mmap.

uint64_t map =(uint64_t) mmap(NULL , 1024*1024 /*1MB default size of the stack*/ , PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_GROWSDOWN, -1,0);

Then I tried to change the rbp and the rsp to point to the new stack and tried pushing the envp, argv and argc into the stack so that they can be used in the _start function.

asm volatile("mov %0, %%rsp\n\t"

"mov %0, %%rbp\n\t"

"push $0\n\t"

"push %1\n\t" //envp

"push $0\n\t"

"push %2\n\t" //argv

"push $1\n\t" //argc

:

:"r"(map), "r"(envp), "r"(argc)

:"%rsp", "%rbp");

However, there is an error with the compilation process. I guess that it has something to do with modifying the rbp.

Post image Can anyone please help me out with this?

0 Answers
Related