[gcc]
[official-gcc.git] / gcc / ada / s-mmosin-unix.ads
blob002bf7743517c4e8cea05731ce5cffbd0a3deca5
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . M M A P . O S _ I N T E R F A C E --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2007-2016, AdaCore --
10 -- --
11 -- This library is free software; you can redistribute it and/or modify it --
12 -- under terms of the GNU General Public License as published by the Free --
13 -- Software Foundation; either version 3, or (at your option) any later --
14 -- version. This library is distributed in the hope that it will be useful, --
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- --
16 -- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- As a special exception under Section 7 of GPL version 3, you are granted --
19 -- additional permissions described in the GCC Runtime Library Exception, --
20 -- version 3.1, as published by the Free Software Foundation. --
21 -- --
22 -- You should have received a copy of the GNU General Public License and --
23 -- a copy of the GCC Runtime Library Exception along with this program; --
24 -- see the files COPYING3 and COPYING.RUNTIME respectively. If not, see --
25 -- <http://www.gnu.org/licenses/>. --
26 -- --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
29 -- --
30 ------------------------------------------------------------------------------
32 with System.OS_Lib;
34 -- OS pecularities abstraction package for Unix systems.
36 package System.Mmap.OS_Interface is
38 type System_File is record
39 Fd : System.OS_Lib.File_Descriptor;
41 Mapped : Boolean;
42 -- Whether mapping is requested by the user and available on the system
44 Write : Boolean;
45 -- Whether this file can be written to
47 Length : File_Size;
48 -- Length of the file. Used to know what can be mapped in the file
49 end record;
51 type System_Mapping is record
52 Address : Standard.System.Address;
53 Length : File_Size;
54 end record;
56 Invalid_System_File : constant System_File :=
57 (System.OS_Lib.Invalid_FD, False, False, 0);
58 Invalid_System_Mapping : constant System_Mapping :=
59 (Standard.System.Null_Address, 0);
61 function Open_Read
62 (Filename : String;
63 Use_Mmap_If_Available : Boolean := True) return System_File;
64 -- Open a file for reading and return the corresponding System_File. Return
65 -- Invalid_System_File if unsuccessful.
67 function Open_Write
68 (Filename : String;
69 Use_Mmap_If_Available : Boolean := True) return System_File;
70 -- Likewise for writing to a file
72 procedure Close (File : in out System_File);
73 -- Close a system file
75 function Read_From_Disk
76 (File : System_File;
77 Offset, Length : File_Size) return System.Strings.String_Access;
78 -- Read a fragment of a file. It is up to the caller to free the result
79 -- when done with it.
81 procedure Write_To_Disk
82 (File : System_File;
83 Offset, Length : File_Size;
84 Buffer : System.Strings.String_Access);
85 -- Write some content to a fragment of a file
87 procedure Create_Mapping
88 (File : System_File;
89 Offset, Length : in out File_Size;
90 Mutable : Boolean;
91 Mapping : out System_Mapping);
92 -- Create a memory mapping for the given File, for the area starting at
93 -- Offset and containing Length bytes. Store it to Mapping.
94 -- Note that Offset and Length may be modified according to the system
95 -- needs (for boudaries, for instance). The caller must cope with actually
96 -- wider mapped areas.
98 procedure Dispose_Mapping
99 (Mapping : in out System_Mapping);
100 -- Unmap a previously-created mapping
102 function Get_Page_Size return File_Size;
103 -- Return the number of bytes in a system page.
105 end System.Mmap.OS_Interface;