NetBSD-Users archive

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

Re: mmap and MAP_FIXED



I haven't tested, or analyzed this to any depth, but I wonder... What is the pagesize of the machine? 8K? I wonder if you might have some issue when you try to map only 4K fixed. The man-page says that if MAP_FIXED is used, the address must be page aligned, but it does not say anything about the size, but it makes me wonder... (Yes, I also noted that the man-page says that size might be rounded up, but interactions with MAP_FIXED as well as MAP_ANON might possibly change the conditions here.)

	Johnny

On 2016-05-12 10:21, Daniel Jour wrote:
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



--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index