Issue #2258 has been updated by Suraj Kurapati.

File 0001-make-SET_STACK_END-macro-respect-rb_thread_t.machine.patch added

Hi,

The root cause of the problem of gc_mark_locations() processing 
(and corrupting) a portion of the SysV context's stack space was
the SET_STACK_END macro.  It was blindly setting machine_stack_end
without respecting the machine_stack_maxsize limit in rb_thread_t.

I am attaching a patch which solves this problem.  I ran `make test`
after applying this patch and all tests pass successfully, but it
needs to be tested on more architectures (64-bit and opposite stack 
grow direction):

PASS all 949 tests
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./tool/runruby.rb --extout=.ext  -- "./bootstraptest/runner.rb" --ruby="ruby"  ./KNOWNBUGS.rb
2009-10-24 11:23:47 -0700
Driver is ruby 1.9.2dev (2009-10-23 trunk 25426) [i686-linux]
Target is ruby 1.9.2dev (2009-10-23 trunk 25426) [i686-linux]

With this patch, the ruby-ucontext-full.tgz example is able to
proceed further --- but it still does not complete successfully.
There still seems to be some amount of memory corruption occuring
at the new point of failure (see below).

Notice the fname parameter in some of these stack frames; the
"`\266k\be" in "`\266k\be/sun/app/ruby/lib/ruby/1.9.1/date.rb"
should really be "/home".

I will debug this memory corruption now and try to make the
ruby-ucontext-full.tgz example run successfully to completion.

Thanks for your consideration.

###############################################################
# new point of failure for Kernel#require inside rb_protect()
###############################################################

Program received signal SIGSEGV, Segmentation fault.
0x080abc85 in parser_yyerror (parser=0x86b94a0, msg=0x86018c0 "syntax error, unexpected $end, expecting keyword_end") at parse.y:4897
(gdb) bt
#0  0x080abc85 in parser_yyerror (parser=0x86b94a0, msg=0x86018c0 "syntax error, unexpected $end, expecting keyword_end") at parse.y:4897
#1  0x080ab651 in ruby_yyparse (parser=0x86b94a0) at parse.c:10412
#2  0x080ac10f in yycompile0 (arg=141268128, tracing=0) at parse.y:5009
#3  0x08156601 in ruby_suppress_tracing (func=0x80ac00c <yycompile0>, arg=141268128, always=1) at thread.c:4031
#4  0x080ac261 in yycompile (parser=0x86b94a0, f=0x86b9428 "`\266k\be/sun/app/ruby/lib/ruby/1.9.1/date.rb", line=1) at parse.y:5035
#5  0x080ac686 in rb_parser_compile_file (vparser=140736600, f=0x86b9428 "`\266k\be/sun/app/ruby/lib/ruby/1.9.1/date.rb", file=140736580, start=1) at parse.y:5164
#6  0x080f0d33 in load_file_internal (arg=140517824) at ruby.c:1582
#7  0x08064521 in rb_ensure (b_proc=0x80f0783 <load_file_internal>, data1=140517824, e_proc=0x80f0dc2 <restore_lineno>, data2=1) at eval.c:695
#8  0x080f0e29 in load_file (parser=140736600, fname=0x86b9428 "`\266k\be/sun/app/ruby/lib/ruby/1.9.1/date.rb", script=0, opt=0x86021f8) at ruby.c:1610
#9  0x080f0e63 in rb_load_file (fname=0x86b9428 "`\266k\be/sun/app/ruby/lib/ruby/1.9.1/date.rb") at ruby.c:1618
#10 0x080659d1 in rb_load_internal (fname=140736800, wrap=0) at load.c:289
#11 0x080664e7 in rb_require_safe (fname=140737040, safe=0) at load.c:582
#12 0x08065d81 in rb_f_require (obj=140777820, fname=140737060) at load.c:439
#13 0x0813f027 in call_cfunc (func=0x8065d67 <rb_f_require>, recv=140777820, len=1, argc=1, argv=0xb7d76024) at vm_insnhelper.c:292
#14 0x0813f9be in vm_call_cfunc (th=0x8611290, reg_cfp=0xb7df5f84, num=1, recv=140777820, blockptr=0x0, flag=8, me=0x868f058) at vm_insnhelper.c:386
#15 0x0813fec9 in vm_call_method (th=0x8611290, cfp=0xb7df5f84, num=1, blockptr=0x0, flag=8, id=8456, me=0x868f058, recv=140777820) at vm_insnhelper.c:511
#16 0x08144322 in vm_exec_core (th=0x8611290, initial=0) at insns.def:994
#17 0x0814e800 in vm_exec (th=0x8611290) at vm.c:1117
#18 0x0814ee42 in rb_iseq_eval (iseqval=140737760) at vm.c:1327
#19 0x08065a30 in rb_load_internal (fname=140739020, wrap=0) at load.c:293
#20 0x080664e7 in rb_require_safe (fname=140739380, safe=0) at load.c:582
#21 0x0806663b in rb_require (fname=0x8182e1e "./hello.rb") at load.c:618
#22 0x08064451 in rb_protect (proc=0x80665e5 <rb_require>, data=135802398, state=0x8603244) at eval.c:670
#23 0x0805d09f in ruby_context_body_require (file=0x8182e1e "./hello.rb") at main.c:38
#24 0x0805d282 in ruby_context_body () at main.c:93
#25 0xb7e3303b in makecontext () from /lib/libc.so.6
#26 0x08203140 in ?? ()
#27 0x00000000 in ?? ()
----------------------------------------
http://redmine.ruby-lang.org/issues/show/2258

----------------------------------------
http://redmine.ruby-lang.org