1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
kosaki 2011-07-06 12:29:09 +00:00
parent c454ee6c9f
commit 032e56fbd6
2 changed files with 14 additions and 3 deletions

View file

@ -1,3 +1,11 @@
Wed Jul 6 21:24:53 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* 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]
Wed Jul 6 21:23:38 2011 KOSAKI Motohiro <kosaki.motohiro@gmail.com>
* cont.c (fiber_machine_stack_alloc): use MAP_STACK if it's provided.

9
cont.c
View file

@ -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