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.8 required=5.0 tests=BAYES_00,PLING_QUERY autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,9a5e0182cbfaa45b X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!p26g2000yqb.googlegroups.com!not-for-mail From: Ludovic Brenta Newsgroups: comp.lang.ada Subject: Re: Does mmap gives a right result?! Date: Mon, 4 Oct 2010 01:05:00 -0700 (PDT) Organization: http://groups.google.com Message-ID: <03443531-1122-4387-9cfa-fcd922fbbaba@p26g2000yqb.googlegroups.com> References: <459d08e4-1370-4925-9d9f-64ee0f472c19@f25g2000yqc.googlegroups.com> NNTP-Posting-Host: 153.98.68.197 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1286179500 19432 127.0.0.1 (4 Oct 2010 08:05:00 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 4 Oct 2010 08:05:00 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p26g2000yqb.googlegroups.com; posting-host=153.98.68.197; posting-account=pcLQNgkAAAD9TrXkhkIgiY6-MDtJjIlC User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6 (.NET CLR 3.5.30729),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:14372 Date: 2010-10-04T01:05:00-07:00 List-Id: Francesco PIRANEO GIULIANO wrote on comp.lang.ada: >[...] I've imported mmap as follows: > > =A0 =A0function mmap(addr : in u32; length : in u32; prot : in mmap_prot; > flags : in mmap_flag; fd : in file_id; offset : in u32) return > Void_Ptr; > =A0 =A0pragma import( C, mmap, "mmap" ); > =A0 =A0pragma import_function(mmap); > > Void_Ptr is defined as follows: > > =A0 =A0type void is mod System.Memory_Size; > =A0 =A0for void'Size use System.Word_Size; > > =A0 =A0type Void_Ptr is access all Void; > =A0 =A0pragma Convention (C, Void_Ptr); > > The lines above has been derived by:http://en.wikibooks.org/wiki/Ada_Prog= ramming/Types/access#Where_is_vo... > > Finally, the mmap has been called as follows: > > =A0 =A0 =A0 fbindex :=3D mmap(0, fbhandler.fixinfo.smem_len, > fbhandler.PROT_READ + fbhandler.PROT_WRITE, fbhandler.MAP_FILE + > fbhandler.MAP_SHARED, fbid, 0); > > NOTE: I defined PROT_READ and so on as constants in my code; > > First question: I have to analyze if fbindex is /=3D -1 otherwise I have > to raise an exception: > > =A0 =A0 =A0 if integer(fbindex) =3D -1 then > =A0 =A0 =A0 =A0 =A0 =A0 =A0raise BADMMAPRESULT; > =A0 =A0 =A0 end if; > > ...seems to be the most logical comparision BUT the following error in > compile phase appears: "illegal operand for numeric conversion" -- Any > help is really apreciated here! :-) > > When commenting out the above instructions and starting the compiled > application, everything goes right except, when I try to draw inside > the first location the program hungs with the following: > > raised STORAGE_ERROR : stack overflow (or erroneous memory access) > > I'm quite sure my mmap doesn't run properly. I'm about to makes all > framebuffer's interfacing functions in C then implement the remaining > in Ada but it will be a nice things if everything can be made with the > same language. > > Any clues or opinion is welcome about. Since mmap returns (void*) -1 or a "valid" void pointer, I would import it into Ada as a function returning System.Storage_Elements.Integer_Address, which you can compare against -1 and convert to a System.Address using System.Storage_Elements.To_Address. For example: function mmap (Hint : in System.Address; Length : in System.Storage_Elements.Storage_Count; Prot : in mmap_prot; Flags : in mmap_flag; fd : in file_id; offset : in u32) return System.Storage_Elements.Integer_Address; pragma Import (C, mmap, "mmap"); But all this work (the definition of constants for the flags, the import, the comparison with -1, the raising of an exception and the conversion to System.Address) has already been done in Florist, see the function POSIX.Memory_Mapping.Map_Memory. I suggest you simply "aptitude install libflorist2009-dev", add "with "florist";" to your project file and compile... Once you have the address, you can either: (1) declare the object contained in the file with an address representation clause, or (2) convert the address to an access value using an instance of System.Address_To_Access_Conversions. HTH PS. Jacob has nice stories to tell about this function... -- Ludovic Brenta.