1 ------------------------------------------------------------------------------ 2 ------------------------------------------------------------------------------ 3 -- This file is part of 'Cryostat', an Ada library for persistent storage. -- 4 -- -- 5 -- (C) 2020 Stanislav Datskovskiy ( www.loper-os.org ) -- 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- 7 -- -- 8 -- You do not have, nor can you ever acquire the right to use, copy or -- 9 -- distribute this software ; Should you use this software for any purpose, -- 10 -- or copy and distribute it to anyone or in any manner, you are breaking -- 11 -- the laws of whatever soi-disant jurisdiction, and you promise to -- 12 -- continue doing so for the indefinite future. In any case, please -- 13 -- always : read and understand any software ; verify any PGP signatures -- 14 -- that you use - for any purpose. -- 15 ------------------------------------------------------------------------------ 16 ------------------------------------------------------------------------------ 17 18 ------------------------------------------------------------------------------ 19 -- WARNING : MIPS32/64 currently unsupported! -- 20 -- See also: http://logs.nosuchlabs.com/log/trilema/2018-10-24#1865524 -- 21 ------------------------------------------------------------------------------ 22 23 with Interfaces; use Interfaces; 24 with Interfaces.C; 25 with System; use System; 26 27 28 package Unix is 29 30 pragma Preelaborate; 31 32 -- Machine Word 33 type Word is mod 2**Standard'Address_Size; 34 35 -- Byte 36 type Byte is mod 2**8; 37 38 -- Unit int 39 type Unix_Int is mod 2**Interfaces.C.int'Size; 40 41 -- File descriptors 42 type FD is new Unix_Int; 43 44 type MM_Prot is new Unix_Int; 45 PROT_READ : constant MM_Prot := 1; 46 PROT_WRITE : constant MM_Prot := 2; 47 48 type MM_Flags is new Unix_Int; 49 MAP_NONE : constant MM_Flags := 16#00#; 50 MAP_FIXED : constant MM_Flags := 16#10#; 51 MAP_SHARED : constant MM_Flags := 16#01#; 52 MAP_PRIVATE : constant MM_Flags := 16#02#; 53 -- TODO: MAP_HUGETLB 54 55 -- Null Pointer 56 NullPtr : constant Address := System'To_Address(0); 57 58 function MMap 59 (Start : Address := NullPtr; 60 Length : Word; 61 Prot : MM_Prot; 62 Flags : MM_Flags; 63 Handle : FD; 64 Off_T : Word := 0) 65 return Address; 66 pragma Import(C, MMap, "mmap"); 67 68 -- Eggog code '-1' (posix uses instead of null here) 69 MAP_FAILED : constant Address := System'To_Address(Word'Last); 70 71 function MUnmap 72 (Start : Address; 73 Length : Word) 74 return Unix_Int; 75 pragma Import(C, MUnmap, "munmap"); 76 77 type O_Flags is new Unix_Int; 78 O_RDONLY : constant O_Flags := 8#00#; 79 O_WRONLY : constant O_Flags := 8#01#; 80 O_RDWR : constant O_Flags := 8#02#; 81 O_CREAT : constant O_Flags := 8#0100#; 82 83 type M_Flags is new Unix_Int; 84 MS_ASYNC : constant M_Flags := 1; 85 MS_INVALIDATE : constant M_Flags := 2; 86 MS_SYNC : constant M_Flags := 4; 87 88 function MSync 89 (Addr : Address; 90 Length : Word; 91 Flags : M_Flags) 92 return Unix_Int; 93 pragma Import(C, MSync, "msync"); 94 95 function Open 96 (Name : System.Address; 97 Flags : O_Flags; 98 Mode : Unix_Int := 8#666#) -- TODO 99 return FD; 100 pragma Import(C, Open, "open"); 101 102 -- '-1' 103 FD_EGGOG : constant FD := FD'Last; 104 105 function Close(Handle : FD) return Unix_Int; 106 pragma Import(C, Close, "close"); 107 108 function FTruncate(Handle : FD; Length : Word) return Unix_Int; 109 pragma Import(C, FTruncate, "ftruncate"); 110 111 end Unix;