From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7e32386ac8078f13 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!proxad.net!news.tele.dk!news.tele.dk!small.news.tele.dk!not-for-mail Sender: malo@0x5358c0df.boanxx18.adsl-dhcp.tele.dk Newsgroups: comp.lang.ada Subject: Re: POSIX.Memory_Mapping.Map_Memory References: <1107014307.952357.216870@f14g2000cwb.googlegroups.com> <1107016260.265640.138990@z14g2000cwz.googlegroups.com> <1107053159.644479.173850@z14g2000cwz.googlegroups.com> From: Mark Lorenzen Date: 30 Jan 2005 16:39:48 +0100 Message-ID: User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Organization: TDC Totalloesninger NNTP-Posting-Host: 83.88.192.223 X-Trace: 1107099588 dtext02.news.tele.dk 170 83.88.192.223:53454 X-Complaints-To: abuse@post.tele.dk Xref: g2news1.google.com comp.lang.ada:8077 Date: 2005-01-30T16:39:48+01:00 List-Id: "Adrian Hoe" 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 > #include > #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