Crash reduced to 13 lines of code

View: New views
5 Messages — Rating Filter:   Alert me  

Crash reduced to 13 lines of code

by Melton, Ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Somebody who knows how to debug FXRuby please help…  The following 13 lines of code will cause a seg fault immediately on Solaris/Ubuntu.  I can’t make it any simpler than this.   The code dies in the garbage collect mark code trying to get the focus window from FXApp (apparently because memory has become corrupted).

Thanks,

Ryan

 

require 'rubygems'

require 'thread'

require 'fox16'

include Fox

 

Thread.new do

  loop do

    GC.start

  end

end

application = FXApp.new("NA", "NA")

application.create

FXMessageBox.warning(FXApp.instance, MBOX_OK, 'Warning!', 'Are you sure?')

application.run  


This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Patch for crashes

by Melton, Ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

I posted the patch to rubyforge here: http://rubyforge.org/tracker/index.php?func=detail&aid=24898&group_id=300&atid=1223

 

Lyle if you could release a new version of FXRuby with this fix, I would really appreciate it.

 

Here is the summary so people don’t have to follow the link:

 

Here the fix, the issue turned out to be very complicated related
to how ruby handles the stack frames of its threads.  In summary,
you can't access stack variables between threads.
FXMessageBox::warning creates the FXMessageBox on the stack.
If the Garbage Collector running in another threads context trys
to access the FXMessageBox, it blows up because the stack values
are no longer in context.  Below is the fix.
 
Add this method to FXRbApp.cpp:
 
FXWindow *FXApp::getFocusWindow() const {
  FXWindow *result=getActiveWindow();
  VALUE value=FXRbGetRubyObj(result,true);
  if(!NIL_P(value)){
    if(result){
      while(result->getFocus()){
        result=result->getFocus();
        }
      }
    return result;
    }
  return NULL;
  }
 
Update markfuncs.cpp FXRbWindow::markfunc with this change:
 
