diff --git a/System/Posix/Env.hsc b/System/Posix/Env.hsc
index 39db08c3fd95e8e338b9498feb7fb71583aa26db..83bdc2c93894d83a9783d8746736c5ce2de09193 100644
--- a/System/Posix/Env.hsc
+++ b/System/Posix/Env.hsc
@@ -55,12 +55,24 @@ foreign import ccall unsafe "getenv"
 
 getEnvironmentPrim :: IO [String]
 getEnvironmentPrim = do
-  c_environ <- peek c_environ_p
+  c_environ <- getCEnviron
   arr <- peekArray0 nullPtr c_environ
   mapM peekCString arr
 
+getCEnviron :: IO (Ptr CString)
+#if darwin_HOST_OS
+-- You should not access _environ directly on Darwin in a bundle/shared library.
+-- See #2458 and http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man7/environ.7.html
+getCEnviron = nsGetEnviron >>= peek
+
+foreign import ccall unsafe "_NSGetEnviron"
+   nsGetEnviron :: IO (Ptr (Ptr CString))
+#else
+getCEnviron = peek c_environ_p
+
 foreign import ccall unsafe "&environ"
    c_environ_p :: Ptr (Ptr CString)
+#endif
 
 -- |'getEnvironment' retrieves the entire environment as a
 -- list of @(key,value)@ pairs.