Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unix Shared Memory from Ada

147 views
Skip to first unread message

as...@motown.ge.com

unread,
Nov 18, 1993, 6:52:40 PM11/18/93
to

Have any of you Ada experts utilized Unix shared memory system calls in an Ada program?


Here is how I do it:


function shmget(key: integer; size: integer; shmflag: integer) return integer;
pragma interface(C, shmget);

function shmat(shmid: integer; shmaddr: address; shmflag: integer) return address;
pragma interface(C, shmat);

SHMID: INTEGER;

...

begin
SHMID := SHMGET(0, 100, 8#600#);
...

end;


The problem is that the returned SHMID is a valid number (i.e. not equal to -1), but
the shared memory segment is NOT being created. I use the ipcs command to check for
the shared memory and it's not there. I have used the shmget() call in a C program
with the same parameters and it works fine.

I am using Sun Ada (Verdix).

Any ideas?

Anthony

Bob Wells #402

unread,
Nov 19, 1993, 8:23:54 AM11/19/93
to
Anthony,

Are you actually linking in what you think you are? Why is there
no Verdix-defined pragma INTERFACE_NAME being used?

Does the size for the Ada type "integer" match the sizes of the Unix
types "key_t" and "int?" Try compiling a trivial C program that will
print out what is coming across in the "C world." The call this via
your pragmas INTERFACE and INTERFACE_NAME.

Are you compiling with the "-w" option set so that you are
missing out on warnings about incorrect parameter type sizes?
I think Verdix will only let you have 32 bits as the size. (Have a
look at the programmers guide, chapter 4 (I think?))

Bob Wells.

Chris Warack <sys mgr>

unread,
Nov 19, 1993, 12:00:17 PM11/19/93
to
I haven't actually done shared memory stuff -- but a c int is not equivalent
to an Ada integer. I think you want your Ada parameters to be short_integers
and either use a short_integer provided by your compiler or define your own.

-- Chris

--
Christopher A. Warack, Capt, USAF
Computer Science Department, US Air Force Academy

cwa...@kirk.usafa.af.mil (719) 472-2401

LJ1...@lmsc5.is.lmsc.lockheed.com

unread,
Nov 21, 1993, 12:40:10 PM11/21/93
to
I am using shared memory with Verdix Ada on a DECStation under Ultrix,
and also had problems for a while. Two things I encountered:

1 - For some reason I could never get "shmget" to work with what I thought
was a reasonable flag value "16#1666#", but it did work with "10#932#. I
was never able to get Verdix to explain to me why this was so. 932 came
from a fax they sent me of FAQs about shared memory. You should be able
to request it from their software support department.

2 - Once you have allocated a block of memory and attached it to your
process, variables declared to be within the shared block of memory need
a user-defined AA_GLOBAL_ALLOC routine to overlaod the standard allocation
routine of the Verdix Ada environment. This is also covered in the
aforementioned FAQ.

Without comparing my code to yours in greater detail, I can offer
little else, but reassurance. Once I finally did get it working, it worked
really well, doing exactly what I wanted it to do.

************************************************
G_Ha...@qm.is.lmsc.lockheed.com
I found these opinions on my doorstep, would you please give them a good home?
************************************************

Oystein Torbjornsen

unread,
Nov 21, 1993, 3:53:12 PM11/21/93
to
In article <93325.348...@LMSC5.IS.LMSC.LOCKHEED.COM>, LJ1...@LMSC5.IS.LMSC.LOCKHEED.COM writes:
|> I am using shared memory with Verdix Ada on a DECStation under Ultrix,
|> and also had problems for a while. Two things I encountered:
|>
|> 1 - For some reason I could never get "shmget" to work with what I thought
|> was a reasonable flag value "16#1666#", but it did work with "10#932#. I
^^^^^^^^^ -> 8#1666#

|> was never able to get Verdix to explain to me why this was so. 932 came
|> from a fax they sent me of FAQs about shared memory. You should be able
|> to request it from their software support department.

The flag values are coded with 3 bits for each of the 3 permission flags (at
least on the Sun), a total of 9 bits. The flags should therefore be coded in
octal, ie. 8#1666#. I guess you wanted to create the memory with a "rw-rw-rw-"
permission flag [ie. (IPC_CREAT | 0666) in C]. 10#932#=8#1644#, ie. create
with "rw-r--r--" permissions.

--
Oystein Torbjornsen Phone: +47 73 59 70 57 (office)
Division of Computer Systems and Telematics +47 73 52 92 91 (home)
Norwegian Institute of Technology Email: oy...@hobbes.er.sintef.no
N-7034 Trondheim, Norway or oys...@idt.unit.no

LJ1...@lmsc5.is.lmsc.lockheed.com

unread,
Nov 22, 1993, 1:37:56 PM11/22/93
to
------------------------- Original Article -------------------------

|> 1 - For some reason I could never get "shmget" to work with what I thought
|> was a reasonable flag value "16#1666#", but it did work with "10#932#. I
^^^^^^^^^ -> 8#1666#
|> was never able to get Verdix to explain to me why this was so. 932 came
|> from a fax they sent me of FAQs about shared memory. You should be able
|> to request it from their software support department.

>The flag values are coded with 3 bits for each of the 3 permission flags (at
>least on the Sun), a total of 9 bits. The flags should therefore be coded in
>octal, ie. 8#1666#. I guess you wanted to create the memory with a "rw-rw-rw-"
>permission flag [ie. (IPC_CREAT | 0666) in C]. 10#932#=8#1644#, ie. create
>with "rw-r--r--" permissions.

Thanks. I looked at (what I thought were) the appropriate header files
to get the Ultrix bit map, but I missed that somehow.

**************************************
G_Ha...@qm.is.lmsc.lockheed.com
I found these opinions on my doorstep, could you please give them a good home?
**************************************

0 new messages