File: posix-memory_range_locking.adb

package info (click to toggle)
libflorist 2017-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,216 kB
  • sloc: ada: 11,902; ansic: 7,195; makefile: 150; sh: 19
file content (105 lines) | stat: -rw-r--r-- 5,211 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
------------------------------------------------------------------------------
--                                                                          --
--            FLORIST (FSU Implementation of POSIX.5) COMPONENTS            --
--                                                                          --
--            P O S I X . M E M O R Y _ R A N G E _ L O C K I N G           --
--                                                                          --
--                                  B o d y                                 --
--                                                                          --
--                                                                          --
--  Copyright (c) 1996-1998                 Florida State University (FSU)  --
--  All Rights Reserved.                                                    --
--                                                                          --
--  This file is a component of FLORIST, an  implementation of an  Ada API  --
--  for the POSIX OS services, for use with  the  GNAT  Ada  compiler  and  --
--  the FSU Gnu Ada Runtime Library (GNARL).   The  interface  is intended  --
--  to be close to that specified in  IEEE STD  1003.5: 1990  and IEEE STD  --
--  1003.5b: 1996.                                                          --
--                                                                          --
--  FLORIST is free software;  you can  redistribute  it and/or  modify it  --
--  under terms of the  GNU  General  Public  License as  published by the  --
--  Free Software Foundation;  either version  2, or (at  your option) any  --
--  later version.  FLORIST is distributed  in  the hope  that  it will be  --
--  useful, but WITHOUT ANY WARRANTY;  without  even the implied  warranty  --
--  of MERCHANTABILITY or FITNESS FOR A PARTICULAR  PURPOSE.  See  the GNU  --
--  General Public License for more details.  You  should have  received a  --
--  copy of the GNU General Public License  distributed  with  GNARL;  see  --
--  file  COPYING.  If not,  write to  the  Free  Software  Foundation, 59  --
--  Temple Place - Suite 330, Boston, MA 02111-1307, USA.                   --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
--                                                                          --
------------------------------------------------------------------------------

with POSIX.C,
     POSIX.Implementation;
package body POSIX.Memory_Range_Locking is

   use POSIX.C,
       POSIX.Implementation;

   ------------------
   --  Lock_Range  --
   ------------------

   procedure Lock_Range
     (First  : System.Address;
      Length : System.Storage_Elements.Storage_Offset) is
      function mlock (addr : access System.Address; len : size_t) return int;
      pragma Import (C, mlock, mlock_LINKNAME);
      Addr : aliased System.Address := First;
   begin
      --  .... Some OS (eg. Solaris) has non-standard mlock/munlock.
      --  For the reason if "mlock/munlock" fails with EINVAL,
      --  we speculate that the OS has non-standard form of the
      --  functions. So, try it again with a different form of the function.

      --  .... This is not a perfact solution and we feel that this kind of
      --  thing has to be resolved in the configuration management. It does its
      --  work for now....

      if mlock (Addr'Unchecked_Access, size_t (Length)) = -1
        and then Fetch_Errno = Invalid_Argument
      then
         declare
            function mlock (addr : System.Address; len : size_t) return int;
            pragma Import (C, mlock, mlock_LINKNAME);
         begin
            Check (mlock (Addr, size_t (Length)));
         end;
      else
         Check (mlock (Addr'Unchecked_Access, size_t (Length)));
      end if;
   end Lock_Range;

   --------------------
   --  UnLock_Range  --
   --------------------

   procedure Unlock_Range
     (First  : System.Address;
      Length : System.Storage_Elements.Storage_Offset) is
      function munlock (addr : access System.Address; len : size_t) return int;
      pragma Import (C, munlock, munlock_LINKNAME);
      Addr : aliased System.Address := First;
   begin
      if munlock (Addr'Unchecked_Access, size_t (Length)) = -1
        and then Fetch_Errno = Invalid_Argument
      then
         declare
            function munlock (addr : System.Address; len : size_t) return int;
            pragma Import (C, munlock, munlock_LINKNAME);
         begin
            Check (munlock (Addr, size_t (Length)));
         end;
      else
         Check (munlock (Addr'Unchecked_Access, size_t (Length)));
      end if;
   end Unlock_Range;

end POSIX.Memory_Range_Locking;