-
+ D7DB32741F25095335308C2EFCC1060161B184BFD2FEA87556DE3AF2F7709C0ADF6E7083356DD9A185460083C5FC772D02838A6AF881C9FA93A930011E6A5E24
cryostat/libcryo/unix.ads
(0 . 0)(1 . 111)
1011 ------------------------------------------------------------------------------
1012 ------------------------------------------------------------------------------
1013 -- This file is part of 'Cryostat', an Ada library for persistent storage. --
1014 -- --
1015 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) --
1016 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
1017 -- --
1018 -- You do not have, nor can you ever acquire the right to use, copy or --
1019 -- distribute this software ; Should you use this software for any purpose, --
1020 -- or copy and distribute it to anyone or in any manner, you are breaking --
1021 -- the laws of whatever soi-disant jurisdiction, and you promise to --
1022 -- continue doing so for the indefinite future. In any case, please --
1023 -- always : read and understand any software ; verify any PGP signatures --
1024 -- that you use - for any purpose. --
1025 ------------------------------------------------------------------------------
1026 ------------------------------------------------------------------------------
1027
1028 ------------------------------------------------------------------------------
1029 -- WARNING : MIPS32/64 currently unsupported! --
1030 -- See also: http://logs.nosuchlabs.com/log/trilema/2018-10-24#1865524 --
1031 ------------------------------------------------------------------------------
1032
1033 with Interfaces; use Interfaces;
1034 with Interfaces.C;
1035 with System; use System;
1036
1037
1038 package Unix is
1039
1040 pragma Preelaborate;
1041
1042 -- Machine Word
1043 type Word is mod 2**Standard'Address_Size;
1044
1045 -- Byte
1046 type Byte is mod 2**8;
1047
1048 -- Unit int
1049 type Unix_Int is mod 2**Interfaces.C.int'Size;
1050
1051 -- File descriptors
1052 type FD is new Unix_Int;
1053
1054 type MM_Prot is new Unix_Int;
1055 PROT_READ : constant MM_Prot := 1;
1056 PROT_WRITE : constant MM_Prot := 2;
1057
1058 type MM_Flags is new Unix_Int;
1059 MAP_NONE : constant MM_Flags := 16#00#;
1060 MAP_FIXED : constant MM_Flags := 16#10#;
1061 MAP_SHARED : constant MM_Flags := 16#01#;
1062 MAP_PRIVATE : constant MM_Flags := 16#02#;
1063 -- TODO: MAP_HUGETLB
1064
1065 -- Null Pointer
1066 NullPtr : constant Address := System'To_Address(0);
1067
1068 function MMap
1069 (Start : Address := NullPtr;
1070 Length : Word;
1071 Prot : MM_Prot;
1072 Flags : MM_Flags;
1073 Handle : FD;
1074 Off_T : Word := 0)
1075 return Address;
1076 pragma Import(C, MMap, "mmap");
1077
1078 -- Eggog code '-1' (posix uses instead of null here)
1079 MAP_FAILED : constant Address := System'To_Address(Word'Last);
1080
1081 function MUnmap
1082 (Start : Address;
1083 Length : Word)
1084 return Unix_Int;
1085 pragma Import(C, MUnmap, "munmap");
1086
1087 type O_Flags is new Unix_Int;
1088 O_RDONLY : constant O_Flags := 8#00#;
1089 O_WRONLY : constant O_Flags := 8#01#;
1090 O_RDWR : constant O_Flags := 8#02#;
1091 O_CREAT : constant O_Flags := 8#0100#;
1092
1093 type M_Flags is new Unix_Int;
1094 MS_ASYNC : constant M_Flags := 1;
1095 MS_INVALIDATE : constant M_Flags := 2;
1096 MS_SYNC : constant M_Flags := 4;
1097
1098 function MSync
1099 (Addr : Address;
1100 Length : Word;
1101 Flags : M_Flags)
1102 return Unix_Int;
1103 pragma Import(C, MSync, "msync");
1104
1105 function Open
1106 (Name : System.Address;
1107 Flags : O_Flags;
1108 Mode : Unix_Int := 8#666#) -- TODO
1109 return FD;
1110 pragma Import(C, Open, "open");
1111
1112 -- '-1'
1113 FD_EGGOG : constant FD := FD'Last;
1114
1115 function Close(Handle : FD) return Unix_Int;
1116 pragma Import(C, Close, "close");
1117
1118 function FTruncate(Handle : FD; Length : Word) return Unix_Int;
1119 pragma Import(C, FTruncate, "ftruncate");
1120
1121 end Unix;