Commit Graph

537 Commits

Author SHA1 Message Date
Félix Baylac Jacqué f4dff011f7 glx: introduce NIX_GLVND_GLX_PATH env variable
If NIX_GLVND_GLX_PATH is set, libglvnd will try to load the glx DSOs
from the directory it points at instead of loading them from LD_LIBRARY_PATH.
2022-11-15 16:27:16 +01:00
Kyle Brenneman 6c5497e527 GLX: Fix assembly stubs for x32
Add x32 assembly stubs for GLX functions.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/225
2022-10-05 14:34:44 -06:00
yes,i Do 05f75de586 Add support for loongarch64. 2022-09-20 14:05:14 +00:00
Kyle Brenneman 1d270ce502 Merge branch 'update-opengl-headers' into 'master'
Update OpenGL headers

See merge request glvnd/libglvnd!268
2022-08-30 14:16:22 +00:00
Kyle Brenneman fd1df5e989 Update GL headers and XML files.
Update the GL headers and XML files to the Khronos repository, from
commit 11d7b7baebfc2b58116670cd17266f9c6a0d760b.
2022-08-23 07:30:18 -06:00
Dylan Baker a1a4123c7e meson: rename idep_glx -> dep_glx
Since we use idep as a convention to mean "internal dep"
2022-07-06 14:15:28 -07:00
Dylan Baker 8ee0213413 meson: use meson.override_dependency when possible
Which allows libglvnd to be consumed as a meson subproject.
2022-07-06 14:15:28 -07:00
Dylan Baker ca2eeb5a3b meson: remove dep_glx
It's just an array holding two external dependencies, and we usually use
dep_* to mean "here's a dependency object that subprojects can use".
2022-07-06 14:15:28 -07:00
Kyle Brenneman 3144f287d1 Read gl.symbols when generating stubs for libGL.so.
Instead of generating symbols for everything in gl.xml, read the symbol
list from src/GL/gl.symbols and only generate the functions listed
there.

That way, when new functions get added to gl.xml, we won't add any more
symbols in libGL.so.

To do that, if the target parameter to gen_gldispatch_mapi.py is a
filename, then it will read that file for symbols instead of calling
genCommon.getExportNamesFromRoots.

Also added a new genCommon.readSymbolsFile function, which is mostly
copied from symbols-check.py.
2022-06-07 07:57:02 -06:00
Kyle Brenneman 7b892b72e0 Merge branch 'fix-gldispatch-thread-state-leak' into 'master'
Fix a memory leak in libGLdispatch

Closes #230

See merge request glvnd/libglvnd!265
2022-06-07 12:54:32 +00:00
Kyle Brenneman d853cf56f8 GLdispatch: Build ARMv7 stubs as ARM instead of Thumb
Change the ARMv7 dispatch stubs to use ARM instead of Thumb. There's no
difference in size (since either one fits in the 128-byte alignment that
we use), but using ARM means that they'll compile and work on an ARMv6
build as well.
2022-06-01 07:15:35 -06:00
Kyle Brenneman 70e6a300b2 Fix a memory leak in libGLdispatch
In __glDispatchMakeCurrent, it allocates a
__GLdispatchThreadStatePrivate struct, which would normally get freed in
__glDispatchLoseCurrent.

However, if the library gets unloaded while another thread still has a
current context, then __glDispatchLoseCurrent never gets called, and so
that memory leaks.

Add the __GLdispatchThreadStatePrivate to a linked list so that it can
free any remaining structs in __glDispatchFini.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/230.
2022-05-17 13:37:06 -06:00
Aidan Foster 9f59259dc6 Moving setspecific to before DestroyThreadState 2022-03-15 17:53:15 +00:00
Aidan Foster 1f2bfbb6f0 Update src/EGL/libeglcurrent.c 2022-03-14 20:38:20 +00:00
Aidan Foster 4834bd26e7 Set current thread state to NULL in teardown
In the EGL destructor, DestroyThreadState gets called by
__eglCurrentTeardown to free the threadState, but the threadState does
not get changed to NULL when this happens.

The function eglReleaseThread calls __eglDestroyCurrentThreadAPIState,
which does set the threadState to NULL, right before calling
DestroyThreadState. Both eglReleaseThread and
__eglDestroyCurrentThreadAPIState check to make sure the threadState is
NULL before continuing.

If eglReleaseThread gets externally called after destruction, the
threadState is not NULL, so DestroyThreadState will be called to free
the threadState that was already freed by the destructor, causing a
double free.

This change is to add the same setting threadState to NULL in
__eglCurrentTeardown as which already __eglDestroyCurrentThreadAPIState,
to prevent this double free situation.
2022-03-14 18:51:37 +00:00
Guillaume Gardet 7107f73939 Add BTI landing pads for aarch64
When Branch Target Identifier (BTI) is enabled on aarch64,
any software which run libglvnd will fail with SIGILL, Illegal instruction.
This is because some assembler code misses the BTI landing pads.
See: https://developer.arm.com/documentation/102433/0100/Jump-oriented-programming

"hint #34" is the same thing as "BTI C" landing pad, but keep
compatibility with systems without BTI enabled.
2022-02-24 16:21:52 +01:00
Alex Richardson 7fa33fac51 Update the EGL headers
Updated the EGL headers and XML file to the Khronos repository, from commit
0997d5398d9de08ac012e7230d6546eb342c2939.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2022-02-06 17:53:55 +00:00
Kyle Brenneman db5ca3370c EGL: Add support for eglQueryDisplayAttribKHR and NV.
There are KHR, EXT, and NV versions of eglQueryDisplayAttrib, so add
support for all of them.

Define separate eglQueryDisplayAttribEXT, eglQueryDisplayAttribKHR, and
eglQueryDisplayAttribNV functions. They all call into the same common
function, with the only difference being the name passed to an error
callback.

When loading a vendor library, check for the vendor's
eglQueryDisplayAttrib using all three suffixes, and use whichever one is
available.
2021-11-29 07:26:39 -07:00
Kyle Brenneman eaffa7bc12 EGL: Add a dispatch stub for eglQueryDisplayAttribEXT.
Add a dispatch stub for eglQueryDisplayAttribEXT, which updates the device
hashtable if the application queries EGL_DEVICE_EXT.

It's possible that eglQueryDisplayAttribEXT could return an EGLDeviceEXT handle
that wasn't returned by eglQueryDevicesEXT, so the dispatch stub needs to add
the handle to the device hashtable.
2021-11-25 09:51:20 -07:00
Kyle Brenneman 26d15a9f13 EGL: Allow vendor's dispatch stubs to update the EGL device map.
Export a new __EGLapiExports::setVendorForDevice function, which allows
dispatch stubs to update the device hashtable when something returns an
EGLDeviceEXT handle.

Bumped the ABI version number to 1.2.
2021-11-25 09:51:20 -07:00
Kyle Brenneman 2747fcd3fc EGL: Allow adding EGLDeviceEXT handles
It's possible for new devices to become available while a program is running,
so eglQueryDevicesEXT might need to return a different list.

Change the EGLDeviceEXT hashtable so that each entry is allocated and added
separately, rathat than allocating every entry in a single malloc.

Added a new __eglAddDevice function, which adds an entry to the device
hashtable.

When the application calls eglQueryDevicesEXT, always call through to each
vendor library, and add (or update) each EGLDeviceEXT to the hashtable.

There's still no provision for removing an entry from the device hashtable. The
semantics of hot-unplugging a device aren't defined yet, and there's no way to
ensure that libglvnd's mapping will get updated if a device disappears
asynchonously, so it's up to the vendor library to deal with the old handle.
2021-11-25 09:51:20 -07:00
Kyle Brenneman 922b85a94a Merge branch 'fix-x11-config-option' into 'master'
Fix the option to disable X11 in meson

See merge request glvnd/libglvnd!258
2021-10-28 15:28:42 +00:00
Kyle Brenneman fa9ef3971f Replace USE_X11 macro with ENABLE_EGL_X11.
If x11 support is enabled, then the meson and configure scripts will set
a macro named ENABLE_EGL_X11 instead of USE_X11.

USE_X11 will also select the Xlib typedef of EGLNativeDisplayType in
eglplatform.h, and libglvnd does not need or want those.

Enabling or disabling X11 support for EGL only affects platform
detection in eglGetDisplay. The rest of libEGL is supposed to treat
EGLNativeDisplayType as an opaque void* pointer.
2021-10-27 12:27:47 -06:00
Kyle Brenneman 185ca4b3ea Merge branch 'update-uthash' into 'master'
Update uthash to v2.3.0

