CS208 Introduction to Computer Systems Wednesday, 22 Feb 2023 + What happens when a function gets called? - Answer expressed in terms of - registers - the system stack (i.e., the portion of memory pointed to by rsp) rip -- points to the next instruction to execute rsp -- points to the top of the stack - Before: caller puts parameters into registers (rdi, rsi,...) - Before: rip points to some callq instruction in caller ... - During callq - push rip (address of the instruction immediately after callq) - set rip = address of the function - The function pushes the values of registers that it's going to use so the old values can be restored before the function returns - The function subtracts some offset from rsp to make room on the stack for local variables, etc. + What happens when a function returns? - set up rax as the return value - add that offset back to rsp to deallocate the stack frame space - pop saved registers - retq - jumps back to the return address (pop return address from stack into rip) + Buffer overflow assignment walkthrough To do: - Read the assignment, take notes - How can I set a break point where I want it? (objdump -d ctarget > ctarget.d) - What's on the stack when Gets gets called?