1 ------------------------------------------------------------------------------
3 -- GNAT RUN-TIME COMPONENTS --
5 -- S Y S T E M . M M A P . O S _ I N T E R F A C E --
9 -- Copyright (C) 2007-2019, AdaCore --
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. --
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. --
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/>. --
27 -- GNAT was originally developed by the GNAT team at New York University. --
28 -- Extensive contributions were provided by Ada Core Technologies Inc. --
30 ------------------------------------------------------------------------------
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;
42 -- Whether mapping is requested by the user and available on the system
45 -- Whether this file can be written to
48 -- Length of the file. Used to know what can be mapped in the file
51 type System_Mapping is record
52 Address : Standard.System.Address;
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);
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.
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
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
81 procedure Write_To_Disk
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
89 Offset, Length : in out File_Size;
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;