Fix OSX RTS crash due to bad coercion.
Fix OSX RTS crash due to bad coercion.

The code coerces Int to CInt, which causes an overflow if Int is bigger
than CInt (for example, Int 64bit, CInt 32 bit). This results in a
negative value being passed to c_poll.

On Linux all negative values are treated as infinite timeouts, which
gives subtly wrong semantics, but is unlikely to produce actual bugs.

OSX insists that only -1 is a valid value for infinite timeout, any
other negative timeout is treated as an invalid argument.

This patch replaces the c_poll call with a loop that handles the
overflow gracefully by chaining multiple calls to poll to obtain the
proper semantics.

Signed-off-by: Austin Seipp <48c905ac3851f382b914247d97dd93273d5ff555@pobox.com>

ml9951/ghc,tjakway/ghcjvm,gcampax/ghc,mfine/ghc,sdiehl/ghc,ml9951/ghc,nushio3/ghc,wxwxwwxxx/ghc,holzensp/ghc,TomMD/ghc,ezyang/ghc,fmthoma/ghc,bitemyapp/ghc,TomMD/ghc,GaloisInc/halvm-ghc,tjakway/ghcjvm,oldmanmike/ghc,da-x/ghc,anton-dessiatov/ghc,ml9951/ghc,tjakway/ghcjvm,urbanslug/ghc,acowley/ghc,snoyberg/ghc,GaloisInc/halvm-ghc,spacekitteh/smcghc,green-haskell/ghc,urbanslug/ghc,sgillespie/ghc,tjakway/ghcjvm,fmthoma/ghc,tibbe/ghc,acowley/ghc,mcschroeder/ghc,ghc-android/ghc,snoyberg/ghc,GaloisInc/halvm-ghc,mettekou/ghc,elieux/ghc,mfine/ghc,jstolarek/ghc,ezyang/ghc,elieux/ghc,ryantm/ghc,urbanslug/ghc,nkaretnikov/ghc,ghc-android/ghc,acowley/ghc,snoyberg/ghc,shlevy/ghc,mcschroeder/ghc,fmthoma/ghc,nkaretnikov/ghc,nushio3/ghc,ghc-android/ghc,acowley/ghc,shlevy/ghc,olsner/ghc,vikraman/ghc,elieux/ghc,olsner/ghc,nkaretnikov/ghc,mfine/ghc,nathyong/microghc-ghc,lukexi/ghc,nkaretnikov/ghc,christiaanb/ghc,siddhanathan/ghc,sdiehl/ghc,ryantm/ghc,spacekitteh/smcghc,nushio3/ghc,vTurbine/ghc,ml9951/ghc,GaloisInc/halvm-ghc,gcampax/ghc,AlexanderPankiv/ghc,sgillespie/ghc,gridaphobe/ghc,frantisekfarka/ghc-dsi,christiaanb/ghc,TomMD/ghc,holzensp/ghc,da-x/ghc,mcschroeder/ghc,mfine/ghc,vikraman/ghc,vTurbine/ghc,bitemyapp/ghc,nathyong/microghc-ghc,oldmanmike/ghc,lukexi/ghc,olsner/ghc,tibbe/ghc,wxwxwwxxx/ghc,GaloisInc/halvm-ghc,sgillespie/ghc,gridaphobe/ghc,bitemyapp/ghc,gcampax/ghc,lukexi/ghc,sdiehl/ghc,anton-dessiatov/ghc,forked-upstream-packages-for-ghcjs/ghc,green-haskell/ghc,oldmanmike/ghc,fmthoma/ghc,tjakway/ghcjvm,snoyberg/ghc,olsner/ghc,gridaphobe/ghc,mcschroeder/ghc,TomMD/ghc,nathyong/microghc-ghc,forked-upstream-packages-for-ghcjs/ghc,ryantm/ghc,shlevy/ghc,green-haskell/ghc,ryantm/ghc,mfine/ghc,gcampax/ghc,jstolarek/ghc,spacekitteh/smcghc,spacekitteh/smcghc,shlevy/ghc,urbanslug/ghc,gridaphobe/ghc,forked-upstream-packages-for-ghcjs/ghc,mfine/ghc,sdiehl/ghc,elieux/ghc,nushio3/ghc,jstolarek/ghc,forked-upstream-packages-for-ghcjs/ghc,christiaanb/ghc,frantisekfarka/ghc-dsi,AlexanderPankiv/ghc,gcampax/ghc,vikraman/ghc,sdiehl/ghc,ml9951/ghc,ezyang/ghc,TomMD/ghc,shlevy/ghc,urbanslug/ghc,bitemyapp/ghc,acowley/ghc,ezyang/ghc,sdiehl/ghc,da-x/ghc,jstolarek/ghc,gridaphobe/ghc,bitemyapp/ghc,siddhanathan/ghc,anton-dessiatov/ghc,snoyberg/ghc,urbanslug/ghc,TomMD/ghc,shlevy/ghc,mettekou/ghc,christiaanb/ghc,ryantm/ghc,vTurbine/ghc,elieux/ghc,wxwxwwxxx/ghc,frantisekfarka/ghc-dsi,urbanslug/ghc,green-haskell/ghc,nkaretnikov/ghc,christiaanb/ghc,AlexanderPankiv/ghc,ghc-android/ghc,forked-upstream-packages-for-ghcjs/ghc,vTurbine/ghc,mcschroeder/ghc,forked-upstream-packages-for-ghcjs/ghc,vTurbine/ghc,wxwxwwxxx/ghc,gridaphobe/ghc,tibbe/ghc,anton-dessiatov/ghc,olsner/ghc,ghc-android/ghc,oldmanmike/ghc,olsner/ghc,oldmanmike/ghc,mettekou/ghc,ezyang/ghc,olsner/ghc,mcschroeder/ghc,forked-upstream-packages-for-ghcjs/ghc,mettekou/ghc,holzensp/ghc,da-x/ghc,spacekitteh/smcghc,sgillespie/ghc,nathyong/microghc-ghc,fmthoma/ghc,vikraman/ghc,nushio3/ghc,AlexanderPankiv/ghc,da-x/ghc,TomMD/ghc,ghc-android/ghc,snoyberg/ghc,christiaanb/ghc,mettekou/ghc,AlexanderPankiv/ghc,sdiehl/ghc,mcschroeder/ghc,ml9951/ghc,nushio3/ghc,ml9951/ghc,lukexi/ghc,GaloisInc/halvm-ghc,anton-dessiatov/ghc,ezyang/ghc,oldmanmike/ghc,wxwxwwxxx/ghc,nathyong/microghc-ghc,elieux/ghc,sgillespie/ghc,mfine/ghc,fmthoma/ghc,vikraman/ghc,christiaanb/ghc,ml9951/ghc,da-x/ghc,tibbe/ghc,ezyang/ghc,nathyong/microghc-ghc,lukexi/ghc,tibbe/ghc,nathyong/microghc-ghc,elieux/ghc,anton-dessiatov/ghc,sgillespie/ghc,gcampax/ghc,mettekou/ghc,mettekou/ghc,acowley/ghc,green-haskell/ghc,siddhanathan/ghc,AlexanderPankiv/ghc,nkaretnikov/ghc,siddhanathan/ghc,nushio3/ghc,jstolarek/ghc,wxwxwwxxx/ghc,sgillespie/ghc,siddhanathan/ghc,holzensp/ghc,vikraman/ghc,snoyberg/ghc,holzensp/ghc,siddhanathan/ghc,AlexanderPankiv/ghc,frantisekfarka/ghc-dsi,GaloisInc/halvm-ghc,anton-dessiatov/ghc,gridaphobe/ghc,shlevy/ghc,tjakway/ghcjvm,nkaretnikov/ghc,fmthoma/ghc,siddhanathan/ghc,tjakway/ghcjvm,vikraman/ghc,oldmanmike/ghc,da-x/ghc,vTurbine/ghc,gcampax/ghc,frantisekfarka/ghc-dsi,vTurbine/ghc,ghc-android/ghc,acowley/ghc,wxwxwwxxx/ghc