comp.lang.ada
 help / color / mirror / Atom feed
* Posix.4 memory mapping from Ada programs
@ 1997-05-06  0:00 billimad
  1997-05-06  0:00 ` David C. Hoos, Sr.
  0 siblings, 1 reply; 2+ messages in thread
From: billimad @ 1997-05-06  0:00 UTC (permalink / raw)



I have been trying to use the Posix.4 memory mapping functions from an
Ada program, but without total success. I have managed to successfully
map static arrays but have been having more problems trying to map
access to array types.

For example, for types defined as such -

	type Integer_Array is array(1..10) of Integer;
	type integer_Array_Ptr is access all Integer_Array;

using (via a pragma IMPORT),

	Integer_Array_ptr := mmap(NULL, size, PROT_READ, MAP_SHARED,     
file_descriptor, 0ffset);

produces the desired result (i.e. the array can be read using
Integer_Array_Ptr(I)).

But, using -

	type Integer_Array is array(Integer range <>) of Integer;
	type Integer_Array_ptr is access all Integer_Array;

and using the same mmap function call produces an "Illegal Instruction"
run-time report when the program returns from the mmap function call.
The mmap function itself works fine (it is called from a small C
routine and code placed in there confirms that the mapping works). I
see the problem being in the asignment of Integer_Array_Ptr to the
return address from the mmap function.

We thought this may be due to the extra dope information present in Ada
arrays. So we then tried declaring the access type and allocating
memory to it (to fill in the extra dope information) -

	Array_Ptr := new Integer_Array(1..Size);

and then using the address of Array_ptr (Array_Ptr.all(1)'Address) as
the desired address to the mmap function (in place of NULL above). The
mmap function also requires MAP_SHARED to be changed to MAP_FIXED and
that the desired address is aligned on a page boundary.  We attempted
to satisfy this constraint by allocating an integer, determining its
address, and padding out to the next page boundary. We were still
unsuccessful with the mmap function.

I wonder whther anyone else tried to use memory mapping from Ada
programs (with or without success)?

Also, I have heard of the Posix.5 Ada language bindings to Posix.1 and
Posix.20 bindings to Posix.4. Is this still a work is progress, and
does anyone have any pointers (on-line, or off-line) to material of
this nature?

Any help would be gratefully appreciated. For your information, I am
using SunOS 5.5.1, gcc (v2.7), and gnatbl.

Thanks Andy




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Posix.4 memory mapping from Ada programs
  1997-05-06  0:00 Posix.4 memory mapping from Ada programs billimad
@ 1997-05-06  0:00 ` David C. Hoos, Sr.
  0 siblings, 0 replies; 2+ messages in thread
From: David C. Hoos, Sr. @ 1997-05-06  0:00 UTC (permalink / raw)



I have been using memory mapping for some years now with VADS on SGI
platforms.  We have always used a constrained (two-dimensional) array type,
though.  The array dimensions are computed at run-time based on the known
dimensions and the array element type associate with the file, and the
required type is declared in a local declare block.
These files have been up to 500+ Mb. in size, and all works as expected.
The Ada interface is based in pragma interface to the underlying mmap, and
associated c- library.

Although this particular code has not yet been ported to Ada95, I see no
reason why it would not work, as long as you stick to constrained arrays.  

Hope this helps

David C. Hoos, Sr.

http://www.ada95.com

billimad <billimad@vanuata.dcs.gla.ac.uk> wrote in article
<5kname$iv7@singer.cent.gla.ac.uk>...
> I have been trying to use the Posix.4 memory mapping functions from an
> Ada program, but without total success. I have managed to successfully
> map static arrays but have been having more problems trying to map
> access to array types.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-05-06  0:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-05-06  0:00 Posix.4 memory mapping from Ada programs billimad
1997-05-06  0:00 ` David C. Hoos, Sr.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox