blob: e2384bee85fe328019566ed0c205289d05fc7061 [file] [log] [blame]
Nico Huberf03ef4f2017-03-04 13:57:09 +01001--
2-- Copyright (C) 2017 Nico Huber <nico.h@gmx.de>
3--
4-- This program is free software; you can redistribute it and/or modify
5-- it under the terms of the GNU General Public License as published by
6-- the Free Software Foundation; either version 2 of the License, or
7-- (at your option) any later version.
8--
9-- This program is distributed in the hope that it will be useful,
10-- but WITHOUT ANY WARRANTY; without even the implied warranty of
11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-- GNU General Public License for more details.
13--
14
15with Interfaces.C;
16with Interfaces.C.Strings;
17
18with HW.Debug;
19
20use Interfaces.C;
21use Interfaces.C.Strings;
22
23package body HW.File is
24
25 READ : constant := 16#01#;
26 WRITE : constant := 16#02#;
27
28 function c_map
Nico Hubera43b1ee2017-07-09 15:40:25 +020029 (addr : out Word64;
30 path : chars_ptr;
Nico Huberf03ef4f2017-03-04 13:57:09 +010031 len : Word32;
Nico Huber967dd0d2017-07-09 15:51:08 +020032 off : Word32;
Nico Huberf03ef4f2017-03-04 13:57:09 +010033 mode : Word32;
34 copy : int)
35 return int;
36 pragma Import (C, c_map, "hw_file_map");
37
38 procedure Map
Nico Hubera43b1ee2017-07-09 15:40:25 +020039 (Addr : out Word64;
40 Path : in String;
Nico Huber967dd0d2017-07-09 15:51:08 +020041 Len : in Natural := 0;
42 Offset : in Natural := 0;
Nico Huberf03ef4f2017-03-04 13:57:09 +010043 Readable : in Boolean := False;
44 Writable : in Boolean := False;
45 Map_Copy : in Boolean := False;
46 Success : out Boolean)
47 is
48 use type HW.Word32;
49
50 cpath : chars_ptr := New_String (Path);
51 ret : constant int := c_map
Nico Hubera43b1ee2017-07-09 15:40:25 +020052 (addr => Addr,
53 path => cpath,
Nico Huberf03ef4f2017-03-04 13:57:09 +010054 len => Word32 (Len),
Nico Huber967dd0d2017-07-09 15:51:08 +020055 off => Word32 (Offset),
Nico Huberf03ef4f2017-03-04 13:57:09 +010056 mode => (if Readable then READ else 0) or
57 (if Writable then WRITE else 0),
58 copy => (if Map_Copy then 1 else 0));
59 begin
Nico Huber32f14892017-06-18 02:35:37 +020060 pragma Warnings(GNAT, Off, """cpath"" modified*, but* referenced",
Nico Huberf03ef4f2017-03-04 13:57:09 +010061 Reason => "Free() demands to set it to null_ptr");
62 Free (cpath);
Nico Huber32f14892017-06-18 02:35:37 +020063 pragma Warnings(GNAT, On, """cpath"" modified*, but* referenced");
Nico Huberf03ef4f2017-03-04 13:57:09 +010064 Success := ret = 0;
65
66 pragma Debug (not Success, Debug.Put ("Mapping failed: "));
67 pragma Debug (not Success, Debug.Put_Int32 (Int32 (ret)));
68 pragma Debug (not Success, Debug.New_Line);
69 end Map;
70
71end HW.File;