Factor Language Blog

Warning: User mode Linux mmap() is broken

Wednesday, September 13, 2006

On my linode, this program hangs instead of dying with a segfault:

#include <sys/mman.h>
#include <stdlib.h>

int main()
{
 int pagesize = getpagesize();

 int *array = mmap((void*)0,pagesize,
  PROT_NONE,MAP_ANON | MAP_PRIVATE,-1,0);

 if(!array)
  abort();

 printf("%x\n",*array);
}

This is a serious issue. It causes Factor to hang on stack underflow if the underflow was caused by a memory read (eg, dup with an empty stack).

Of course I don’t use stack underflow errors for control flow, but it makes debugging on the server rather annoying. Perhaps its time to find another hosting provider.