Was:
while(child!=NULL){
 
Is:
while((child!=NULL) && (!(NIL_P(FXRbGetRubyObj(child,
true))))){

 

Thanks,

Ryan

 


From: fxruby-users-bounces@... [mailto:fxruby-users-bounces@...] On Behalf Of Melton, Ryan
Sent: Tuesday, May 12, 2009 1:26 PM
To: fxruby-users@...
Subject: [fxruby-users] Crash reduced to 13 lines of code

 

Somebody who knows how to debug FXRuby please help…  The following 13 lines of code will cause a seg fault immediately on Solaris/Ubuntu.  I can’t make it any simpler than this.   The code dies in the garbage collect mark code trying to get the focus window from FXApp (apparently because memory has become corrupted).

Thanks,

Ryan

 

require 'rubygems'

require 'thread'

require 'fox16'

include Fox

 

Thread.new do

  loop do

    GC.start

  end

end

application = FXApp.new("NA", "NA")

application.create

FXMessageBox.warning(FXApp.instance, MBOX_OK, 'Warning!', 'Are you sure?')


This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Re: Patch for crashes

by Lyle Johnson-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On May 14, 2009, at 11:04 AM, Melton, Ryan wrote:

 
Lyle if you could release a new version of FXRuby with this fix, I would really appreciate it.
 
Here is the summary so people don’t have to follow the link:

<snip>

Add this method to FXRbApp.cpp:
 
FXWindow *FXApp::getFocusWindow() const {
  FXWindow *result=getActiveWindow();
  VALUE value=FXRbGetRubyObj(result,true);
  if(!NIL_P(value)){
    if(result){
      while(result->getFocus()){
        result=result->getFocus();
        }
      }
    return result;
    }
  return NULL;
  }

Was your intent here to replace the version of FXApp::getFocusWindow() that is compiled into the FOX library? Because as it's written you're just going to get duplicate symbols error at link time.

The getFocusWindow() isn't declared as a virtual function in the FXApp class, so we can't override it in the FXRbApp subclass. If the only concern is that the call to FXApp::getFocusWindow() can crash during the GC phase, however, I can probably just apply this patch as a special case in the FXRbApp::markfunc (in markfuncs.cpp). I'll try that and see if it does the trick.

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Re: Patch for crashes

by Melton, Ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Surprisingly, it compiled and worked for me.  I’m thinking the compiler just used this version of getFocusWindow for calls within fox16.so.

 

The problem with only fixing it in markfuncs.cpp is that users could still crash cause a seg fault by doing:

 

app = FXApp.new

 

Thread.new do

  app.focusWindow

end

 

The intent was to override the getFocusWindow function call so as to make sure that the value returned by getActiveWindow internally was valid.

 

I’m not sure why it links without errors… maybe ruby just ignores dynamic linking errors of that kind.

Ryan

 


From: fxruby-users-bounces@... [mailto:fxruby-users-bounces@...] On Behalf Of Lyle Johnson
Sent: Tuesday, May 26, 2009 2:14 PM
To: fxruby-users@...
Subject: Re: [fxruby-users] Patch for crashes

 

 

On May 14, 2009, at 11:04 AM, Melton, Ryan wrote:



 

Lyle if you could release a new version of FXRuby with this fix, I would really appreciate it.

 

Here is the summary so people don’t have to follow the link:

 

<snip>



Add this method to FXRbApp.cpp:

 
FXWindow *FXApp::getFocusWindow() const {
  FXWindow *result=getActiveWindow();
  VALUE value=FXRbGetRubyObj(result,true);
  if(!NIL_P(value)){
    if(result){
      while(result->getFocus()){
        result=result->getFocus();
        }
      }
    return result;
    }
  return NULL;
  }

 

Was your intent here to replace the version of FXApp::getFocusWindow() that is compiled into the FOX library? Because as it's written you're just going to get duplicate symbols error at link time.

 

The getFocusWindow() isn't declared as a virtual function in the FXApp class, so we can't override it in the FXRbApp subclass. If the only concern is that the call to FXApp::getFocusWindow() can crash during the GC phase, however, I can probably just apply this patch as a special case in the FXRbApp::markfunc (in markfuncs.cpp). I'll try that and see if it does the trick.


This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users

Re: Patch for crashes

by Melton, Ryan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.

Unfortunately you will probably get linking errors when you try to statically link FXRuby and FOX together for the windows binary…

Perhaps a local fix in fxmarkfuncs and a local fix in the SWIG wrappers?

 

Ryan

 


From: fxruby-users-bounces@... [mailto:fxruby-users-bounces@...] On Behalf Of Melton, Ryan
Sent: Tuesday, May 26, 2009 2:48 PM
To: fxruby-users@...
Subject: Re: [fxruby-users] Patch for crashes

 

Surprisingly, it compiled and worked for me.  I’m thinking the compiler just used this version of getFocusWindow for calls within fox16.so.

 

The problem with only fixing it in markfuncs.cpp is that users could still crash cause a seg fault by doing:

 

app = FXApp.new

 

Thread.new do

  app.focusWindow

end

 

The intent was to override the getFocusWindow function call so as to make sure that the value returned by getActiveWindow internally was valid.

 

I’m not sure why it links without errors… maybe ruby just ignores dynamic linking errors of that kind.

Ryan

 


From: fxruby-users-bounces@... [mailto:fxruby-users-bounces@...] On Behalf Of Lyle Johnson
Sent: Tuesday, May 26, 2009 2:14 PM
To: fxruby-users@...
Subject: Re: [fxruby-users] Patch for crashes

 

 

On May 14, 2009, at 11:04 AM, Melton, Ryan wrote:

 

 

Lyle if you could release a new version of FXRuby with this fix, I would really appreciate it.

 

Here is the summary so people don’t have to follow the link:

 

<snip>

 

Add this method to FXRbApp.cpp:

 
FXWindow *FXApp::getFocusWindow() const {
  FXWindow *result=getActiveWindow();
  VALUE value=FXRbGetRubyObj(result,true);
  if(!NIL_P(value)){
    if(result){
      while(result->getFocus()){
        result=result->getFocus();
        }
      }
    return result;
    }
  return NULL;
  }

 

Was your intent here to replace the version of FXApp::getFocusWindow() that is compiled into the FOX library? Because as it's written you're just going to get duplicate symbols error at link time.

 

The getFocusWindow() isn't declared as a virtual function in the FXApp class, so we can't override it in the FXRbApp subclass. If the only concern is that the call to FXApp::getFocusWindow() can crash during the GC phase, however, I can probably just apply this patch as a special case in the FXRbApp::markfunc (in markfuncs.cpp). I'll try that and see if it does the trick.


This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.

_______________________________________________
fxruby-users mailing list
fxruby-users@...
http://rubyforge.org/mailman/listinfo/fxruby-users