See merge request glvnd/libglvnd!256
2021-10-05 14:08:29 +00:00
Alex Richardson b3a958feb0 Update uthash to v2.3.0
Also delete files and folders that are only useful in the original
repository. Updating uthash to this version allows compiling with
CHERI LLVM where the current version of uthash (1.9.8) triggers a
warning that our build infrastructure includes in -Werror by default:
```
../../libglvnd/src/util/winsys_dispatch.c:154:9: error: cast from provenance-free integer type to pointer type will give pointer that can not be dereferenced [-Werror,-Wcheri-capability-misuse]
../../libglvnd/include/lkdhash.h:86:5: note: expanded from macro 'LKDHASH_TEARDOWN'
    LKDHASH_TEARDOWN_2(_lh, _param, cur ## _ht,                   \
    ^
../../libglvnd/include/lkdhash.h:55:9: note: expanded from macro 'LKDHASH_TEARDOWN_2'
        HASH_DEL(_LH(_lockedhash), _cur);                                       \
        ^
../../libglvnd/src/util/uthash/src/uthash.h:271:5: note: expanded from macro 'HASH_DEL'
    HASH_DELETE(hh,head,delptr)
    ^
../../libglvnd/src/util/uthash/src/uthash.h:239:14: note: expanded from macro 'HASH_DELETE'
            ((UT_hash_handle*)((ptrdiff_t)_hd_hh_del->next +                     \
             ^
```

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-10-05 09:34:36 +01:00
Alex Richardson 0f5c40db0a Add one more missing dep_x11_headers
I missed this in 396c10bdd7 since I was
building with -Dglx=disabled. This fixes the build with glx if the X11
libraries are installed into a custom prefix.

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-10-04 16:42:16 +01:00
Alex Richardson 396c10bdd7 Add x11_headers dependency to all targets that use it
This fixes the build for me since I have libX11 installed to a custom
prefix, so the default include path does not include libX11. This fixes
lots of instances of the following error:
../../libglvnd/include/EGL/eglplatform.h:109:10: fatal error: 'X11/Xlib.h' file not found

Signed-off-by: Alex Richardson <Alexander.Richardson@cl.cam.ac.uk>
2021-10-04 10:58:08 +01:00
Kyle Brenneman a7bb6f4d19 Remove extra paragraph from license text.
Remove the "If only executable code is distributed..." paragraph from
the license text. Everything now uses a normal MIT license.

The only code from Khronos that's included in libglvnd is the EGL/GL
header and XML files, which do not contain that paragraph.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/221
2021-09-30 09:21:34 -06:00
Charlotte Delenk 97db5662c1
Mark entrypointFunctions as used for clang+lto
LLVM currently ignores inline assembly references to symbols during
dead code and data elimination while linking with link-time optimizations
enabled.

This manifests in a very large amount of unresolved references to
entrypointFunctions when building libglvnd using clang with LTO enabled.

This issue fixes #220 by marking the entrypointFunctions array as used,
using a compiler attribute.

Signed-off-by: Charlotte Delenk <darkkirb@darkkirb.de>
2021-09-20 18:48:28 +02:00
Felix Yan e579f218e5 Correct a typo in entry_pure_c.c 2021-09-16 22:04:51 +00:00
Alex Xu (Hello71) e87d51f006 Use initial-exec TLS for glibc and FreeBSD only
It is not portable to use initial-exec TLS in dlopened libraries. glibc
and FreeBSD allocate extra memory for extra initial-exec variables
specifically for libGL, but other libcs including musl do not.

Since TLS entry asm assumes IE TLS, use TSD asm in other cases. Update
autoconf to match meson logic: enable ELF TLS if it is supported,
regardless of which type of asm is being used.
2021-09-13 17:24:13 -04:00
Kyle Brenneman b29f99d836 Update the EGL headers.
Updated the EGL headers and XML file to the Khronos repository, from commit
745e9ad435ad10323d0f42da1f279ad3cae2dba3.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/206
2021-08-23 17:24:53 -06:00
Simon McVittie a22477ba28 EGL: Interpret relative ICD paths as relative to the JSON manifest
Previously, relative ICD paths were treated as being relative to the
current working directory, but this doesn't seem useful in practice:
EGL vendors cannot predict what the current working directory of EGL
applications is going to be.

Instead, interpret the path as being relative to the realpath() of the
JSON manifest describing the ICD.

Signed-off-by: Simon McVittie <smcv@collabora.com>
Resolves: https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/190
2021-08-04 14:32:22 +01:00
Simon Ser 418cbb6be3 egl: sync with Khronos
Updated the EGL headers and XML file to the Khronos repository, from commit
3dd5604d6791a0fdd102b665fe706ebf8737892b.
2021-07-22 16:35:01 +02:00
Kyle Brenneman 4a08df7bdc GLX: Remove the XESetCloseDisplay callback during teardown.
When libGLX.so is unloaded, call XESetCloseDisplay to remove the display close
callback for any displays that still exist.

Otherwise, if libGLX.so is loaded using dlopen, and then unloaded while a
display is still open, then XCloseDisplay would try to call the (now dangling)
callback.
2021-06-16 11:32:26 -06:00
Kyle Brenneman c1c60ac80a GLdispatch: Add a build option to disable entrypoint patching.
Added a --disable-entrypoint-tracking configure option and an
'entrypoint-patching' meson option to disable libGLdispatch's entrypoint
patching at build time.

