mmap & MAP_FIXED

From: Antonio Musumeci (bile_at_landofbile.com)
Date: 10/28/04

  • Next message: John Reiser: "Re: mmap & MAP_FIXED"
    Date: 28 Oct 2004 07:38:15 -0700
    
    

    i'm not sure if this is a mmap or ld-linux bug... or if it's just a
    no-no and shouldnt work regardless.

      pagesize = getpagesize();
      
      fd = open("mapped_data", O_CREAT|O_RDWR, 0666);

      lseek(fd, pagesize-1, SEEK_SET);
      write(fd, "X", 1);
      ptr = mmap(0, pagesize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
      printf("%p\n", ptr);
      
      for(i = 1; i < 10; i++)
        {
          lseek(fd, ((pagesize*(i+1))-1), SEEK_SET);
          write(fd, "X", 1);
          ptr = mmap(ptr+pagesize, pagesize, PROT_READ|PROT_WRITE,
    MAP_SHARED|MAP_FIXED, fd, pagesize*i);
          printf("%p\n", ptr);
          strcpy(ptr, "HNC");
        }

    When dynamically compiled... i get this

    0xb7feb000
    0xb7fec000

    Program received signal SIGSEGV, Segmentation fault.
    0xb7ff3c50 in _dl_rtld_di_serinfo () from /lib/ld-linux.so.2

    the seg is at the strcpy but if i remove it it will give the same
    fault when it exits. this code works however when statically compiled.
    This is similar to what gdb's mmalloc does/did... but that also fails
    the same way.

    Linux 2.6.9, glibc 2.3.3, gcc 3.3.4

    any ideas?


  • Next message: John Reiser: "Re: mmap & MAP_FIXED"

    Relevant Pages

    • Re: make cores on 5.4-RELEASE amd64 but not on i386, need a maintainer.
      ... The hardware is OK, no other troubles. ... > This could be a hint to the bug in suffix parsing that Matt found some ... Using current make it does Not Segmentation fault, ...
      (freebsd-current)
    • Re: Problems with my little c-program
      ... > segmentation fault after running my program. ... find a bug, you need to find which of your assumptions is wrong, ... Make a diagram of a two-element list, ... Take a couple of tokens - two distinct coins, ...
      (comp.lang.c)
    • Re: Doubt on segmentation fault
      ... Here how kernel is creating ... generates a segmentation fault. ... the stack, the value should always be zero. ... I'm not referring to a bug in the underlying OS, but I was hinting at the fact that ...
      (comp.os.linux.development.system)
    • Re: Syscall problem
      ... Sommers" writes: ... >> the problem is that my program produces a segmentation fault but I ... 1st bug in MS win2k source code found after 20 minutes: ...
      (alt.lang.asm)
    • Re: malloc error
      ... > from within malloc. ... > I would like to re-create this bug within a debugger. ... > segmentation fault happens so infrequently that I think I need to have ... It's an app bug. ...
      (comp.lang.cpp)