Handling X errors using exception handlers

Lionel Ulmer lionel.ulmer at free.fr
Sat Jul 14 04:52:24 CDT 2001


Hi all,

When discussing with Ove yesterday on #WineHQ about the handling of X
errors, he told me about an idea of his : using exceptions to handle X
errors.

This way, when we have to explicitely handle X errors (as we will need to do
for XVidmode and XDGA2 due to some (stupidly done IMHO :-) ) security fixes
in XFree 4.x), we could do that using exceptions.

Before doing this 'properly' (ie change the X11 drv, update the XShm error
mechanism, the debugger, ...), here is what I did for now :

 1) I created a new Wine-private exception type in include/wine/exception.h :
 
/* unhandled X error */
#define EXCEPTION_WINE_X11DRV     0x80000104

 2) I created a new X error handler that is installed at X11DRV
    initialization :
 
static int X11DRV_XErrorHandler(Display *dpy, XErrorEvent *event) {
    EXCEPTION_RECORD rec;
    
    rec.ExceptionCode    = EXCEPTION_WINE_X11DRV;
    rec.ExceptionFlags   = 0;
    rec.ExceptionRecord  = NULL;
    rec.ExceptionAddress = XGLErrorHandler;
    rec.NumberParameters = 4;
    rec.ExceptionInformation[0] = (DWORD)event->serial;
    rec.ExceptionInformation[1] = (DWORD)event->error_code;
    rec.ExceptionInformation[2] = (DWORD)event->request_code;
    rec.ExceptionInformation[3] = (DWORD)event->minor_code;

    RtlRaiseException(&rec);
    return 0;
}

 3) I changed the XVidMode detection code thus :
 
/* handle only X errors */
static WINE_EXCEPTION_FILTER(xerror_handler)
{
  switch (GetExceptionCode()) {
    case EXCEPTION_WINE_X11DRV:
       return EXCEPTION_EXECUTE_HANDLER;
	
    default:
       return EXCEPTION_CONTINUE_SEARCH;
   }
}

(...)

void X11DRV_XF86VM_Init(void)
{
(...)
  wine_tsx11_lock();
(...)
  __TRY {
     if (!XF86VidModeQueryVersion(gdi_display, &xf86vm_major, &xf86vm_minor)) {
       xf86vm_major = 0;
     }
    XSync(gdi_display, False);
  } 
  __EXCEPT(xerror_handler) {
    xf86vm_major = 0;
  }
  __ENDTRY
  wine_tsx11_unlock();

  if (xf86vm_major == 0) {
    TRACE("No XVidmode\n");
    return;
  }
(...)
}
						
So what do you all think of this ? Is this something that I should add to
the whole Wine tree ?

The only problem with that is that it would make debugging X errors a bit
more difficult as we won't have the standard X error message in debug
reports from users...

                     Lionel

-- 
		 Lionel Ulmer - http://www.bbrox.org/




More information about the wine-devel mailing list