+#ifndef RTLD_NEXT
+# define RTLD_NEXT ((void *) -1l)
+#endif
+#ifndef RTLD_DEFAULT
+# define RTLD_DEFAULT ((void *) 0)
+#endif
+
+static inline void *psi_dlsym(struct psi_plist *dllist, const char *name, const char *redir)
+{
+ void *dl, *sym = NULL;
+ const char *test = redir ?: name;
+
+again:
+ if (dllist) {
+ size_t i = 0;
+
+ while (!sym && psi_plist_get(dllist, i++, &dl)) {
+ sym = dlsym(dl, test);
+ }
+ }
+ if (!sym) {
+ sym = dlsym(RTLD_DEFAULT, test);
+ }
+ if (!sym && test == redir) {
+ test = name;
+ goto again;
+ }
+
+ return sym;
+}
+
+#define PSI_DEBUG_PRINT(ctx, ...) do { \