Re: [PATCH] svgalib error in mmap documentation

Christoph Rohland (cr@sap.com)
07 Jan 2001 10:16:49 +0100


Matan Ziv-Av <matan@svgalib.org> writes:

> I hope it is reasonable to ask, how?
>
> What I need is to allocate a big amount of memory (say 1MB, for
> example), copy the video memory to it, and then have fixed 64K of
> virutal address of the process point to any 64K window of the large
> allocated memory. How can I do it?

fd = shm_open("vidmem-filename", O_CREAT,...);
ftruncate(fd, 1<<20);
ptr = mmap(0, 64 * 1<<10, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);

to remap another area:

if (mmap(ptr, 64 * 1<<10, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED,
fd, blocknr * 64 * 1<<10) != ptr)
error();

On exit:

munmap(ptr, 64 * 1<<10);
shm_unlink ("vidmem-filename");

Note the MAP_FIXED argument to the remap operation. You do not need to
unmap on Linux to remap an area when giving MAP_FIXED. (So MAP_FIXED
can to really bad things to your program...)

Greetings
Christoph

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/