Subject: Re: mmap problems
To: Jared D. McNeill <>
From: Chuck Silvers <>
List: tech-kern
Date: 05/27/2001 11:09:35

if "offset" is a signed 32-bit variable then what's happening is that
it's being sign-extended what cast to off_t, making the offset negative,
which isn't what you want.  make sure that the upper bits of the value
passed to mmap() as the offset are zero.


On Sun, May 27, 2001 at 02:02:17PM -0300, Jared D. McNeill wrote:
> I've been working on updating the emulators/snes9x package to 1.37c, and
> in the process I remembered that DGA didn't work in the current package.
> So, I've been poking around with things, and it looks like mmap is failing
> where it shouldn't be.
> >From XF86DGA.c:
>    /* This requires linux-0.99.pl10 or above */
>    *addr = (void *)mmap(NULL, *bank, PROT_READ,
>                         MAP_FILE | MAP_SHARED, fd,
>                         (off_t)offset + bus_base_addr);
> #ifdef DEBUG
>    fprintf(stderr, "XF86DGAGetVideo: physaddr: 0x%08x, size: %d\n",
>            (long)offset, *bank);
> #endif
>    if (*addr == (char *) -1) {
>         fprintf(stderr, "XF86DGAGetVideo: failed to mmap %s (%s)\n",
>                            DEV_MEM, strerror(errno));
>         exit (-2);
>    }
> Running snes9x (with DGA support) at securelevel -1 (with or without the
> aperture driver loaded) yields the following:
> sun:/home/jmcneill/roms# snes9x -y
> Rate: 22050, Buffer size: 1024, 16-bit: yes, Stereo: yes, Encoded: yes
> Found ROM file header (and ignored it).
> "STAR FOX" [checksum ok] LoROM, 8Mbits, Type: ROM+SuperFX, Mode: 20, TV:
> NTSC, S-RAM: 64Kb, ROMId: ???? Company: ??
> XF86DGAGetVideo: physaddr: 0xca000000, size: 16646144
> XF86DGAGetVideo: failed to mmap /dev/mem (Invalid argument)
> According to the mmap(2) man page, mmap should only fail with EINVAL and
> the flags that XF86DGAGetVideo uses if len (in this case, size (which is
> 16646144)) is less than zero.
> The current xmame package exhibits the same behavior. Is this a bug with
> UVM, mmap, or libXxf86dga?
> Thanks,
> Jared