正在显示
1 个修改的文件
包含
16 行增加
和
0 行删除
@@ -55,12 +55,28 @@ int _st_randomize_stacks = 0; | @@ -55,12 +55,28 @@ int _st_randomize_stacks = 0; | ||
55 | 55 | ||
56 | static char *_st_new_stk_segment(int size); | 56 | static char *_st_new_stk_segment(int size); |
57 | 57 | ||
58 | +/** | ||
59 | +The below comments is by winlin: | ||
60 | +The stack memory struct: | ||
61 | + | REDZONE | stack | extra | REDZONE | | ||
62 | + +---------+------------------------+---------+---------+ | ||
63 | + | 4k | | 4k/0 | 4k | | ||
64 | + +---------+------------------------+---------+---------+ | ||
65 | + vaddr bottom top | ||
66 | +When _st_randomize_stacks is on, by st_randomize_stacks(), | ||
67 | +the bottom and top will random movided in the extra: | ||
68 | + long offset = (random() % extra) & ~0xf; | ||
69 | + ts->stk_bottom += offset; | ||
70 | + ts->stk_top += offset; | ||
71 | +Both REDZONE are protected by mprotect when DEBUG is on. | ||
72 | +*/ | ||
58 | _st_stack_t *_st_stack_new(int stack_size) | 73 | _st_stack_t *_st_stack_new(int stack_size) |
59 | { | 74 | { |
60 | _st_clist_t *qp; | 75 | _st_clist_t *qp; |
61 | _st_stack_t *ts; | 76 | _st_stack_t *ts; |
62 | int extra; | 77 | int extra; |
63 | 78 | ||
79 | + // TODO: WINLIN: remove the stack reuse. | ||
64 | for (qp = _st_free_stacks.next; qp != &_st_free_stacks; qp = qp->next) { | 80 | for (qp = _st_free_stacks.next; qp != &_st_free_stacks; qp = qp->next) { |
65 | ts = _ST_THREAD_STACK_PTR(qp); | 81 | ts = _ST_THREAD_STACK_PTR(qp); |
66 | if (ts->stk_size >= stack_size) { | 82 | if (ts->stk_size >= stack_size) { |
-
请 注册 或 登录 后发表评论