Im having a hard time trying to figure out what of the to following options is the second line of code doing and why.
- Substracting 1xsizeof(t_stackFrame) to the memory direction of baseStack
- Subtracting 1 to the memory direction of baseStack
- Subtracting 1xsizeof(t_stackFrame*) (equals to 8 bytes in x64) to the memory direction of baseStack
Here's the code:
static void* initializeStackFrame(void* entryPoint, void* baseStack) {
t_stackFrame* frame = (t_stackFrame*)baseStack - 1;
frame->gs = 0x001;
frame->fs = 0x002;
frame->r15 = 0x003;
frame->r14 = 0x004;
frame->r13 = 0x005;
frame->r12 = 0x006;
frame->r11 = 0x007;
frame->r10 = 0x008;
frame->r9 = 0x009;
frame->r8 = 0x00A;
frame->rsi = 0x00B;
frame->rdi = 0x00C;
frame->rbp = 0x00D;
frame->rdx = 0x00E;
frame->rcx = 0x00F;
frame->rbx = 0x010;
frame->rax = 0x011;
frame->rip = (uint64_t)entryPoint;
frame->cs = 0x008;
frame->eflags = 0x202;
frame->rsp = (uint64_t) & (frame->base);
frame->ss = 0x000;
frame->base = 0x000;
return (void*)(frame);
}