Index: /trunk/Config.kmk
===================================================================
--- /trunk/Config.kmk	(revision 2444)
+++ /trunk/Config.kmk	(revision 2445)
@@ -321,5 +321,5 @@
   TEMPLATE_BIN_LDFLAGS.sparc64 += -m64
  ifeq ($(KBUILD_TARGET),solaris)
-  TEMPLATE_BIN_LIBS            += rt
+  TEMPLATE_BIN_LIBS            += rt dl
   TEMPLATE_BIN_LDFLAGS         += -Wl,-i
  endif
Index: /trunk/src/lib/restartable-syscall-wrappers.c
===================================================================
--- /trunk/src/lib/restartable-syscall-wrappers.c	(revision 2444)
+++ /trunk/src/lib/restartable-syscall-wrappers.c	(revision 2445)
@@ -38,7 +38,10 @@
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <dlfcn.h>
+#include <errno.h>
 #include <fcntl.h>
-#include <errno.h>
 #include <stdarg.h>
+#include <stddef.h>
+#include <stdio.h>
 
 
@@ -55,4 +58,11 @@
 #endif
 
+/** Optional '64' suffix string for dlsym.  */
+#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
+# define SYM_64_SUFFIX "64"
+#else
+# define SYM_64_SUFFIX ""
+#endif
+
 /** Mangle a syscall name with optional '64' suffix. */
 #if !defined(_LP64) && _FILE_OFFSET_BITS == 64
@@ -140,3 +150,67 @@
 }
 
+static int dlsym_libc(const char *pszSymbol, void **ppvSym)
+{
+    static void *s_pvLibc = NULL;
+    void        *pvLibc;
+    void        *pvSym;
+
+    /*
+     * Open libc.
+     */
+    pvLibc = s_pvLibc;
+    if (!pvLibc)
+    {
+#ifdef RTLD_NOLOAD
+        pvLibc = dlopen("/libc/libc.so", RTLD_NOLOAD);
+#else
+        pvLibc = dlopen("/libc/libc.so", RTLD_GLOBAL);
+#endif
+        if (!pvLibc)
+        {
+            fprintf(stderr, "restartable-syscall-wrappers: failed to dlopen libc for resolving %s: %s\n",
+                    pszSymbol, dlerror());
+            errno = ENOSYS;
+            return -1;
+        }
+        /** @todo check standard symbol? */
+    }
+
+    /*
+     * Resolve the symbol.
+     */
+    pvSym = dlsym(pvLibc, pszSymbol);
+    if (!pvSym)
+    {
+        fprintf(stderr, "restartable-syscall-wrappers: failed to resolve %s: %s\n",
+                pszSymbol, dlerror());
+        errno = ENOSYS;
+        return -1;
+    }
+
+    *ppvSym = pvSym;
+    return 0;
+}
+
+FILE *fopen(const char *pszName, const char *pszMode)
+{
+    static union
+    {
+        FILE *(* pfnFopen)(const char *, const char *);
+        void *pvSym;
+    } s_u;
+    FILE *pFile;
+
+    if (   !s_u.pfnFopen
+        && dlsym_libc("fopen" SYM_64_SUFFIX, &s_u.pvSym) != 0)
+        return NULL;
+
+    do
+        pFile = s_u.pfnFopen(pszName, pszMode);
+    while (!pFile && SHOULD_RESTART());
+    return pFile;
+}
+
 /** @todo chmod, chown, chgrp, times, and possible some more. */
+
+
