NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

mmap and MAP_FIXED



Hi :)

I'm currently working on CLISP and am trying to build it on
NetBSD 7.0 (GENERIC.201509250726Z) amd64. This fails due to a call to mmap
with flags MAP_ANON | MAP_PRIVATE | MAP_FIXED. Some experimenting with a
minimal example program suggests that using MAP_FIXED isn't going to work,
all calls made by this program fail:


#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <stdint.h>

#define PROT_READ_WRITE (PROT_READ | PROT_WRITE)

void try_fixed(void * addr, size_t size) {
  fprintf(stderr, "Trying %p (%zu) fixed\n", addr, size);
  void * result =
    mmap(addr, size, PROT_READ_WRITE,
         MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0);
  if (result == (void *) -1) {
    perror("-- Failed");
  }
}

int main() {
  uintptr_t a = 0x4000000000000; // the address used by CLISP
  uintptr_t e = 0xF000000000000;
  size_t step = 0x10000000000;
  for (; a < e; a += step) {
    try_fixed((void *) a, 0x1000);
  }
  return 0;
}

(This program tests the address that a mmap call without MAP_FIXED returns,
too, but even then it doesn't work.)

A fix for CLISP is to disable its mmap support (which seems to be already
done: http://gnats.netbsd.org/33189), but I'm interested whether any use
of MAP_FIXED is going to work?

The man page https://www.freebsd.org/cgi/man.cgi?query=mmap&manpath=NetBSD+7.0
states for MAP_FIXED:

> Use of this option is discouraged.

Is it only discouraged or completely disabled?
A side note: The error message printed by perror is

> File too large

which is a bit misleading.

Best,
Daniel



Home | Main Index | Thread Index | Old Index