mapi: do not return thread-specific data for wrong thread

If the current thread asks for either the current context or the current
dispatch table for a thread that has not yet set any context current, we
currently risk returning the wrong data if there was only a single
thread that had called u_current_init() yet.

So let's first check if the only expected thread-id is the one getting
these, and return NULL and/or __glapi_noop_table instead if not.

Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Louis-Francis Ratté-Boulianne <lfrb@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7280>
This commit is contained in:
Erik Faye-Lund 2020-10-22 19:06:44 +02:00 committed by Marge Bot
parent 61d40ae4d0
commit 26f58e87a0

View file

@ -180,6 +180,7 @@ thread_id_equal(thread_id t1, thread_id t2)
#endif
}
static thread_id knownID;
/**
* We should call this periodically from a function such as glXMakeCurrent
@ -188,7 +189,6 @@ thread_id_equal(thread_id t1, thread_id t2)
void
u_current_init(void)
{
static thread_id knownID;
static int firstCall = 1;
if (ThreadSafe)
@ -249,7 +249,12 @@ u_current_get_context_internal(void)
#if defined(USE_ELF_TLS)
return u_current_context;
#else
return ThreadSafe ? tss_get(u_current_context_tsd) : u_current_context;
if (ThreadSafe)
return tss_get(u_current_context_tsd);
else if (!thread_id_equal(knownID, get_thread_id()))
return NULL;
else
return u_current_context;
#endif
}
@ -287,6 +292,8 @@ u_current_get_table_internal(void)
#else
if (ThreadSafe)
return (struct _glapi_table *) tss_get(u_current_table_tsd);
else if (!thread_id_equal(knownID, get_thread_id()))
return (struct _glapi_table *) table_noop_array;
else
return (struct _glapi_table *) u_current_table;
#endif