+static const char *wrapped_libs[] = {
+ "libGL.so",
+ "libEGL.so",
+ "libGLESv2.so"
+};
+
+static void *orig_handles[ARRAY_SIZE(wrapped_libs)];
+
+/* Match 'filename' against an internal list of libraries for which
+ * libfips has wrappers.
+ *
+ * Returns true and sets *index_ret if a match is found.
+ * Returns false if no match is found. */
+static bool
+find_wrapped_library_index (const char *filename, unsigned *index_ret)
+{
+ unsigned i;
+
+ for (i = 0; i < ARRAY_SIZE(wrapped_libs); i++) {
+ if (strncmp(wrapped_libs[i], filename,
+ strlen (wrapped_libs[i])) == 0)
+ {
+ *index_ret = i;
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* Perform a dlopen on the libfips library itself.
+ *
+ * Many places in fips need to lookup symbols within the libfips
+ * library itself, (and not in any other library). This function
+ * provides a reliable way to get a handle for performing such
+ * lookups.
+ *
+ * The returned handle can be passed to dlwrap_real_dlsym for the
+ * lookups. */
+void *
+dlwrap_dlopen_libfips (void)
+{
+ Dl_info info;
+
+ /* We first find our own filename by looking up a function
+ * known to exist only in libfips. This function itself
+ * (dlwrap_dlopen_libfips) is a good one for that purpose. */
+ if (dladdr (dlwrap_dlopen_libfips, &info) == 0) {
+ fprintf (stderr, "Internal error: Failed to lookup filename of libfips library with dladdr\n");
+ exit (1);
+ }
+
+ return dlwrap_real_dlopen (info.dli_fname, RTLD_NOW);
+}
+