[Haskell-cafe] getSymbolicLinkStatus completely broken on some 6.8.2 systems

Adam Langley agl at imperialviolet.org
Wed Feb 13 01:44:17 EST 2008

On Feb 12, 2008 8:38 PM, Jeremy Shaw <jeremy.shaw at linspireinc.com> wrote:
> I get funny results when I call getSymbolicLinkStatus in ghc 6.8.2 on
> Ubuntu 7.10. This happens on several systems and has been confirmed by
> other people.

Currently I'm looking at hsc2hs for this bug. On a 32 bit box here:

int main() {
  struct stat st;
  printf("size of structure is %d\n", sizeof(st));
  printf("inode is at offset %d\n", __builtin_offsetof(struct stat, st_ino));


size of structure is 88
inode is at offset 12

However, building Files.hsc gives:

fileID (FileStatus stat) =
  unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 88))
{-# LINE 315 "Files.hsc" #-}

e.g. it's reading random memory at the end of the structure. Looking
at the code from the documentation:


fileID (FileStatus stat) =
  unsafePerformIO $ withForeignPtr stat $ ((\hsc_ptr -> peekByteOff hsc_ptr 8))
{-# LINE 315 "System/Posix/Files.hsc" #-}

Seems like it might work, but that offset is too small. It appears
that it might be a 64-bit build (because the size of the stat
structure which when it gets malloced is 144), but a 64-bit build
should have larger offsets, not smaller.

You can't write your own fileID function, because FileStatus isn't
exported from Posix.Files. You can, however, write
getSymbolicLinkInode a c function (which does both the lstat and
extraction from the structure) and FFI it.


Adam Langley                                      agl at imperialviolet.org
http://www.imperialviolet.org                       650-283-9641

More information about the Haskell-Cafe mailing list