Lecture 002

ISA

x86-64: more register, easier programmer, harder code kernel and debug

x86-64 = neutral generic term (used by academics and OS vendors) AMD64 = AMD’s marketing & technical name EM64T / Intel 64 = Intel’s marketing name for the same architecture x86-64: means "the 64-bit extension of x86 processors/instruction set that are backwards-compatible with 32-bit x86"

x86 / IA32 (32-bit x86 ISA): Means Intel Architecture, 32-bit. We will use this.

General Purpose: %eax, %ebx, %ecx, %edx

Stack

Linux 2.x on IA32 Stack Space. We define bottom as higher number and top as lower number. So "stack grows down to the top"

Linux 2.x on IA32 Stack Space. We define bottom as higher number and top as lower number. So "stack grows down to the top"

%esp (not stored in stack, but hardware register): pointing top most item in the stack (not next avaliable)

"esp" stands for extended stack pointer (extended from 16 bits)

Rowhammer (also written as row hammer or RowHammer) is a computer security exploit that takes advantage of an unintended and undesirable side effect in dynamic random-access memory (DRAM) in which memory cells interact electrically between themselves by leaking their charges, possibly changing the contents of nearby memory rows that were not addressed in the original memory access. (It happens when read and write frequently)

Procedure Control Flow (ie. Function Call)

Instruction has varying number of bytes. Hardware will know how many bytes to expect for the next instruction.

804854e: e8 3d 06 00 00 (call 8048b90 <main>)
8048553: 50             (pushl %eax)
...
8048591: c3             (ret)

This 3d 06 00 00 is relative address while e8 is call. The return address will be 8048553

call:

ret:

Stack Frame

When function call, we store on stack

Stack Frame

Stack Frame

Arguments Store

Arguments Store

Note that we store the first argument closest to return address so that we can know how many arguments in total for functions like printf which takes variable amount of arguments but total number of arguments is defined when we see the first argument.

Stack Frame Setup

Stack Frame Setup

Stack Frame Setup Instructions

Stack Frame Setup Instructions

Note that in image, %ebx is a callee saved register for local variable, and we save that. We don't see %eax because they are caller-save and our caller does not make use of %eax.

Note:

Caller vs. Callee saved register. Caller-saved are considered temporary.

Caller vs. Callee saved register. Caller-saved are considered temporary.

Register %eax holds return value.

Main

Different program does not share virtual memory stack, how do we input arguments argc, argv to main() function? - OS will transfer environment variables on high address, higher than code.

What does return(0) do? - the same as exit(0)

Table of Content