process layout and function calls
play

Process Layout and Function Calls CS 161 Spring 2016 January 25, - PowerPoint PPT Presentation

Process Layout and Function Calls CS 161 Spring 2016 January 25, 2016 1 / 7 Process Layout in Memory 0xc0000000 Stack Stack high address grows towards decreasing addresses. dynamic is initialized at run-time . growth


  1. Process Layout and Function Calls CS 161 – Spring 2016 January 25, 2016 1 / 7

  2. Process Layout in Memory 0xc0000000 ◮ Stack Stack high address ◮ grows towards decreasing addresses. dynamic ◮ is initialized at run-time . growth ◮ Heap ◮ grow towards increasing addresses. Heap ◮ is initialized at run-time . ◮ BSS section BSS ◮ size fixed at compile-time . Data ◮ is initialized at run-time . low address Text ◮ was grouped into Data in CS61C. 0x08048000 ◮ Data section ◮ is initialized at compile-time . ◮ Text section ◮ holds the program instructions (read-only). Process Layout 2 / 7

  3. Process Layout in Memory 0xc0000000 ◮ Stack Stack high address ◮ grows towards decreasing addresses. dynamic ◮ is initialized at run-time . growth ◮ Heap ◮ grow towards increasing addresses. Heap ◮ is initialized at run-time . ◮ BSS section BSS ◮ size fixed at compile-time . Data ◮ is initialized at run-time . low address Text ◮ was grouped into Data in CS61C. 0x08048000 ◮ Data section uninitialized variables ◮ is initialized at compile-time . initialized variables ◮ Text section ◮ holds the program instructions (read-only). Process Layout 2 / 7

  4. IA-32 ◮ Limited Number of Registers ◮ IA-32 has 6 (%eax, %edx, %ecx, %ebx, %esi, %edi) ◮ This means lots of stack operations! ◮ Operand Directions ◮ IA-32: mov src dst ◮ Memory operations ◮ Very common to see push/pop/mov in IA-32 ◮ We’ll see more of this later ◮ The list goes on! IA-32 3 / 7

  5. IA-32 Registers Use IA32 Notes Program Counter %eip Can not be referenced directly Stack Pointer %esp Frame Pointer %ebp Return Value (32 bit) %eax %eax not used solely for RV Register Terminology SFP saved frame pointer : saved %ebp on the stack OFP old frame pointer : old %ebp from the previous stack frame RIP return instruction pointer : return address on the stack IA-32 4 / 7

  6. Function Calls void foo(int a, int b, int c) { int bar[2]; char qux[3]; bar[0] = ’A’; qux[0] = 0x42; } int main(void) { int i = 1; foo(1, 2, 3); return 0; } Function Calls 5 / 7

  7. Function Calls in Assembler int main(void) ebp { int i = 1; esp foo(1, 2, 3); return 0; } main: pushl %ebp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  8. Function Calls in Assembler int main(void) ebp { int i = 1; foo(1, 2, 3); esp sfp return 0; } main: pushl %ebp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  9. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); esp + ebp sfp return 0; } main: pushl %ebp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  10. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; esp } main: pushl %ebp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  11. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 esp } main: pushl %ebp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  12. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 } 3 main: 2 pushl %ebp 1 esp movl %esp,%ebp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  13. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip esp subl $4,%esp movl $1,-4(%ebp) pushl $3 pushl $2 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  14. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ebp sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip esp subl $12,%esp movl $65,-8(%ebp) movb $66,-12(%ebp) leave ret Function Calls 6 / 7

  15. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ebp sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp esp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) leave ret Function Calls 6 / 7

  16. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ofp (m) sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp esp + ebp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) leave ret Function Calls 6 / 7

  17. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ofp (m) sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp ebp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) leave esp ret Function Calls 6 / 7

  18. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ofp (m) sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp ebp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) 00 00 00 41 leave esp ret Function Calls 6 / 7

  19. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ofp (m) sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp ebp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) 00 00 00 41 leave 42 esp ret Function Calls 6 / 7

  20. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ofp (m) sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip subl $12,%esp esp + ebp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) 00 00 00 41 leave: leave movl %ebp,%esp 42 popl %ebp ret Function Calls 6 / 7

  21. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ebp sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 movl %esp,%ebp rip esp subl $12,%esp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) 00 00 00 41 leave: leave movl %ebp,%esp 42 popl %ebp ret Function Calls 6 / 7

  22. Function Calls in Assembler void foo(int a, int b, int c) { ofp int bar[2]; char qux[3]; bar[0] = ’A’; ebp sfp qux[0] = 0x42; 1 } 3 foo: 2 pushl %ebp 1 esp movl %esp,%ebp rip subl $12,%esp sfp movl $65,-8(%ebp) movb $66,-12(%ebp) 00 00 00 41 ret: leave popl %eip 42 ret Function Calls 6 / 7

  23. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 } 3 main: 2 pushl %ebp 1 esp movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  24. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 esp } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  25. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); ebp sfp return 0; 1 esp } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  26. Function Calls in Assembler int main(void) ofp { int i = 1; foo(1, 2, 3); esp + ebp sfp return 0; 1 } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  27. Function Calls in Assembler int main(void) ebp { int i = 1; esp foo(1, 2, 3); sfp return 0; 1 } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

  28. Function Calls in Assembler int main(void) ebp { esp int i = 1; (rip) foo(1, 2, 3); sfp return 0; 1 } 3 main: 2 pushl %ebp 1 movl %esp,%ebp rip subl $4,%esp sfp movl $1,-4(%ebp) pushl $3 00 00 00 41 pushl $2 42 pushl $1 call foo addl $12,%esp xorl %eax,%eax leave ret Function Calls 6 / 7

Recommend


More recommend