git-annex/standalone/android/haskell-patches/network_android-port-fixes.patch
Joey Hess 22f49f216e
get android building the security fix
Had to update http-client and network, with follow-on dep changes.

This commit was sponsored by Brock Spratlen on Patreon.
2018-06-21 10:23:04 -04:00

341 lines
11 KiB
Diff

From 834a0d3bfe56b969a65eff834604442cde8798f7 Mon Sep 17 00:00:00 2001
From: dummy <dummy@example.com>
Date: Wed, 20 Jun 2018 05:06:41 +0100
Subject: [PATCH] android port fixes
Build note: Ensure a hsc2hs in PATH is modified to pass -x to the real
one, to enable cross-compiling.
---
Network/BSD.hsc | 84 -------------------------------------------
Network/Socket.hsc | 16 ++++-----
Network/Socket/ByteString.hsc | 2 +-
Network/Socket/Internal.hsc | 2 +-
Network/Socket/Types.hsc | 14 +++-----
cbits/HsNet.c | 18 ++++++++++
configure | 1 +
include/HsNetworkConfig.h | 4 +--
8 files changed, 36 insertions(+), 105 deletions(-)
diff --git a/Network/BSD.hsc b/Network/BSD.hsc
index 67f2fcd..4c86af5 100644
--- a/Network/BSD.hsc
+++ b/Network/BSD.hsc
@@ -28,12 +28,8 @@ module Network.BSD
, hostAddress
#if defined(HAVE_GETHOSTENT) && !defined(mingw32_HOST_OS)
- , getHostEntries
-
-- ** Low level functionality
- , setHostEntry
, getHostEntry
- , endHostEntry
#endif
-- * Service names
@@ -61,14 +57,6 @@ module Network.BSD
, getProtocolNumber
, defaultProtocol
-#if !defined(mingw32_HOST_OS)
- , getProtocolEntries
- -- ** Low level functionality
- , setProtocolEntry
- , getProtocolEntry
- , endProtocolEntry
-#endif
-
-- * Port numbers
, PortNumber
@@ -80,11 +68,6 @@ module Network.BSD
#if !defined(mingw32_HOST_OS)
, getNetworkByName
, getNetworkByAddr
- , getNetworkEntries
- -- ** Low level functionality
- , setNetworkEntry
- , getNetworkEntry
- , endNetworkEntry
#endif
#if defined(HAVE_IF_NAMETOINDEX)
@@ -298,30 +281,6 @@ getProtocolNumber proto = do
(ProtocolEntry _ _ num) <- getProtocolByName proto
return num
-#if !defined(mingw32_HOST_OS)
-getProtocolEntry :: IO ProtocolEntry -- Next Protocol Entry from DB
-getProtocolEntry = withLock $ do
- ent <- throwNoSuchThingIfNull "getProtocolEntry" "no such protocol entry"
- $ c_getprotoent
- peek ent
-
-foreign import ccall unsafe "getprotoent" c_getprotoent :: IO (Ptr ProtocolEntry)
-
-setProtocolEntry :: Bool -> IO () -- Keep DB Open ?
-setProtocolEntry flg = withLock $ c_setprotoent (fromBool flg)
-
-foreign import ccall unsafe "setprotoent" c_setprotoent :: CInt -> IO ()
-
-endProtocolEntry :: IO ()
-endProtocolEntry = withLock $ c_endprotoent
-
-foreign import ccall unsafe "endprotoent" c_endprotoent :: IO ()
-
-getProtocolEntries :: Bool -> IO [ProtocolEntry]
-getProtocolEntries stayOpen = withLock $ do
- setProtocolEntry stayOpen
- getEntries (getProtocolEntry) (endProtocolEntry)
-#endif
-- ---------------------------------------------------------------------------
-- Host lookups
@@ -405,21 +364,6 @@ getHostEntry = withLock $ do
>>= peek
foreign import ccall unsafe "gethostent" c_gethostent :: IO (Ptr HostEntry)
-
-setHostEntry :: Bool -> IO ()
-setHostEntry flg = withLock $ c_sethostent (fromBool flg)
-
-foreign import ccall unsafe "sethostent" c_sethostent :: CInt -> IO ()
-
-endHostEntry :: IO ()
-endHostEntry = withLock $ c_endhostent
-
-foreign import ccall unsafe "endhostent" c_endhostent :: IO ()
-
-getHostEntries :: Bool -> IO [HostEntry]
-getHostEntries stayOpen = do
- setHostEntry stayOpen
- getEntries (getHostEntry) (endHostEntry)
#endif
-- ---------------------------------------------------------------------------
@@ -482,34 +426,6 @@ getNetworkByAddr addr family = withLock $ do
foreign import ccall unsafe "getnetbyaddr"
c_getnetbyaddr :: NetworkAddr -> CInt -> IO (Ptr NetworkEntry)
-
-getNetworkEntry :: IO NetworkEntry
-getNetworkEntry = withLock $ do
- throwNoSuchThingIfNull "getNetworkEntry" "no more network entries"
- $ c_getnetent
- >>= peek
-
-foreign import ccall unsafe "getnetent" c_getnetent :: IO (Ptr NetworkEntry)
-
--- | Open the network name database. The parameter specifies
--- whether a connection is maintained open between various
--- networkEntry calls
-setNetworkEntry :: Bool -> IO ()
-setNetworkEntry flg = withLock $ c_setnetent (fromBool flg)
-
-foreign import ccall unsafe "setnetent" c_setnetent :: CInt -> IO ()
-
--- | Close the connection to the network name database.
-endNetworkEntry :: IO ()
-endNetworkEntry = withLock $ c_endnetent
-
-foreign import ccall unsafe "endnetent" c_endnetent :: IO ()
-
--- | Get the list of network entries.
-getNetworkEntries :: Bool -> IO [NetworkEntry]
-getNetworkEntries stayOpen = do
- setNetworkEntry stayOpen
- getEntries (getNetworkEntry) (endNetworkEntry)
#endif
-- ---------------------------------------------------------------------------
diff --git a/Network/Socket.hsc b/Network/Socket.hsc
index 8b2e6fe..b02b80d 100644
--- a/Network/Socket.hsc
+++ b/Network/Socket.hsc
@@ -59,7 +59,7 @@ module Network.Socket
, HostName
, ServiceName
-#if defined(IPV6_SOCKET_SUPPORT)
+#if defined(IPV6_SOCKET_SUPPORT) || 1
, AddrInfo(..)
, AddrInfoFlag(..)
@@ -143,7 +143,7 @@ module Network.Socket
-- * Special constants
, aNY_PORT
, iNADDR_ANY
-#if defined(IPV6_SOCKET_SUPPORT)
+#if defined(IPV6_SOCKET_SUPPORTNO)
, iN6ADDR_ANY
#endif
, sOMAXCONN
@@ -521,7 +521,7 @@ accept sock@(MkSocket s family stype protocol status) = do
return new_sock
#else
with (fromIntegral sz) $ \ ptr_len -> do
-# ifdef HAVE_ACCEPT4
+#if 0
new_sock <- throwSocketErrorIfMinus1RetryMayBlock "accept"
(threadWaitRead (fromIntegral s))
(c_accept4 s sockaddr ptr_len (#const SOCK_NONBLOCK))
@@ -903,7 +903,7 @@ packSocketOption so =
Just MaxSegment -> Just ((#const IPPROTO_TCP), (#const TCP_MAXSEG))
#endif
#ifdef TCP_NODELAY
- Just NoDelay -> Just ((#const IPPROTO_TCP), (#const TCP_NODELAY))
+ Just NoDelay -> Nothing -- Just ((#const IPPROTO_TCP), (#const TCP_NODELAY))
#endif
#ifdef TCP_USER_TIMEOUT
Just UserTimeout -> Just ((#const IPPROTO_TCP), (#const TCP_USER_TIMEOUT))
@@ -1036,9 +1036,9 @@ iNADDR_ANY :: HostAddress
iNADDR_ANY = htonl (#const INADDR_ANY)
-- | Converts the from host byte order to network byte order.
-foreign import CALLCONV unsafe "htonl" htonl :: Word32 -> Word32
+foreign import CALLCONV unsafe "my_htonl" htonl :: Word32 -> Word32
-- | Converts the from network byte order to host byte order.
-foreign import CALLCONV unsafe "ntohl" ntohl :: Word32 -> Word32
+foreign import CALLCONV unsafe "my_ntohl" ntohl :: Word32 -> Word32
#if defined(IPV6_SOCKET_SUPPORT)
-- | The IPv6 wild card address.
@@ -1206,7 +1206,7 @@ unpackBits ((k,v):xs) r
-----------------------------------------------------------------------------
-- Address and service lookups
-#if defined(IPV6_SOCKET_SUPPORT)
+#if defined(IPV6_SOCKET_SUPPORT) || 1
-- | Flags that control the querying behaviour of 'getAddrInfo'.
-- For more information, see <https://tools.ietf.org/html/rfc3493#page-25>
@@ -1568,7 +1568,7 @@ foreign import CALLCONV unsafe "bind"
c_bind :: CInt -> Ptr SockAddr -> CInt{-CSockLen???-} -> IO CInt
foreign import CALLCONV SAFE_ON_WIN "connect"
c_connect :: CInt -> Ptr SockAddr -> CInt{-CSockLen???-} -> IO CInt
-#ifdef HAVE_ACCEPT4
+#if 0
foreign import CALLCONV unsafe "accept4"
c_accept4 :: CInt -> Ptr SockAddr -> Ptr CInt{-CSockLen???-} -> CInt -> IO CInt
#else
diff --git a/Network/Socket/ByteString.hsc b/Network/Socket/ByteString.hsc
index 93e29c9..a736932 100644
--- a/Network/Socket/ByteString.hsc
+++ b/Network/Socket/ByteString.hsc
@@ -177,7 +177,7 @@ sendMany sock@(MkSocket fd _ _ _ _) cs = do
liftM fromIntegral . withIOVec cs $ \(iovsPtr, iovsLen) ->
throwSocketErrorWaitWrite sock "writev" $
c_writev (fromIntegral fd) iovsPtr
- (fromIntegral (min iovsLen (#const IOV_MAX)))
+ (fromIntegral (min iovsLen (0x0026)))
#else
sendMany sock = sendAll sock . B.concat
#endif
diff --git a/Network/Socket/Internal.hsc b/Network/Socket/Internal.hsc
index c8bf4f6..2463bd7 100644
--- a/Network/Socket/Internal.hsc
+++ b/Network/Socket/Internal.hsc
@@ -24,7 +24,7 @@ module Network.Socket.Internal
(
-- * Socket addresses
HostAddress
-#if defined(IPV6_SOCKET_SUPPORT)
+#if defined(IPV6_SOCKET_SUPPORTNO)
, HostAddress6
, FlowInfo
, ScopeID
diff --git a/Network/Socket/Types.hsc b/Network/Socket/Types.hsc
index b42c98d..e5bb9fe 100644
--- a/Network/Socket/Types.hsc
+++ b/Network/Socket/Types.hsc
@@ -758,10 +758,10 @@ intToPortNumber v = PortNum (htons (fromIntegral v))
portNumberToInt :: PortNumber -> Int
portNumberToInt (PortNum po) = fromIntegral (ntohs po)
-foreign import CALLCONV unsafe "ntohs" ntohs :: Word16 -> Word16
-foreign import CALLCONV unsafe "htons" htons :: Word16 -> Word16
-foreign import CALLCONV unsafe "ntohl" ntohl :: Word32 -> Word32
-foreign import CALLCONV unsafe "htonl" htonl :: Word32 -> Word32
+foreign import CALLCONV unsafe "my_ntohs" ntohs :: Word16 -> Word16
+foreign import CALLCONV unsafe "my_htons" htons :: Word16 -> Word16
+foreign import CALLCONV unsafe "my_ntohl" ntohl :: Word32 -> Word32
+foreign import CALLCONV unsafe "my_htonl" htonl :: Word32 -> Word32
instance Enum PortNumber where
toEnum = intToPortNumber
@@ -1071,13 +1071,9 @@ poke32 p i0 a = do
-- | Private newtype proxy for the Storable instance. To avoid orphan instances.
newtype In6Addr = In6Addr HostAddress6
-#if __GLASGOW_HASKELL__ < 800
-#let alignment t = "%lu", (unsigned long)offsetof(struct {char x__; t (y__); }, y__)
-#endif
-
instance Storable In6Addr where
sizeOf _ = #const sizeof(struct in6_addr)
- alignment _ = #alignment struct in6_addr
+ alignment _ = 64
peek p = do
a <- peek32 p 0
diff --git a/cbits/HsNet.c b/cbits/HsNet.c
index 86b55dc..6225c32 100644
--- a/cbits/HsNet.c
+++ b/cbits/HsNet.c
@@ -6,3 +6,21 @@
#define INLINE
#include "HsNet.h"
+
+#include <sys/endian.h>
+uint16_t my_htons(uint16_t v)
+{
+ htons(v);
+}
+uint32_t my_htonl(uint32_t v)
+{
+ htonl(v);
+}
+uint16_t my_ntohs(uint16_t v)
+{
+ ntohs(v);
+}
+uint32_t my_ntohl(uint32_t v)
+{
+ ntohl(v);
+}
diff --git a/configure b/configure
index 9e82879..24ef3ce 100755
--- a/configure
+++ b/configure
@@ -1,4 +1,5 @@
#! /bin/sh
+set -- --host=arm-linux-androideabi
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for Haskell network package 2.3.0.14.
#
diff --git a/include/HsNetworkConfig.h b/include/HsNetworkConfig.h
index 383f6e2..62b8852 100644
--- a/include/HsNetworkConfig.h
+++ b/include/HsNetworkConfig.h
@@ -2,7 +2,7 @@
/* include/HsNetworkConfig.h.in. Generated from configure.ac by autoheader. */
/* Define to 1 if you have the `accept4' function. */
-#define HAVE_ACCEPT4 1
+/* #undef HAVE_ACCEPT4 */
/* Define to 1 if you have the <arpa/inet.h> header file. */
#define HAVE_ARPA_INET_H 1
@@ -73,7 +73,7 @@
#define HAVE_LIMITS_H 1
/* Define to 1 if you have the <linux/can.h> header file. */
-#define HAVE_LINUX_CAN_H 1
+/* #undef HAVE_LINUX_CAN_H */
/* Define to 1 if you have a Linux sendfile(2) implementation. */
#define HAVE_LINUX_SENDFILE 1
--
2.1.4