Bug #4983

Fiberのガードページの設定が間違ってる

Added by Motohiro KOSAKI almost 4 years ago. Updated almost 4 years ago.

[ruby-dev:44043]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI
ruby -v:trunk Backport:

Description

以下の関数でスタックのアロケーションとガードページの設定をしていますが、ガードページがPROT_READ|PROT_WRITEなのは
なにかの間違いだと思います。あとで直しておきます。

static VALUE*
fiber_machine_stack_alloc(size_t size)
{
VALUE ptr;
(snip)
}
else {
void *page;
STACK_GROW_DIR_DETECTION;
ptr = (VALUE
)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
if (ptr == (VALUE*)(SIGNED_VALUE)-1) {
rb_raise(rb_eFiberError, "can't alloc machine stack to fiber");
}
page = ptr + STACK_DIR_UPPER((size - RB_PAGE_SIZE) / sizeof(VALUE), 0);
if (mprotect(page, RB_PAGE_SIZE, PROT_READ | PROT_WRITE) < 0) { // ここ!
rb_raise(rb_eFiberError, "mprotect failed");


Related issues

Related to Ruby trunk - Bug #3781: FIBER_USE_NATIVE が有効だと落ちるスクリプトがある Closed 09/02/2010
Related to Ruby trunk - Bug #1813: Threading seg fault (1.9.1-p129 Linux/Mac) Closed 07/24/2009

Associated revisions

Revision 32421
Added by Motohiro KOSAKI almost 4 years ago

  • 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]

Revision 32421
Added by Motohiro KOSAKI almost 4 years ago

  • 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]

History

#1 Updated by Motohiro KOSAKI almost 4 years ago

別件でささださんに質問があるのですが、ファイバーのスタックサイズは

#define FIBER_MACHINE_STACK_ALLOCATION_SIZE (0x10000 / sizeof(VALUE))

のように sizeof(VALUE)での割り算を入れることにより、sizeof(VALUE)の倍数を保とうとしている痕跡がありますが、
ガードページ用に1ページ食われてしまうので、結局、真のスタックサイズは sizeof(VALUE)の倍数である保証は
なくなってしまっています。
これは問題ないでしょうか?それとも意図を誤読してます?

#2 Updated by Motohiro KOSAKI almost 4 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32421.
Motohiro, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • 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]

Also available in: Atom PDF