ruby-changes:20373
From: kosaki <ko1@a...>
Date: Wed, 6 Jul 2011 21:29:16 +0900 (JST)
Subject: [ruby-changes:20373] kosaki:r32421 (trunk): * cont.c (fiber_machine_stack_alloc): fix mprotect misuse. A stack
kosaki 2011-07-06 21:29:09 +0900 (Wed, 06 Jul 2011) New Revision: 32421 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32421 Log: * 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] Modified files: trunk/ChangeLog trunk/cont.c Index: ChangeLog =================================================================== --- ChangeLog (revision 32420) +++ ChangeLog (revision 32421) @@ -1,3 +1,11 @@ +Wed Jul 6 21:24:53 2011 KOSAKI Motohiro <kosaki.motohiro@g...> + + * 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@g...> * cont.c (fiber_machine_stack_alloc): use MAP_STACK if it's provided. Index: cont.c =================================================================== --- cont.c (revision 32420) +++ cont.c (revision 32421) @@ -543,12 +543,15 @@ 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 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/