You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
EGL translator: concurrent eglCreatePbufferSurface() calls can get the same surface handle #241
EglSurface gets its handle from ++s_nextSurfaceHndl (host/gl/glestranslator/egl/egl_surface.h).
The counter is a plain unsigned int. eglCreatePbufferSurface() constructs the surface before
it takes graphicsDriverLock(). Thus, two threads can increment the counter at the same time and
get the same handle.
Cause
egl_imp.cpp, eglCreatePbufferSurface(): new EglPbufferSurface(dpy, cfg) runs before AutoLock mutex(*graphicsDriverLock()).
The EglSurface constructor does m_hndl = ++s_nextSurfaceHndl;. This is a data race when
two render threads create pbuffer surfaces at the same time.
EglDisplay::addSurface() does not add a surface if its handle is already in the map. It
returns the existing handle.
The second caller gets the handle of the first surface. Its own surface is released.
Window surfaces and contexts get their handles while the lock is held. They are not affected. ~EglContext also creates an EglPbufferSurface. It can run outside the lock, for example when
a thread exits.
Result
Two EmulatedEglWindowSurface objects can share one host EGL surface. When one is destroyed,
calls on the other fail with EGL_BAD_SURFACE.
Expected result
Each surface gets a unique handle.
Proposed fix
Make s_nextSurfaceHndl a std::atomic<unsigned int>. The increment then gives a unique value
without the lock. PR: #243.
Notes
We found this by code review. We did not see it occur.
Activity