Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4349 Serge 1
/* VxWorks provides its own version of malloc, and we can't use this
2
   one because VxWorks does not provide sbrk.  So we have a hook to
3
   not compile this code.  */
4
 
5
/* The routines here are simple cover fns to the routines that do the real
6
   work (the reentrant versions).  */
7
/* FIXME: Does the warning below (see WARNINGS) about non-reentrancy still
8
   apply?  A first guess would be "no", but how about reentrancy in the *same*
9
   thread?  */
10
 
11
#ifdef MALLOC_PROVIDED
12
 
13
int _dummy_malloc = 1;
14
 
15
#else
16
 
17
/*
18
FUNCTION
19
<>, <>, <>---manage memory
20
 
21
INDEX
22
	malloc
23
INDEX
24
	realloc
25
INDEX
26
	reallocf
27
INDEX
28
	free
29
INDEX
30
	memalign
31
INDEX
32
	malloc_usable_size
33
INDEX
34
	_malloc_r
35
INDEX
36
	_realloc_r
37
INDEX
38
	_reallocf_r
39
INDEX
40
	_free_r
41
INDEX
42
	_memalign_r
43
INDEX
44
	_malloc_usable_size_r
45
 
46
ANSI_SYNOPSIS
47
	#include 
48
	void *malloc(size_t <[nbytes]>);
49
	void *realloc(void *<[aptr]>, size_t <[nbytes]>);
50
	void *reallocf(void *<[aptr]>, size_t <[nbytes]>);
51
	void free(void *<[aptr]>);
52
 
53
	void *memalign(size_t <[align]>, size_t <[nbytes]>);
54
 
55
	size_t malloc_usable_size(void *<[aptr]>);
56
 
57
	void *_malloc_r(void *<[reent]>, size_t <[nbytes]>);
58
	void *_realloc_r(void *<[reent]>,
59
                         void *<[aptr]>, size_t <[nbytes]>);
60
	void *_reallocf_r(void *<[reent]>,
61
                         void *<[aptr]>, size_t <[nbytes]>);
62
	void _free_r(void *<[reent]>, void *<[aptr]>);
63
 
64
	void *_memalign_r(void *<[reent]>,
65
			  size_t <[align]>, size_t <[nbytes]>);
66
 
67
	size_t _malloc_usable_size_r(void *<[reent]>, void *<[aptr]>);
68
 
69
TRAD_SYNOPSIS
70
	#include 
71
	char *malloc(<[nbytes]>)
72
	size_t <[nbytes]>;
73
 
74
	char *realloc(<[aptr]>, <[nbytes]>)
75
	char *<[aptr]>;
76
	size_t <[nbytes]>;
77
 
78
	char *reallocf(<[aptr]>, <[nbytes]>)
79
	char *<[aptr]>;
80
	size_t <[nbytes]>;
81
 
82
	void free(<[aptr]>)
83
	char *<[aptr]>;
84
 
85
	char *memalign(<[align]>, <[nbytes]>)
86
	size_t <[align]>;
87
	size_t <[nbytes]>;
88
 
89
	size_t malloc_usable_size(<[aptr]>)
90
	char *<[aptr]>;
91
 
92
	char *_malloc_r(<[reent]>,<[nbytes]>)
93
	char *<[reent]>;
94
	size_t <[nbytes]>;
95
 
96
	char *_realloc_r(<[reent]>, <[aptr]>, <[nbytes]>)
97
	char *<[reent]>;
98
	char *<[aptr]>;
99
	size_t <[nbytes]>;
100
 
101
	char *_reallocf_r(<[reent]>, <[aptr]>, <[nbytes]>)
102
	char *<[reent]>;
103
	char *<[aptr]>;
104
	size_t <[nbytes]>;
105
 
106
	void _free_r(<[reent]>, <[aptr]>)
107
	char *<[reent]>;
108
	char *<[aptr]>;
109
 
110
	char *_memalign_r(<[reent]>, <[align]>, <[nbytes]>)
111
	char *<[reent]>;
112
	size_t <[align]>;
113
	size_t <[nbytes]>;
114
 
115
	size_t malloc_usable_size(<[reent]>, <[aptr]>)
116
	char *<[reent]>;
117
	char *<[aptr]>;
118
 
119
DESCRIPTION
120
These functions manage a pool of system memory.
121
 
122
Use <> to request allocation of an object with at least
123
<[nbytes]> bytes of storage available.  If the space is available,
124
<> returns a pointer to a newly allocated block as its result.
125
 
126
If you already have a block of storage allocated by <>, but
127
you no longer need all the space allocated to it, you can make it
128
smaller by calling <> with both the object pointer and the
129
new desired size as arguments.  <> guarantees that the
130
contents of the smaller object match the beginning of the original object.
131
 
132
Similarly, if you need more space for an object, use <> to
133
request the larger size; again, <> guarantees that the
134
beginning of the new, larger object matches the contents of the
135
original object.
136
 
137
When you no longer need an object originally allocated by <>
138
or <> (or the related function <>), return it to the
139
memory storage pool by calling <> with the address of the object
140
as the argument.  You can also use <> for this purpose by
141
calling it with <<0>> as the <[nbytes]> argument.
142
 
143
The <> function behaves just like <> except if the
144
function is required to allocate new storage and this fails.  In this
145
case <> will free the original object passed in whereas
146
<> will not.
147
 
148
The <> function returns a block of size <[nbytes]> aligned
149
to a <[align]> boundary.  The <[align]> argument must be a power of
150
two.
151
 
152
The <> function takes a pointer to a block
153
allocated by <>.  It returns the amount of space that is
154
available in the block.  This may or may not be more than the size
155
requested from <>, due to alignment or minimum size
156
constraints.
157
 
158
The alternate functions <<_malloc_r>>, <<_realloc_r>>, <<_reallocf_r>>,
159
<<_free_r>>, <<_memalign_r>>, and <<_malloc_usable_size_r>> are reentrant
160
versions.  The extra argument <[reent]> is a pointer to a reentrancy structure.
161
 
162
If you have multiple threads of execution which may call any of these
163
routines, or if any of these routines may be called reentrantly, then
164
you must provide implementations of the <<__malloc_lock>> and
165
<<__malloc_unlock>> functions for your system.  See the documentation
166
for those functions.
167
 
168
These functions operate by calling the function <<_sbrk_r>> or
169
<>, which allocates space.  You may need to provide one of these
170
functions for your system.  <<_sbrk_r>> is called with a positive
171
value to allocate more space, and with a negative value to release
172
previously allocated space if it is no longer required.
173
@xref{Stubs}.
174
 
175
RETURNS
176
<> returns a pointer to the newly allocated space, if
177
successful; otherwise it returns <>.  If your application needs
178
to generate empty objects, you may use <> for this purpose.
179
 
180
<> returns a pointer to the new block of memory, or <>
181
if a new block could not be allocated.  <> is also the result
182
when you use `<,0)>>' (which has the same effect as
183
`<)>>').  You should always check the result of
184
<>; successful reallocation is not guaranteed even when
185
you request a smaller object.
186
 
187
<> does not return a result.
188
 
189
<> returns a pointer to the newly allocated space.
190
 
191
<> returns the usable size.
192
 
193
PORTABILITY
194
<>, <>, and <> are specified by the ANSI C
195
standard, but other conforming implementations of <> may
196
behave differently when <[nbytes]> is zero.
197
 
198
<> is part of SVR4.
199
 
200
<> is not portable.
201
 
202
Supporting OS subroutines required: <>.  */
203
 
204
#include <_ansi.h>
205
#include 
206
#include 
207
#include 
208
 
209
#ifndef _REENT_ONLY
210
 
211
_PTR
212
_DEFUN (malloc, (nbytes),
213
	size_t nbytes)		/* get a block */
214
{
215
  return _malloc_r (_REENT, nbytes);
216
}
217
 
218
void
219
_DEFUN (free, (aptr),
220
	_PTR aptr)
221
{
222
  _free_r (_REENT, aptr);
223
}
224
 
225
#endif
226
 
227
#endif /* ! defined (MALLOC_PROVIDED) */