From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Does mmap gives a right result?!
Date: Mon, 4 Oct 2010 01:05:00 -0700 (PDT)
Date: 2010-10-04T01:05:00-07:00 [thread overview]
Message-ID: <03443531-1122-4387-9cfa-fcd922fbbaba@p26g2000yqb.googlegroups.com> (raw)
In-Reply-To: 459d08e4-1370-4925-9d9f-64ee0f472c19@f25g2000yqc.googlegroups.com
Francesco PIRANEO GIULIANO wrote on comp.lang.ada:
>[...] I've imported mmap as follows:
>
> function 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;
> pragma import( C, mmap, "mmap" );
> pragma import_function(mmap);
>
> Void_Ptr is defined as follows:
>
> type void is mod System.Memory_Size;
> for void'Size use System.Word_Size;
>
> type Void_Ptr is access all Void;
> pragma Convention (C, Void_Ptr);
>
> The lines above has been derived by:http://en.wikibooks.org/wiki/Ada_Programming/Types/access#Where_is_vo...
>
> Finally, the mmap has been called as follows:
>
> fbindex := 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 /= -1 otherwise I have
> to raise an exception:
>
> if integer(fbindex) = -1 then
> raise BADMMAPRESULT;
> 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.
next prev parent reply other threads:[~2010-10-04 8:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-03 11:27 Does mmap gives a right result?! Francesco PIRANEO GIULIANO
2010-10-03 17:04 ` Jeffrey Carter
2010-10-03 17:49 ` Björn
2010-10-03 19:22 ` Francesco PIRANEO GIULIANO
2010-10-03 19:32 ` Shark8
2010-10-11 3:03 ` David Thompson
2010-10-04 8:05 ` Ludovic Brenta [this message]
2010-10-04 21:11 ` Francesco PIRANEO GIULIANO
2010-10-04 9:06 ` Jacob Sparre Andersen
2010-10-04 21:08 ` Francesco PIRANEO GIULIANO
2010-10-05 8:19 ` Ludovic Brenta
2010-10-05 13:17 ` Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox