From: Mark Lorenzen <mark.lorenzen@ofir.dk>
Subject: Re: POSIX.Memory_Mapping.Map_Memory
Date: 30 Jan 2005 16:39:48 +0100
Date: 2005-01-30T16:39:48+01:00 [thread overview]
Message-ID: <m3sm4japtn.fsf@0x5358c0df.boanxx18.adsl-dhcp.tele.dk> (raw)
In-Reply-To: 1107053159.644479.173850@z14g2000cwz.googlegroups.com
"Adrian Hoe" <byhoe@greenlime.com> writes:
> Mark Lorenzen wrote:
> >
> > In the way you are using Map_Memeory, it is probably because the
> value
> > of Offset (i.e. 0) is not page aligned.
> >
> > On many implementations, you can only map a multiple of the page size
> > and the memory has to be page aligned.
> >
>
>
>
> I wrote a short C program to test mmap. It works and seems like no
> problem doing mmap. The C code is as below:
>
> ---------------------------------------------------------------------
> #include <stdio.h>
> #include <fcntl.h>
> #include "linux/ioctl.h"
> #include "sys/ioctl.h"
> #include "sys/mman.h"
>
> int main ()
> {
> int fd;
> int bufsize;
> int result;
> char *buf;
>
> fd = open ("/dev/video0", O_RDWR);
>
> if (fd < 0) {
> printf ("Error open device.\n");
> exit (1);
> }
>
> bufsize = 320 * 240 * 3;
> buf=mmap(0, bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
>
> if (!buf) {
Note that mmap wil NEVER return 0, so the check should be "if (buf ==
MAP_FAILED)".
> printf ("mmap error.\n");
> exit (1);
> }
> else {
> printf ("mmap successful.\n");
> }
>
> result = munmap (buf, bufsize);
> printf ("unmap successful.\n");
> close (fd);
> printf ("device closed.\n");
>
> return (0);
> }
> ---------------------------------------------------------------------
>
> Is this gnat/florist error or just as what you mentioned about page
> alignment?
I corrected the above mentioned problem and successfully opened and
mapped a file. Strange.
>
> I am using gcc/gnat 3.3.3 and florist 3.15p on SuSE Linux 9.1 Pro on
> AMD Athlon. I have no problem with both gcc/gnat and florist. My other
> programs using both for RS-232 interface have no problems at all.
> Now, I'm in despair with curiosity! :-)
Please try to run the program using strace and see how mmap is
actually called.
> --
> Adrian Hoe
- Mark Lorenzen
next prev parent reply other threads:[~2005-01-30 15:39 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-01-29 15:58 POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-29 16:20 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-29 16:31 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-29 18:44 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 2:45 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 2:48 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 15:39 ` Mark Lorenzen [this message]
2005-01-30 16:02 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 16:19 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 16:36 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 18:51 ` POSIX.Memory_Mapping.Map_Memory Florian Weimer
2005-02-27 6:59 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-02-27 13:03 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
2005-01-30 16:05 ` POSIX.Memory_Mapping.Map_Memory Adrian Hoe
2005-01-30 16:22 ` POSIX.Memory_Mapping.Map_Memory Mark Lorenzen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox