summaryrefslogtreecommitdiff
path: root/src/lib/libc/stdlib/malloc.3
diff options
context:
space:
mode:
authortholo <>1996-09-26 04:19:42 +0000
committertholo <>1996-09-26 04:19:42 +0000
commit40954213683da2af94f45d9b0f35806b54e5e306 (patch)
tree4d52bb67398acd4227bd70258a69403ba2acf910 /src/lib/libc/stdlib/malloc.3
parent7bfb6e73ddb58269b8ec906a008d5999e1b70abf (diff)
downloadopenbsd-40954213683da2af94f45d9b0f35806b54e5e306.tar.gz
openbsd-40954213683da2af94f45d9b0f35806b54e5e306.tar.bz2
openbsd-40954213683da2af94f45d9b0f35806b54e5e306.zip
Latest changes from FreeBSD
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r--src/lib/libc/stdlib/malloc.3118
1 files changed, 110 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 979e77016d..e206245cc2 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -33,11 +33,11 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 34.\" SUCH DAMAGE.
35.\" 35.\"
36.\" $OpenBSD: malloc.3,v 1.3 1996/08/21 03:12:18 downsj Exp $ 36.\" $OpenBSD: malloc.3,v 1.4 1996/09/26 04:19:41 tholo Exp $
37.\" 37.\"
38.Dd June 4, 1993 38.Dd August 27, 1996
39.Dt MALLOC 3 39.Dt MALLOC 3
40.Os BSD 4 40.Os OpenBSD
41.Sh NAME 41.Sh NAME
42.Nm malloc , 42.Nm malloc ,
43.Nd general memory allocation function 43.Nd general memory allocation function
@@ -58,6 +58,8 @@
58.Fn cfree "void *ptr" 58.Fn cfree "void *ptr"
59.Ft void * 59.Ft void *
60.Fn realloc "void *ptr" "size_t size" 60.Fn realloc "void *ptr" "size_t size"
61.Ft char *
62.Va malloc_options
61.Sh DESCRIPTION 63.Sh DESCRIPTION
62The 64The
63.Fn malloc 65.Fn malloc
@@ -120,11 +122,13 @@ is zero and
120.Fa ptr 122.Fa ptr
121is not a null pointer, the object it points to is freed. 123is not a null pointer, the object it points to is freed.
122.Pp 124.Pp
123 125Malloc will first look for a symbolic link called
124.Sh ENVIRONMENT 126.Pa /etc/malloc.conf
125This malloc will check the environment for a variable called 127and next check the environment for a variable called
126.Em MALLOC_OPTIONS 128.Ev MALLOC_OPTIONS
127and scan it for flags. 129and finally for the global variable
130.Va malloc_options
131and scan them for flags in that order.
128Flags are single letters, uppercase means on, lowercase means off. 132Flags are single letters, uppercase means on, lowercase means off.
129.Bl -tag -width indent 133.Bl -tag -width indent
130.It A 134.It A
@@ -142,21 +146,42 @@ order to have any effect.
142``junk'' fill some junk into the area allocated. 146``junk'' fill some junk into the area allocated.
143Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) 147Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-)
144 148
149.It H
150``hint'' pass a hint to the kernel about pages we don't use. If the
151machine is paging a lot this may help a bit.
152
145.It R 153.It R
146``realloc'' always reallocate when 154``realloc'' always reallocate when
147.Fn realloc 155.Fn realloc
148is called, even if the initial allocation was big enough. 156is called, even if the initial allocation was big enough.
149This can substantially aid in compacting memory. 157This can substantially aid in compacting memory.
150 158
159.It U
160``utrace'' generate entries for ktrace(1) for all operations.
161Consult the source for this one.
162
151.It Z 163.It Z
152``zero'' fill some junk into the area allocated (see ``J''), 164``zero'' fill some junk into the area allocated (see ``J''),
153except for the exact length the user asked for, which is zeroed. 165except for the exact length the user asked for, which is zeroed.
154 166
167.It <
168``Half the cache size'' Reduce the size of the cache by a factor of two.
169
170.It >
171``Double the cache size'' Double the size of the cache by a factor of two.
155.El 172.El
156.Pp 173.Pp
174So to set a systemwide reduction of cache size and coredumps on problems
175one would:
176.Li ln -s 'A<' /etc/malloc.conf
177.Pp
157The ``J'' and ``Z'' is mostly for testing and debugging, 178The ``J'' and ``Z'' is mostly for testing and debugging,
158if a program changes behavior if either of these options are used, 179if a program changes behavior if either of these options are used,
159it is buggy. 180it is buggy.
181.Pp
182The default cache size is 16 pages.
183.Sh ENVIRONMENT
184See above.
160.Sh RETURN VALUES 185.Sh RETURN VALUES
161The 186The
162.Fn malloc 187.Fn malloc
@@ -172,12 +197,89 @@ The
172.Fn realloc 197.Fn realloc
173function returns either a null pointer or a pointer 198function returns either a null pointer or a pointer
174to the possibly moved allocated space. 199to the possibly moved allocated space.
200.Sh MESSAGES
201If
202.Fn malloc ,
203.Fn free
204or
205.Fn realloc
206detects an error or warning condition,
207a message will be printed to filedescriptor
2082 (not using stdio).
209Errors will always result in the process being
210.Xr abort 2 'ed,
211If the ``A'' option has been specified, also warnings will
212.Xr abort 2
213the process.
214.Pp
215Here is a brief description of the error messages and what they mean:
216.Pp
217``(ES): mumble mumble mumble'':
218malloc have been compiled with -DEXTRA_SANITY and something looks
219fishy in there. Consult sources and or wizards.
220.Pp
221``allocation failed''
222if the ``A'' option is specified it is an error for
223.Fn malloc
224or
225.Fn realloc
226to return NULL.
227.Pp
228``mmap(2) failed, check limits.''
229This is a rather weird condition that is most likely to mean that
230the system is seriously overloaded or that your ulimits are sick.
231.Pp
232``freelist is destroyed.''
233mallocs internal freelist has been stomped on.
234.Pp
235Here is a brief description of the warning messages and what they mean:
236.Pp
237``chunk/page is already free.''
238A pointer to a free chunk is attempted freed again.
239.Pp
240``junk pointer, too high to make sense.''
241The pointer doesn't make sense. It's above the area of memory that
242malloc knows something about.
243This could be a pointer from some
244.Xr mmap 2 'ed
245memory.
246.Pp
247``junk pointer, too low to make sense.''
248The pointer doesn't make sense. It's below the area of memory that
249malloc knows something about.
250This pointer probably came from your data or bss segments.
251.Pp
252``malloc() has never been called.''
253Nothing has ever been allocated, yet something is being freed or
254realloc'ed.
255.Pp
256``modified (chunk-/page-) pointer.''
257The pointer passed to free or realloc has been modified.
258.Pp
259``pointer to wrong page.''
260The pointer that malloc is trying to free is not pointing to
261a sensible page.
262.Pp
263``recursive call.''
264You have tried to call recursively into these functions.
265I can only imagine this as happening if you call one of these
266functions from a signal function, which happens to be called
267while you're already in here.
268Well, sorry to say: that's not supported.
269If this is a problem for you I'd like to hear about it. It
270would be possible to add a sigblock() around this package,
271but it would have a performance penalty that is not acceptable
272as the default.
273.Pp
274``unknown char in MALLOC_OPTIONS''
275we found something we didn't understand.
175.Sh SEE ALSO 276.Sh SEE ALSO
176.Xr brk 2 , 277.Xr brk 2 ,
177.Xr alloca 3 , 278.Xr alloca 3 ,
178.Xr calloc 3 , 279.Xr calloc 3 ,
179.Xr getpagesize 3 , 280.Xr getpagesize 3 ,
180.Xr memory 3 281.Xr memory 3
282.Pa /usr/share/doc/papers/malloc.ascii.gz
181.Sh STANDARDS 283.Sh STANDARDS
182The 284The
183.Fn malloc 285.Fn malloc