Bug 89920

Summary: eglCreatePlatformWindowSurfaceEXT() should not dereference native_window
Product: Mesa Reporter: junkmailnotread
Component: EGLAssignee: mesa-dev
Status: RESOLVED INVALID QA Contact: mesa-dev
Severity: normal    
Priority: medium    
Version: 10.5   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:

Description junkmailnotread 2015-04-06 17:37:58 UTC
The following code block appears in eglCreatePlatformWindowSurfaceEXT() in src/egl/main/eglapi.c:

#ifdef HAVE_X11_PLATFORM
   if (disp->Platform == _EGL_PLATFORM_X11 && native_window != NULL) {
      /* The `native_window` parameter for the X11 platform differs between
       * eglCreateWindowSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
       * eglCreateWindowSurface(), the type of `native_window` is an Xlib
       * `Window`. In eglCreatePlatformWindowSurfaceEXT(), the type is
       * `Window*`.  Convert `Window*` to `Window` because that's what
       * dri2_x11_create_window_surface() expects.
       */
      native_window = (void*) (* (Window*) native_window);
   }
#endif

The assertion that the `native_window` parameter for the X11 platform differs between eglCreateWindowSurface() and eglCreatePlatformWindowSurfaceEXT() is not supported by the EXT_platform_base extension or EGL Version 1.5. These merely state:

"The behavior of eglCreateWindowSurface is identical to that of eglCreatePlatformWindowSurfaceEXT except that the set of platforms to which <dpy> is permitted to belong, as well as the actual type of <win>, are implementation specific."

Nowhere does it say that - uniquely for the X11 platform - the `native_window` parameter should be passed by reference rather than by value.

My feeling is that eglCreatePlatformWindowSurfaceEXT() should follow the behaviour of eglCreateWindowSurface() in treating the `native_window` parameter as an opaque handle (i.e. EGLNativeWindowType) for all platforms.

A similar situation exists for eglCreatePlatformPixmapSurfaceEXT():

#ifdef HAVE_X11_PLATFORM
      /* The `native_pixmap` parameter for the X11 platform differs between
       * eglCreatePixmapSurface() and eglCreatePlatformPixmapSurfaceEXT(). In
       * eglCreatePixmapSurface(), the type of `native_pixmap` is an Xlib
       * `Pixmap`. In eglCreatePlatformPixmapSurfaceEXT(), the type is
       * `Pixmap*`.  Convert `Pixmap*` to `Pixmap` because that's what
       * dri2_x11_create_pixmap_surface() expects.
       */
   if (disp->Platform == _EGL_PLATFORM_X11 && native_pixmap != NULL) {
      native_pixmap = (void*) (* (Pixmap*) native_pixmap);
   }
#endif
Comment 1 Daniel Stone 2015-04-06 17:54:02 UTC
Per the EGL_KHR_platform_x11 spec, this is incorrect. The language in there about the native window type 'point[ing] to' an X11 Window or Pixmap is slightly ambiguous, but the example provided - where the argument is either &window.x11 or window.x11, depending on whether or not platform_base is being used, is 100% unambiguous.

This also matches the behaviour of at least two proprietary drivers.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.