File : s-memory-pikeos.ads
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT RUN-TIME COMPONENTS --
4 -- --
5 -- S Y S T E M . M E M O R Y --
6 -- --
7 -- S p e c --
8 -- --
9 -- Copyright (C) 2001-2015, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. --
17 -- --
18 -- --
19 -- --
20 -- --
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 ------------------------------------------------------------------------------
31
32 -- This is the PikeOS-specific version of this package.
33
34 -- This package provides the low level memory allocation/deallocation
35 -- mechanisms used by GNAT.
36
37 package System.Memory is
38 pragma Elaborate_Body;
39
40 type size_t is mod 2 ** Standard'Address_Size;
41 -- Note: the reason we redefine this here instead of using the
42 -- definition in Interfaces.C is that we do not want to drag in
43 -- all of Interfaces.C just because System.Memory is used.
44
45 function Alloc (Size : size_t) return System.Address;
46 -- This is the low level allocation routine. Given a size in storage
47 -- units, it returns the address of a maximally aligned block of
48 -- memory.
49 --
50 -- A first check is performed to discard memory allocations that are
51 -- obviously too big, preventing problems of memory wraparound. If Size is
52 -- greater than the maximum number of storage elements (taking into account
53 -- the maximum alignment) in the machine, then a Storage_Error exception is
54 -- raised before trying to perform the memory allocation.
55 --
56 -- If Size is set to zero on entry, then a minimal (but non-zero)
57 -- size block is allocated.
58 --
59 -- If there is not enough free memory on the heap for the requested
60 -- allocation then a Storage_Error exception is raised and the heap remains
61 -- unchanged.
62 --
63 -- Note: this is roughly equivalent to the standard C malloc call
64 -- with the additional semantics as described above.
65
66 procedure Free (Ptr : System.Address);
67 -- This is the low level free routine. It frees a block previously
68 -- allocated with a call to Alloc. As in the case of Alloc, this
69 -- call is guaranteed task safe, and aborts are deferred.
70 --
71 -- Note: this is roughly equivalent to the standard C free call
72 -- with the additional semantics as described above.
73
74 function Realloc
75 (Ptr : System.Address;
76 Size : size_t) return System.Address;
77 -- This is the low level reallocation routine. It takes an existing
78 -- block address returned by a previous call to Alloc or Realloc,
79 -- and reallocates the block. The size can either be increased or
80 -- decreased. If possible the reallocation is done in place, so that
81 -- the returned result is the same as the value of Ptr on entry.
82 -- However, it may be necessary to relocate the block to another
83 -- address, in which case the information is copied to the new
84 -- block, and the old block is freed. The implementation of this
85 -- routine is guaranteed to be task safe, and also aborts are
86 -- deferred as necessary.
87 --
88 -- If size_t is set to size_t'Last on entry, then a Storage_Error
89 -- exception is raised with a message "object too large".
90 --
91 -- If size_t is set to zero on entry, then a minimal (but non-zero)
92 -- size block is allocated.
93 --
94 -- Note: this is roughly equivalent to the standard C realloc call
95 -- with the additional semantics as described above.
96
97 private
98 -- The following names are used from the generated compiler code
99
100 pragma Export (C, Alloc, "__gnat_malloc");
101 pragma Export (C, Realloc, "__gnat_realloc");
102 pragma Export (C, Free, "__gnat_free");
103
104 end System.Memory;