]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/pge-boot/GSysStorage.c
1 /* do not edit automatically generated by mc from SysStorage. */
2 /* SysStorage.mod provides dynamic allocation for the system components.
4 Copyright (C) 2001-2021 Free Software Foundation, Inc.
5 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
7 This file is part of GNU Modula-2.
9 GNU Modula-2 is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
14 GNU Modula-2 is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
26 <http://www.gnu.org/licenses/>. */
28 # if !defined (PROC_D)
30 typedef void (* PROC_t
) ( void );
31 typedef struct { PROC_t proc
; } PROC
;
44 #if defined(__cplusplus)
55 # define enableDeallocation TRUE
56 # define enableZero FALSE
57 # define enableTrace FALSE
58 static unsigned int callno
;
59 static unsigned int zero
;
60 static unsigned int trace
;
61 extern "C" void SysStorage_ALLOCATE ( void * * a
, unsigned int size
);
62 extern "C" void SysStorage_DEALLOCATE ( void * * a
, unsigned int size
);
65 REALLOCATE - attempts to reallocate storage. The address,
66 a, should either be NIL in which case ALLOCATE
67 is called, or alternatively it should have already
68 been initialized by ALLOCATE. The allocated storage
69 is resized accordingly.
72 extern "C" void SysStorage_REALLOCATE ( void * * a
, unsigned int size
);
75 REALLOCATE - attempts to reallocate storage. The address,
76 a, should either be NIL in which case ALLOCATE
77 is called, or alternatively it should have already
78 been initialized by ALLOCATE. The allocated storage
79 is resized accordingly.
82 extern "C" unsigned int SysStorage_Available ( unsigned int size
);
85 Init - initializes the heap. This does nothing on a GNU/Linux system.
86 But it remains here since it might be used in an embedded system.
89 extern "C" void SysStorage_Init ( void );
91 extern "C" void SysStorage_ALLOCATE ( void * * a
, unsigned int size
)
93 (* a
) = libc_malloc ( static_cast < size_t > ( size
));
96 Debug_Halt (( const char *) "out of memory error" , 19 , 50 , ( const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/SysStorage.mod" , 58 );
98 if ( enableTrace
&& trace
)
100 libc_printf (( const char *) "<DEBUG-CALL> %d SysStorage.ALLOCATE (0x%x, %d bytes) \\ n" , 54 , callno
, (* a
), size
);
101 libc_printf (( const char *) "<MEM-ALLOC> %ld %d \\ n" , 20 , (* a
), size
);
106 extern "C" void SysStorage_DEALLOCATE ( void * * a
, unsigned int size
)
108 if ( enableTrace
&& trace
)
110 libc_printf (( const char *) "<DEBUG-CALL> %d SysStorage.DEALLOCATE (0x%x, %d bytes) \\ n" , 56 , callno
, (* a
), size
);
113 if ( enableZero
&& zero
)
115 if ( enableTrace
&& trace
)
117 libc_printf (( const char *) " memset (0x%x, 0, %d bytes) \\ n" , 30 , (* a
), size
);
119 if (( libc_memset ((* a
), 0 , static_cast < size_t > ( size
))) != (* a
))
121 Debug_Halt (( const char *) "memset should have returned the first parameter" , 47 , 76 , ( const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/SysStorage.mod" , 58 );
124 if ( enableDeallocation
)
126 if ( enableTrace
&& trace
)
128 libc_printf (( const char *) " free (0x%x) %d bytes \\ n" , 26 , (* a
), size
);
129 libc_printf (( const char *) "<MEM-FREE> %ld %d \\ n" , 19 , (* a
), size
);
138 REALLOCATE - attempts to reallocate storage. The address,
139 a, should either be NIL in which case ALLOCATE
140 is called, or alternatively it should have already
141 been initialized by ALLOCATE. The allocated storage
142 is resized accordingly.
145 extern "C" void SysStorage_REALLOCATE ( void * * a
, unsigned int size
)
149 SysStorage_ALLOCATE ( a
, size
);
153 if ( enableTrace
&& trace
)
155 libc_printf (( const char *) "<DEBUG-CALL> %d SysStorage.REALLOCATE (0x%x, %d bytes) \\ n" , 56 , callno
, (* a
), size
);
158 if ( enableTrace
&& trace
)
160 libc_printf (( const char *) " realloc (0x%x, %d bytes) -> " , 32 , (* a
), size
);
161 libc_printf (( const char *) "<MEM-FREE> %ld %d \\ n" , 19 , (* a
), size
);
163 (* a
) = libc_realloc ((* a
), static_cast < size_t > ( size
));
166 Debug_Halt (( const char *) "out of memory error" , 19 , 119 , ( const char *) "../../gcc-git-devel-modula2/gcc/m2/gm2-libs/SysStorage.mod" , 58 );
168 if ( enableTrace
&& trace
)
170 libc_printf (( const char *) "<MEM-ALLOC> %ld %d \\ n" , 20 , (* a
), size
);
171 libc_printf (( const char *) " 0x%x %d bytes \\ n" , 18 , (* a
), size
);
178 REALLOCATE - attempts to reallocate storage. The address,
179 a, should either be NIL in which case ALLOCATE
180 is called, or alternatively it should have already
181 been initialized by ALLOCATE. The allocated storage
182 is resized accordingly.
185 extern "C" unsigned int SysStorage_Available ( unsigned int size
)
189 if ( enableTrace
&& trace
)
191 libc_printf (( const char *) "<DEBUG-CALL> %d SysStorage.Available (%d bytes) \\ n" , 49 , callno
, size
);
194 a
= libc_malloc ( static_cast < size_t > ( size
));
197 if ( enableTrace
&& trace
)
199 libc_printf (( const char *) " no \\ n" , 7 , size
);
205 if ( enableTrace
&& trace
)
207 libc_printf (( const char *) " yes \\ n" , 8 , size
);
212 /* static analysis guarentees a RETURN statement will be used before here. */
213 __builtin_unreachable ();
218 Init - initializes the heap. This does nothing on a GNU/Linux system.
219 But it remains here since it might be used in an embedded system.
222 extern "C" void SysStorage_Init ( void )
226 extern "C" void _M2_SysStorage_init ( __attribute__ (( unused
)) int argc
, __attribute__ (( unused
)) char * argv
[], __attribute__ (( unused
)) char * envp
[])
231 trace
= ( libc_getenv ( const_cast < void *> ( reinterpret_cast < const void *>( "M2DEBUG_SYSSTORAGE_trace" )))) != NULL
;
239 zero
= ( libc_getenv ( const_cast < void *> ( reinterpret_cast < const void *>( "M2DEBUG_SYSSTORAGE_zero" )))) != NULL
;
247 extern "C" void _M2_SysStorage_finish ( __attribute__ (( unused
)) int argc
, __attribute__ (( unused
)) char * argv
[], __attribute__ (( unused
)) char * envp
[])