Bug #4983

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

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

[ruby-dev:44043]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI
Category:core
Target version:1.9.3
ruby -v:trunk Backport:

Description

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

static VALUE*
fibermachinestackalloc(sizet size)
{
VALUE ptr;
(snip)
}
else {
void *page;
STACKGROWDIR_DETECTION;
ptr = (VALUE
)mmap(NULL, size, PROTREAD | PROTWRITE, MAPPRIVATE | MAPANON, -1, 0);
if (ptr == (VALUE*)(SIGNEDVALUE)-1) {
rb
raise(rbeFiberError, "can't alloc machine stack to fiber");
}
page = ptr + STACK
DIRUPPER((size - RBPAGESIZE) / sizeof(VALUE), 0);
if (mprotect(page, RB
PAGESIZE, PROTREAD | PROTWRITE) < 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 3 years ago

  • cont.c (fibermachinestackalloc): fix mprotect misuse. A stack guard page should have PROTNONE.
  • cont.c (fiberinitializemachinestackcontext): th->machinestackmaxsize shouldn't be included guard pages size. [Bug #4983]

History

#1 Updated by Motohiro KOSAKI almost 3 years ago

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

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

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

#2 Updated by Motohiro KOSAKI almost 3 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 (fibermachinestackalloc): fix mprotect misuse. A stack guard page should have PROTNONE.
  • cont.c (fiberinitializemachinestackcontext): th->machinestackmaxsize shouldn't be included guard pages size. [Bug #4983]

Also available in: Atom PDF