0

in my system (x86_64), when I'm using GDB, both RBP and RSP point to the same memory address after pushing a new stack frame, therefore I can't reference the end of the stack with the register RSP because it has the same value as RBP. I saw that in other systems the register RSP is used to keep track of the address of the end of the stack, but unfortunately it doesn't work like this in my GDB.

I'm using this little code to test it:

#include <stdio.h>

void test_function(int a, int b, int c, int d) {
    int flag;
    char buffer[10];
 
    flag = 31337;
    buffer[0] = 'A';
}

int main(){
    test_function(1, 2, 3, 4);
}

this is what I get in GDB:

gdb test

Notice that there is also no "sub" operation in assembly for RSP in the function prologue.

So, my question is, is there any other way to access to the end of the stack if I don't have the RSP register?

I'm still a newbie to this, I'm learning all the time, so there are things that maybe I'm ignoring or not understanding.

2
  • I don't think it's a good idea trying to get the value of RSP because it depends on the compiler. If you really want to use it, might be a good idea to write your own function in assembly. I think the compiler isn't subtracting anything because there's no function call inside test_function. Commented Nov 26, 2023 at 5:23
  • "End of stack" has kind of a different meaning when the architecture has the notion of a red zone. You can give gcc the -mno-red-zone option to produce code with more conventional rbp and rsp values, but there will still be an accessible portion of the stack beyond rsp - see this question and its references. Commented Nov 26, 2023 at 15:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.