-
+ 20747487186412CB602107EED5503448CD19D59EF195DD8B44611EFC6BF40DDD566D1F6630BD50D602A84CE820238236C6CA67567897226870A718F9ECB4F584cryostat/libcryo/pmaps.ads(0 . 0)(1 . 110)
810 ------------------------------------------------------------------------------
811 ------------------------------------------------------------------------------
812 -- This file is part of 'Cryostat', an Ada library for persistent storage. --
813 -- --
814 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) --
815 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
816 -- --
817 -- You do not have, nor can you ever acquire the right to use, copy or --
818 -- distribute this software ; Should you use this software for any purpose, --
819 -- or copy and distribute it to anyone or in any manner, you are breaking --
820 -- the laws of whatever soi-disant jurisdiction, and you promise to --
821 -- continue doing so for the indefinite future. In any case, please --
822 -- always : read and understand any software ; verify any PGP signatures --
823 -- that you use - for any purpose. --
824 ------------------------------------------------------------------------------
825 ------------------------------------------------------------------------------
826
827 with System;
828 with Ada.Finalization;
829 with Unix; use Unix;
830
831
832 package PMaps is
833
834 pragma Preelaborate;
835
836 -- Open file for map
837 function OpenMapFile(Path : in String;
838 Writable : in Boolean := False;
839 Create : in Boolean := False)
840 return FD
841 with Pre => not ((not Writable) and Create);
842
843 -- The address in memory where the map resides
844 subtype MapAddress is System.Address;
845
846 -- Internal representation of the map
847 type PMap(Handle : FD; -- Unix FD handle of the open file
848 Length : Word; -- The length (bytes) of the map
849 Offset : Word; -- Offset into the file (normally zero)
850 Create : Boolean; -- Whether to create the file if not exists
851 Writable : Boolean) -- Whether the map is writeable
852 is new Ada.Finalization.Limited_Controlled with private;
853
854 -- Test if map is usable
855 function IsReady(Map : in PMap) return Boolean;
856
857 -- Zero the entire map space
858 procedure Zap(Map : in out PMap);
859
860 -- Sync map to disk immediately
861 procedure Sync(Map : in out PMap);
862
863 -- Close map and mark it unusable
864 procedure Stop(Map : in out PMap);
865
866 -- Retrieve the address at which map resides
867 function GetAddress(Map : in PMap) return MapAddress;
868
869 -- Eggogs
870 PMapFailedOpen : exception; -- Could not open the given file
871 PMapFailedMMap : exception; -- Eggog when performed MMap()
872 PMapFailedAddr : exception; -- MMap() returned an unusable address
873 PMapFailedSync : exception; -- Sync failed
874 PMapFailedUnmap : exception; -- Unmap failed
875 PMapFailedClose : exception; -- Closing backing file failed
876 PMapNotRunning : exception; -- Tried to use an inactive map
877 PMapNotWritable : exception; -- Tried to zap a read-only map
878
879 private
880
881 -- Current state of the map
882 type State is (Stop, Run, Eggog);
883
884 type PMap(Handle : FD;
885 Length : Word;
886 Offset : Word;
887 Create : Boolean;
888 Writable : Boolean) is
889 new Ada.Finalization.Limited_Controlled with
890 record
891 -- Unix FD handle of the open file
892 FileFD : FD := Handle;
893
894 -- Whether to create the file if not exists
895 MapCreate : Boolean := Create;
896
897 -- Whether the map is writeable
898 MapWritable : Boolean := Writable;
899
900 -- The length (bytes) of the map
901 MapLength : Word := Length;
902
903 -- Offset into the file (normally zero)
904 MapOffset : Word := Offset;
905
906 -- The address in memory where the map resides
907 Address : MapAddress := NullPtr;
908
909 -- Current condition of this map
910 Status : State := Stop;
911 end record;
912
913 -- Initialization
914 overriding procedure Initialize(Map : in out PMap);
915
916 -- Automatic sync and close of the map when leaving scope
917 overriding procedure Finalize(Map : in out PMap);
918
919 end PMaps;