patch: libraries/unix __hsunix_-wrappers needed for NetBSD
Krister Walfridsson
krister.walfridsson at gmail.com
Wed Jul 22 16:58:00 EDT 2009
NetBSD does not have support for symbol versioning, so updated systen
functions need to be given a new name, and the header files contain
some __asm hackery in order to let the program call the correct function.
This mean that you need to use the header files in order to call the
correct system functions, which prevents things like "foreign import
ccall" from working.
Ghc solves this with wrapper functions for some of the renamed functions,
but it has not been updated for newer versions of NetBSD that has recently
versioned some more functions.
The attached patches introduces wrapper functions for all currently
NetBSD-versioned functions used in libraries/unix. Solves ~20 testsuite
failures.
/Krister
-------------- next part --------------
--- libraries/unix/include/HsUnix.h.orig 2009-07-22 05:59:10.000000000 +0200
+++ libraries/unix/include/HsUnix.h 2009-07-22 07:12:57.000000000 +0200
@@ -127,6 +127,37 @@
// lstat is a macro on some platforms, so we need a wrapper:
int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev);
+#ifdef HAVE_GETPWENT
+// getpwent is a macro on some platforms, so we need a wrapper:
+struct passwd *__hsunix_getpwent(void);
+#endif
+
+#if HAVE_GETPWNAM_R
+// getpwnam_r is a macro on some platforms, so we need a wrapper:
+int __hsunix_getpwnam_r(const char *, struct passwd *, char *, size_t,
+ struct passwd **);
+#endif
+
+#ifdef HAVE_GETPWUID_R
+// getpwuid_r is a macro on some platforms, so we need a wrapper:
+int __hsunix_getpwuid_r(uid_t, struct passwd *, char *, size_t,
+ struct passwd **);
+#endif
+
+#ifdef HAVE_NANOSLEEP
+// nanosleep is a macro on some platforms, so we need a wrapper:
+int __hsunix_nanosleep(const struct timespec *, struct timespec *);
+#endif
+
+// opendir is a macro on some platforms, so we need a wrapper:
+DIR *__hsunix_opendir(const char *);
+
+// time is a macro on some platforms, so we need a wrapper:
+time_t __hsunix_time(time_t *);
+
+// times is a macro on some platforms, so we need a wrapper:
+clock_t __hsunix_times(struct tms *);
+
#ifdef HAVE_PTSNAME
// I cannot figure out how to make the definitions of the following
// functions visible in <stdlib.h> on Linux. But these definitions
-------------- next part --------------
--- libraries/unix/cbits/HsUnix.c.orig 2009-07-22 06:23:44.000000000 +0200
+++ libraries/unix/cbits/HsUnix.c 2009-07-22 07:13:42.000000000 +0200
@@ -42,6 +42,58 @@
return mknod(pathname,mode,dev);
}
+#ifdef HAVE_GETPWENT
+// getpwent is a macro on some platforms, so we need a wrapper:
+struct passwd *__hsunix_getpwent(void)
+{
+ return getpwent();
+}
+#endif
+
+#if HAVE_GETPWNAM_R
+// getpwnam_r is a macro on some platforms, so we need a wrapper:
+int __hsunix_getpwnam_r(const char *name, struct passwd *pw, char *buffer,
+ size_t buflen, struct passwd **result)
+{
+ return getpwnam_r(name, pw, buffer, buflen, result);
+}
+#endif
+
+#ifdef HAVE_GETPWUID_R
+// getpwuid_r is a macro on some platforms, so we need a wrapper:
+int __hsunix_getpwuid_r(uid_t uid, struct passwd *pw, char *buffer,
+ size_t buflen, struct passwd **result)
+{
+ return getpwuid_r(uid, pw, buffer, buflen, result);
+}
+#endif
+
+#ifdef HAVE_NANOSLEEP
+// nanosleep is a macro on some platforms, so we need a wrapper:
+int __hsunix_nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
+{
+ return nanosleep(rqtp, rmtp);
+}
+#endif
+
+// opendir is a macro on some platforms, so we need a wrapper:
+DIR *__hsunix_opendir(const char *filename)
+{
+ return opendir(filename);
+}
+
+// time is a macro on some platforms, so we need a wrapper:
+time_t __hsunix_time(time_t *tloc)
+{
+ return time(tloc);
+}
+
+// times is a macro on some platforms, so we need a wrapper:
+clock_t __hsunix_times(struct tms *tp)
+{
+ return times(tp);
+}
+
#ifdef HAVE_PTSNAME
// I cannot figure out how to make the definitions of the following
// functions visible in <stdlib.h> on Linux. But these definitions
-------------- next part --------------
--- libraries/unix/System/Posix/User.hsc.orig 2009-07-22 06:44:53.000000000 +0200
+++ libraries/unix/System/Posix/User.hsc 2009-07-22 06:47:12.000000000 +0200
@@ -292,7 +292,7 @@
peekElemOff pppw 0
unpackUserEntry ppw
-foreign import ccall unsafe "getpwuid_r"
+foreign import ccall unsafe "__hsunix_getpwuid_r"
c_getpwuid_r :: CUid -> Ptr CPasswd ->
CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt
#elif HAVE_GETPWUID
@@ -328,7 +328,7 @@
(Just name)
unpackUserEntry ppw
-foreign import ccall unsafe "getpwnam_r"
+foreign import ccall unsafe "__hsunix_getpwnam_r"
c_getpwnam_r :: CString -> Ptr CPasswd
-> CString -> CSize -> Ptr (Ptr CPasswd) -> IO CInt
#elif HAVE_GETPWNAM
@@ -359,7 +359,7 @@
else do thisentry <- unpackUserEntry ppw
worker (thisentry : accum)
-foreign import ccall unsafe "getpwent"
+foreign import ccall unsafe "__hsunix_getpwent"
c_getpwent :: IO (Ptr CPasswd)
foreign import ccall unsafe "setpwent"
c_setpwent :: IO ()
-------------- next part --------------
--- libraries/unix/System/Posix/Unistd.hsc.orig 2009-07-22 06:49:19.000000000 +0200
+++ libraries/unix/System/Posix/Unistd.hsc 2009-07-22 06:49:57.000000000 +0200
@@ -158,7 +158,7 @@
data CTimeSpec
-foreign import ccall safe "nanosleep"
+foreign import ccall safe "__hsunix_nanosleep"
c_nanosleep :: Ptr CTimeSpec -> Ptr CTimeSpec -> IO CInt
#endif
-------------- next part --------------
--- libraries/unix/System/Posix/Directory.hsc.orig 2009-07-22 06:50:49.000000000 +0200
+++ libraries/unix/System/Posix/Directory.hsc 2009-07-22 06:51:21.000000000 +0200
@@ -61,7 +61,7 @@
dirp <- throwErrnoPathIfNull "openDirStream" name $ c_opendir s
return (DirStream dirp)
-foreign import ccall unsafe "opendir"
+foreign import ccall unsafe "__hsunix_opendir"
c_opendir :: CString -> IO (Ptr CDir)
-- | @readDirStream dp@ calls @readdir@ to obtain the
-------------- next part --------------
--- libraries/unix/System/Posix/Time.hsc.orig 2009-07-22 06:43:46.000000000 +0200
+++ libraries/unix/System/Posix/Time.hsc 2009-07-22 06:44:05.000000000 +0200
@@ -33,5 +33,5 @@
epochTime :: IO EpochTime
epochTime = throwErrnoIfMinus1 "epochTime" (c_time nullPtr)
-foreign import ccall unsafe "time"
+foreign import ccall unsafe "__hsunix_time"
c_time :: Ptr CTime -> IO CTime
-------------- next part --------------
--- libraries/unix/System/Posix/Process.hsc.orig 2009-07-22 06:41:42.000000000 +0200
+++ libraries/unix/System/Posix/Process.hsc 2009-07-22 06:43:27.000000000 +0200
@@ -173,7 +173,7 @@
type CTms = ()
-foreign import ccall unsafe "times"
+foreign import ccall unsafe "__hsunix_times"
c_times :: Ptr CTms -> IO CClock
-- -----------------------------------------------------------------------------
More information about the Cvs-ghc
mailing list