summaryrefslogtreecommitdiff
path: root/cont.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-06 12:29:09 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-07-06 12:29:09 +0000
commit032e56fbd66d3dd1aa144a86f4a90b667dcff649 (patch)
treeae8af17a3e89e9d4db55d29fb04b240ab01f9037 /cont.c
parentc454ee6c9fdce8fb558fee0198aea307157ccb23 (diff)
* cont.c (fiber_machine_stack_alloc): fix mprotect misuse. A stack
guard page should have PROT_NONE. * cont.c (fiber_initialize_machine_stack_context): th->machine_stack_maxsize shouldn't be included guard pages size. [Bug #4983][ruby-dev:44043] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'cont.c')
-rw-r--r--cont.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/cont.c b/cont.c
index e46f52c..beaa5c8 100644
--- a/cont.c
+++ b/cont.c
@@ -543,12 +543,15 @@ fiber_machine_stack_alloc(size_t size)
else {
void *page;
STACK_GROW_DIR_DETECTION;
+
ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, FIBER_STACK_FLAGS, -1, 0);
if (ptr == MAP_FAILED) {
rb_raise(rb_eFiberError, "can't alloc machine stack to fiber");
}
+
+ /* guard page setup */
page = ptr + STACK_DIR_UPPER((size - RB_PAGE_SIZE) / sizeof(VALUE), 0);
- if (mprotect(page, RB_PAGE_SIZE, PROT_READ | PROT_WRITE) < 0) {
+ if (mprotect(page, RB_PAGE_SIZE, PROT_NONE) < 0) {
rb_raise(rb_eFiberError, "mprotect failed");
}
}
@@ -572,6 +575,7 @@ fiber_initialize_machine_stack_context(rb_fiber_t *fib, size_t size)
rb_raise(rb_eFiberError, "can't create fiber");
}
}
+ sth->machine_stack_maxsize = size;
#else /* not WIN32 */
ucontext_t *context = &fib->context;
VALUE *ptr;
@@ -584,9 +588,8 @@ fiber_initialize_machine_stack_context(rb_fiber_t *fib, size_t size)
context->uc_stack.ss_size = size;
makecontext(context, rb_fiber_start, 0);
sth->machine_stack_start = ptr + STACK_DIR_UPPER(0, size / sizeof(VALUE));
+ sth->machine_stack_maxsize = size - RB_PAGE_SIZE;
#endif
-
- sth->machine_stack_maxsize = size;
#ifdef __ia64
sth->machine_register_stack_maxsize = sth->machine_stack_maxsize;
#endif