aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mapi/stub.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2013-06-04 09:07:26 +0200
committermarha <marha@users.sourceforge.net>2013-06-04 09:07:26 +0200
commit150771e7aabf4c864b0b970c5b8d773634793abe (patch)
tree3d544cc0d8d06dd70e843d6ca7e4b0ef421d2758 /mesalib/src/mapi/stub.c
parentfbe681216618af573ce29ca03b382b39b5919a52 (diff)
downloadvcxsrv-150771e7aabf4c864b0b970c5b8d773634793abe.tar.gz
vcxsrv-150771e7aabf4c864b0b970c5b8d773634793abe.tar.bz2
vcxsrv-150771e7aabf4c864b0b970c5b8d773634793abe.zip
xwininfo fontconfig libX11 libXau libXdmcp libXext mesa libXinerama libxcb libxcb/xcb-proto libfontenc pixman xkbcomp mkfontscale xkeyboard-config git update 4 Jun 2013
xserver commit c21344add2fc589df83b29be5831c36a372201bd libxcb commit 9ae84ad187e2ba440c40f44b8eb21c82c2fdbf12 libxcb/xcb-proto commit bdfedfa57a13ff805580cfacafc70f9cc55df363 xkeyboard-config commit dad9ade4e83d1ef5a517fcc4cc9ad3a79b47acce libX11 commit 8496122eb00ce6cd5d2308ee54f64b68c378e455 libXdmcp commit 0b443c1b769b9c9a3b45b4252afe07e18b709ff4 libXext commit d8366afbb0d2e4fbb1e419b1187f490522270bea libfontenc commit 3acba630d8b57084f7e92c15732408711ed5137a libXinerama commit 6e1d1dc328ba8162bba2f4694e7f3c706a1491ff libXau commit 899790011304c4029e15abf410e49ce7cec17e0a xkbcomp commit ed582f4fccd4e23abcfba8b3b03649fea6414f44 pixman commit 2acfac5f8e097ee2ae225d986f981b55d65dd152 mkfontscale commit 19e2cb7c6a3ec2c5b1bc0d24866fa685eef0ee13 xwininfo commit ba0d1b0da21d2dbdd81098ed5778f3792b472e13 fontconfig commit cd9b1033a68816a7acfbba1718ba0aa5888f6ec7 mesa commit 7bafd88c153e395274b632e7eae4bc9fc3aec1d2
Diffstat (limited to 'mesalib/src/mapi/stub.c')
-rw-r--r--mesalib/src/mapi/stub.c229
1 files changed, 229 insertions, 0 deletions
diff --git a/mesalib/src/mapi/stub.c b/mesalib/src/mapi/stub.c
new file mode 100644
index 000000000..688dc8143
--- /dev/null
+++ b/mesalib/src/mapi/stub.c
@@ -0,0 +1,229 @@
+/*
+ * Mesa 3-D graphics library
+ * Version: 7.9
+ *
+ * Copyright (C) 2010 LunarG Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Chia-I Wu <olv@lunarg.com>
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "u_current.h"
+#include "u_thread.h"
+#include "entry.h"
+#include "stub.h"
+#include "table.h"
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
+struct mapi_stub {
+ const void *name;
+ int slot;
+ mapi_func addr;
+};
+
+/* define public_string_pool and public_stubs */
+#define MAPI_TMP_PUBLIC_STUBS
+#include "mapi_tmp.h"
+
+static struct mapi_stub dynamic_stubs[MAPI_TABLE_NUM_DYNAMIC];
+static int num_dynamic_stubs;
+static int next_dynamic_slot = MAPI_TABLE_NUM_STATIC;
+
+void
+stub_init_once(void)
+{
+#ifdef HAVE_PTHREAD
+ static pthread_once_t once = PTHREAD_ONCE_INIT;
+ pthread_once(&once, entry_patch_public);
+#else
+ static int first = 1;
+ if (first) {
+ first = 0;
+ entry_patch_public();
+ }
+#endif
+}
+
+static int
+stub_compare(const void *key, const void *elem)
+{
+ const char *name = (const char *) key;
+ const struct mapi_stub *stub = (const struct mapi_stub *) elem;
+ const char *stub_name;
+
+ stub_name = &public_string_pool[(unsigned long) stub->name];
+
+ return strcmp(name, stub_name);
+}
+
+/**
+ * Return the public stub with the given name.
+ */
+const struct mapi_stub *
+stub_find_public(const char *name)
+{
+ return (const struct mapi_stub *) bsearch(name, public_stubs,
+ ARRAY_SIZE(public_stubs), sizeof(public_stubs[0]), stub_compare);
+}
+
+/**
+ * Add a dynamic stub.
+ */
+static struct mapi_stub *
+stub_add_dynamic(const char *name)
+{
+ struct mapi_stub *stub;
+ int idx;
+
+ idx = num_dynamic_stubs;
+ /* minus 1 to make sure we can never reach the last slot */
+ if (idx >= MAPI_TABLE_NUM_DYNAMIC - 1)
+ return NULL;
+
+ stub = &dynamic_stubs[idx];
+
+ /* dispatch to the last slot, which is reserved for no-op */
+ stub->addr = entry_generate(
+ MAPI_TABLE_NUM_STATIC + MAPI_TABLE_NUM_DYNAMIC - 1);
+ if (!stub->addr)
+ return NULL;
+
+ stub->name = (const void *) name;
+ /* to be fixed later */
+ stub->slot = -1;
+
+ num_dynamic_stubs = idx + 1;
+
+ return stub;
+}
+
+/**
+ * Return the dynamic stub with the given name. If no such stub exists and
+ * generate is true, a new stub is generated.
+ */
+struct mapi_stub *
+stub_find_dynamic(const char *name, int generate)
+{
+ u_mutex_declare_static(dynamic_mutex);
+ struct mapi_stub *stub = NULL;
+ int count, i;
+
+ u_mutex_lock(dynamic_mutex);
+
+ if (generate)
+ assert(!stub_find_public(name));
+
+ count = num_dynamic_stubs;
+ for (i = 0; i < count; i++) {
+ if (strcmp(name, (const char *) dynamic_stubs[i].name) == 0) {
+ stub = &dynamic_stubs[i];
+ break;
+ }
+ }
+
+ /* generate a dynamic stub */
+ if (generate && !stub)
+ stub = stub_add_dynamic(name);
+
+ u_mutex_unlock(dynamic_mutex);
+
+ return stub;
+}
+
+static const struct mapi_stub *
+search_table_by_slot(const struct mapi_stub *table, size_t num_entries,
+ int slot)
+{
+ size_t i;
+ for (i = 0; i < num_entries; ++i) {
+ if (table[i].slot == slot)
+ return &table[i];
+ }
+ return NULL;
+}
+
+const struct mapi_stub *
+stub_find_by_slot(int slot)
+{
+ const struct mapi_stub *stub =
+ search_table_by_slot(public_stubs, ARRAY_SIZE(public_stubs), slot);
+ if (stub)
+ return stub;
+ return search_table_by_slot(dynamic_stubs, num_dynamic_stubs, slot);
+}
+
+void
+stub_fix_dynamic(struct mapi_stub *stub, const struct mapi_stub *alias)
+{
+ int slot;
+
+ if (stub->slot >= 0)
+ return;
+
+ if (alias)
+ slot = alias->slot;
+ else
+ slot = next_dynamic_slot++;
+
+ entry_patch(stub->addr, slot);
+ stub->slot = slot;
+}
+
+/**
+ * Return the name of a stub.
+ */
+const char *
+stub_get_name(const struct mapi_stub *stub)
+{
+ const char *name;
+
+ if (stub >= public_stubs &&
+ stub < public_stubs + ARRAY_SIZE(public_stubs))
+ name = &public_string_pool[(unsigned long) stub->name];
+ else
+ name = (const char *) stub->name;
+
+ return name;
+}
+
+/**
+ * Return the slot of a stub.
+ */
+int
+stub_get_slot(const struct mapi_stub *stub)
+{
+ return stub->slot;
+}
+
+/**
+ * Return the address of a stub.
+ */
+mapi_func
+stub_get_addr(const struct mapi_stub *stub)
+{
+ assert(stub->addr || (unsigned int) stub->slot < MAPI_TABLE_NUM_STATIC);
+ return (stub->addr) ? stub->addr : entry_get_public(stub->slot);
+}