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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5b518364bbeba851,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews1.google.com!k26g2000oda.googlegroups.com!not-for-mail From: "Mattias Lindblad" Newsgroups: comp.lang.ada Subject: POSIX_Generic_Shared_Memory Date: 20 Sep 2004 10:23:10 -0700 Organization: http://groups.google.com Message-ID: <1095700990.407634.230970@k26g2000oda.googlegroups.com> NNTP-Posting-Host: 136.163.203.3 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1095700990 22620 127.0.0.1 (20 Sep 2004 17:23:10 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 20 Sep 2004 17:23:10 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: k26g2000oda.googlegroups.com; posting-host=136.163.203.3; posting-account=5JRrfA0AAAB-ausM18rPNDG9yeoDg7W4 Xref: g2news1.google.com comp.lang.ada:3872 Date: 2004-09-20T10:23:10-07:00 List-Id: Hi, I have found some problems when experimenting with the POSIX_Generic_Shared_Memory package. Let's start with a code example to illustrate my point: ---[shmserv.adb]--- with POSIX_Generic_Shared_Memory, POSIX_IO, POSIX_Memory_Mapping, POSIX.Permissions; with Ada.Text_IO; procedure Shmserv is type Data is record I : Integer; J : Integer; end record; package GSM is new Posix_Generic_Shared_Memory(Data); Descriptor : POSIX_IO.File_Descriptor; Data_Access : GSM.Shared_Access; begin Descriptor := GSM.Open_Or_Create_And_Map_Shared_Memory ("/foo", POSIX_Memory_Mapping.Allow_Write, POSIX.Permissions.Access_Permission_Set); Data_Access := GSM.Access_Shared_Memory(Descriptor); Data_Access.I := 1; loop Ada.Text_IO.Put_Line(Integer'Image(Data_Access.I)); delay(0.5); end loop; end Shmserv; ---[end shmserv.adb]--- ---[shmcli.adb]--- with POSIX_Generic_Shared_Memory, POSIX_IO, POSIX_Memory_Mapping; procedure Shmcli is type Data is record I : Integer; J : Integer; end record; package GSM is new Posix_Generic_Shared_Memory(Data); Descriptor : POSIX_IO.File_Descriptor; Data_Access : GSM.Shared_Access; begin Descriptor := GSM.Open_And_Map_Shared_Memory ("/foo", POSIX_Memory_Mapping.Allow_Write); Data_Access := GSM.Access_Shared_Memory(Descriptor); loop Data_Access.I := Data_Access.I + 1; delay(1.0); end loop; end Shmcli; ---[end shmcli.adb]--- The purpose of this example code is to let one process change data in a shared memory area, while the other process monitors the shared data. It accomplishes this by using the convenient Open_(Or_Create_)And_Map_Shared_Memory functions. However, the client raises a Storage_Error when trying to access the shared data. I have found that this is because the Protection_Options are passed straight through to Map_Memory, and in my case this leads to a memory region that is write-only. The obvious solution would of course be to set Protection_Options to (Allow_Write + Allow_Read). Unfortunately, by doing this the Open_Shared_Memory will be called with a mode of Read_Only. This feels a bit weird, but follows the POSIX 1003.5b standard, 12.5.1.2(1): "If the value of Protection is set to Allow_Write, Mode is Read_Write; otherwise Mode is Read_Only." (From the 1996 version, I'm afraid I haven't access to an updated version). Is this really how it is supposed to work? In my opinion the standard text should read "If the value of Protection *includes* Allow_Write [...]". I have only tried this with GNAT 3.15p and Florist. So I don't know if this might be specific to this system or if it is more general. Any ideas about this? Is it a bug in GNAT, the standard, both of them or none of them (i.e. I'm not doing things the way I'm supposed to)? Thanks, Mattias