Skip to content

Commit

Permalink
docs and diagram for exec_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 3, 2015
1 parent 6e27de4 commit 2348b72
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions exec_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,35 @@
#include <string.h>
#include "jv_alloc.h"

/*
* The stack is a directed forest of variably sized blocks. Each block has a
* "next" block which is at a higher memory address, or 0 if the block has no
* "next" block. More than one block may have no "next" block. A block may be
* the "next" block of more than one other block. Pushed blocks are added at
* the low-address end of the stack.
*
* Stack pointers are negative integers that are offsets relative to "mem_end",
* the end of the allocated region. The stack "bound" is the stack pointer of
* the last block that would be able to fit in the currently allocated region.
* The stack "limit" is the stack pointer of the last block currently in the
* stack. The stack pointer of the "next" block is stored directly below each
* block.
*
* <- mem_end = 0x100
* 0xF8 +------------+
* 0xF0 | |
* 0xE8 +------------+ <- stack_ptr1 = -0x18
* 0xE0 next = 0
* 0xD8 +------------+
* 0xD0 | |
* 0xC8 | |
* 0xC0 +------------+ <- stack_ptr2 = limit = -0x40
* 0xB8 next = -0x18
* 0xB0
* 0xA8 <- bound = -0x58
* 0xA0
*/

struct determine_alignment {
char x;
union { int i; double d; uint64_t u64; size_t sz; void* ptr; } u;
Expand Down

0 comments on commit 2348b72

Please sign in to comment.