If entrypoint patching is disabled, then it #ifdef's out the mprotect call, and
acts as if mprotect had failed, which causes libGLdispatch to skip trying to
perform any patching.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/217
2021-04-21 16:22:39 -06:00
Kyle Brenneman e1a4289544 Merge branch 'glx-fix-display-close-lock-order' into 'master'
GLX: Fix a potential deadlock in OnDisplayClosed.

Closes #213

See merge request glvnd/libglvnd!236
2021-02-22 16:30:59 +00:00
Kyle Brenneman 178d57f6d9 Merge branch 'fix-glx-armv7-arm-directive' into 'master'
Add .arm directives for the GLX entrypoint stubs.

See merge request glvnd/libglvnd!233
2021-02-11 23:32:49 +00:00
Kyle Brenneman dd2d28a033 GLX: Fix a potential deadlock in OnDisplayClosed.
In OnDisplayClosed, unlock the __glXDisplayInfoHash lock before locking
glxContextHashLock.

In CommonMakeCurrent, it holds glxContextHashLock while it tries to take the
__glXDisplayInfoHash lock, so if CommonMakeCurrent and OnDisplayClosed run at
the same time, they could deadlock.

To avoid that, OnDisplayClosed will set a new inTeardown flag in the
__GLXdisplayInfoHash, then it will unlock the display hash before calling
__glXDisplayClosed.

After __glXDisplayClosed is finished, OnDisplayClosed will lock
__glXDisplayInfoHash again long enough to remove the display from the
hashtable.

The inTeardown flag tells __glXLookupDisplay to return NULL, since after that
point, nothing should be trying to look up the display. In principle, we could
just remove the display from the hashtable up front, but then if something did
try to look up the display, then __glXLookupDisplay would try to create a new
__GLXdisplayInfo for it.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/213
2020-11-19 11:54:50 -07:00
Ronan Pigott a527411da7 egl: use device dispatch if at least one vendor suceeds
Currently, in InitDeviceListInternal if any egl vendor fails to list
its devices for any reason the construction of the device list is
abandoned. That means that even if we have one vendor successfully
serving the application, the failure of another vendor library will
break any api calls related to egl devices.

Instead, if a vendor fails queryDevicesEXT the device mapping logic
should proceed as if it listed no devices. If the relevant device
belongs to the failed vendor then the dispatch will still fail with
EGL_BAD_DEVICE.
2020-11-18 15:46:53 -07:00
Kyle Brenneman 6cd95fbfe2 Add .arm directives for the GLX entrypoint stubs.
Add .arm and .thumb directives before and after the ARMv7 GLX dispatch stubs.

The function addresses that get passed around don't take Thumb into account, so
if they're compiled as Thumb, then they'd still get executed as ARM, which
would cause them to crash a SIGILL.
2020-08-11 12:37:59 -06:00
Kyle Brenneman f936adad89 generate: Use xml.etree.ElementTree instead of cElementTree.
The cElementTree module is deprecated as of 3.3, so use the normal ElementTree
module instead.

Fixes https://gitlab.freedesktop.org/glvnd/libglvnd/-/issues/204
2020-06-10 08:59:44 -06:00
Simon Ser 4acb9be27d
egl: sync with Khronos
Updated the EGL headers and XML file to the Khronos repository, from commit
90b78b0662e2f0548cfd1926fb77bf628933541b.
2020-05-07 23:36:13 +02:00
H.J. Lu f96f6bde04 x86: Add ENDBR at function entries
Intel Control-flow Enforcement Technology (CET):

https://software.intel.com/en-us/articles/intel-sdm

contains shadow stack (SHSTK) and indirect branch tracking (IBT). When
CET is enabled, ELF object files must be marked with .note.gnu.property
section. Also when IBT is enabled, all indirect branch targets must
start with ENDBR instruction which is NOP on non-CET processors.

This fixes:

https://gitlab.freedesktop.org/glvnd/libglvnd/issues/202
2020-02-21 21:28:29 +00:00
Eric Engestrom e77d52dadb egl/glx: avoid hard-coding the path to `python` 2019-12-12 23:47:24 +00:00
Eric Engestrom 0c38c8ad24 egl: drop shebang on non-executable script 2019-12-12 23:45:37 +00:00
Eric Engestrom f0c2ce450d Merge branch 'python' into 'master'
egl: misc python fixes

See merge request glvnd/libglvnd!218
2019-12-12 23:37:15 +00:00
Eric Engestrom 25024a1f0a egl: sort imports 2019-12-12 23:18:53 +00:00
Eric Engestrom 1f6b455dc8 egl: use ArgumentParser() instead of manually parsing sys.argv 2019-12-12 23:18:53 +00:00
Eric Engestrom 214450d18a egl: import eglFunctionList directly instead of passing it in the command line
`imp` is deprecated, and there's no reason to do things this complicated
when it's the only possibility.
2019-12-12 23:18:53 +00:00