From: Suraj Kurapati Date: 2009-10-24T02:21:52+09:00 Subject: [ruby-core:26257] [Bug #2258] Kernel#require inside rb_require() inside rb_protect() inside SysV context fails Issue #2258 has been updated by Suraj Kurapati. Hi, I ran the ruby-ucontext-full.tgz example on Ruby @ SVN trunk in a debugger and found that the real problem was being hidden by a call to rb_longjmp(). Below is the stack trace of the real problem, just before the long jump is executed. The real problem is that the "stdin" value passed from Inito_IO() to prep_stdio() is becoming corrupted somehow: (gdb) f #1 0x0808b2e4 in Init_IO () at io.c:9785 (gdb) p stdin $3 = (struct _IO_FILE *) 0xb7f3b420 (gdb) down #0 prep_stdio (f=0x8213008, fmode=1, klass=136569860, path=0x81860bd "") at io.c:6267 Notice that stdin is 0xb7f3b420 inside Init_IO(), but inside prep_stdio() its value is 0x8213008. This can only mean *one thing*: the stack pointer in Init_IO() is radically different from the stack pointer in prep_stdio(), and the arguments for the function call to prep_stdio() are being placed at a different stack address than what prep_stdio() is reading from, as illustrated in this pseudo-assembly code: Init_IO(): stack.push stdin # 0xb7f3b420 (correct value) stack.push fmode stack.push klass stack.push path stack.push program_counter + size_of_machine_instruction jump prep_stdio prep_stdio(): # PROBLEM: stack pointer is wrong! return_address = stack.pop path = stack.pop klass = stack.pop fmode = stack.pop stdin = stack.pop # 0x8213008 (wrong value!) Any suggestions? Thanks for your consideration. ############################################################### # The full backtrace before longjmp() is executed: ############################################################### (gdb) bt full #0 0xb7e23201 in siglongjmp () from /lib/libc.so.6 No symbol table info available. #1 0x08063e73 in rb_longjmp (tag=6, mesg=136568440) at eval.c:425 at = 136588340 e = 136568440 th = 0x8213290 file = 0x0 line = 0 #2 0x08063eaa in rb_exc_raise (mesg=136568440) at eval.c:434 No locals. #3 0x08061866 in rb_raise (exc=136570260, fmt=0x8185657 "closed stream") at error.c:1150 args = 0x8205108 "h\275'\b\264\336#\b\b0!\b\001" mesg = 136568460 #4 0x0807a6e2 in rb_io_check_closed (fptr=0x827bd68) at io.c:248 No locals. #5 0x08085044 in prep_stdio (f=0x8213008, fmode=1, klass=136569860, path=0x81860bd "") at io.c:6267 fptr = 0x827bd68 io = 136568500 #6 0x0808b2e4 in Init_IO () at io.c:9785 rb_cARGF = 136570780 #7 0x0807a453 in rb_call_inits () at inits.c:43 No locals. #8 0x08063401 in ruby_init () at eval.c:59 _th = 0x8213290 _tag = {buf = {{__jmpbuf = {136323376, 0, 0, 136335960, -891095361, -2044316993}, __mask_was_saved = 0, __saved_mask = {__val = {134563877, 1, 136335872, 3086940374, 3087005720, 3084878200, 1, 1, 0, 1, 136335864, 3086200820, 136335880, 3085687571, 3086200820, 136335896, 3085687736, 3, 136335880, 8388608, 4294967295, 0, 0, 136335960, 135598991, 8388608, 0, 5, 0, 136335960, 3085266387, 136335960}}}}, tag = 0, retval = 0, prev = 0x0} initialized = 1 state = 0 #9 0x0805d235 in ruby_context_body () at main.c:84 variable_in_this_stack_frame = 0 i = 2 argc = 0 argv = 0x8182bc9 #10 0xb7e3303b in makecontext () from /lib/libc.so.6 No symbol table info available. #11 0x08203140 in ?? () No symbol table info available. #12 0x00000000 in ?? () No symbol table info available. (gdb) ---------------------------------------- http://redmine.ruby-lang.org/issues/show/2258 ---------------------------------------- http://redmine.ruby-lang.org