Moving the portability handling into a small C library cleans up things a lot, avoiding the pain of unpacking structs from inside haskell code.