diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 181 |
1 files changed, 104 insertions, 77 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 804f0b9094..8d333f55c2 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | .\" | ||
| 1 | .\" Copyright (c) 1980, 1991, 1993 | 2 | .\" Copyright (c) 1980, 1991, 1993 |
| 2 | .\" The Regents of the University of California. All rights reserved. | 3 | .\" The Regents of the University of California. All rights reserved. |
| 3 | .\" | 4 | .\" |
| @@ -33,7 +34,7 @@ | |||
| 33 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 34 | .\" SUCH DAMAGE. | 35 | .\" SUCH DAMAGE. |
| 35 | .\" | 36 | .\" |
| 36 | .\" $OpenBSD: malloc.3,v 1.18 2000/01/19 05:36:38 pjanzen Exp $ | 37 | .\" $OpenBSD: malloc.3,v 1.19 2000/04/20 02:14:26 aaron Exp $ |
| 37 | .\" | 38 | .\" |
| 38 | .Dd August 27, 1996 | 39 | .Dd August 27, 1996 |
| 39 | .Dt MALLOC 3 | 40 | .Dt MALLOC 3 |
| @@ -72,7 +73,8 @@ space from the appropriate list. | |||
| 72 | .Pp | 73 | .Pp |
| 73 | The allocated space is | 74 | The allocated space is |
| 74 | suitably aligned (after possible pointer | 75 | suitably aligned (after possible pointer |
| 75 | coercion) for storage of any type of object. If the space is of | 76 | coercion) for storage of any type of object. |
| 77 | If the space is of | ||
| 76 | .Em pagesize | 78 | .Em pagesize |
| 77 | or larger, the memory returned will be page-aligned. | 79 | or larger, the memory returned will be page-aligned. |
| 78 | .Pp | 80 | .Pp |
| @@ -166,43 +168,54 @@ and finally for the global variable | |||
| 166 | and scan them for flags in that order. | 168 | and scan them for flags in that order. |
| 167 | Flags are single letters, uppercase means on, lowercase means off. | 169 | Flags are single letters, uppercase means on, lowercase means off. |
| 168 | .Bl -tag -width indent | 170 | .Bl -tag -width indent |
| 169 | .It A | 171 | .It Cm A |
| 170 | ``abort'' malloc will coredump the process, rather than tolerate failure. | 172 | .Dq Abort . |
| 173 | .Fn malloc | ||
| 174 | will coredump the process, rather than tolerate failure. | ||
| 171 | This is a very handy debugging aid, since the core file will represent the | 175 | This is a very handy debugging aid, since the core file will represent the |
| 172 | time of failure, | 176 | time of failure, rather than when the null pointer was accessed. |
| 173 | rather than when the null pointer was accessed. | ||
| 174 | .Pp | 177 | .Pp |
| 175 | .It D | 178 | .It Cm D |
| 176 | ``dump'' malloc will dump statistics in a file called ``malloc.out'' at exit. | 179 | .Dq Dump . |
| 180 | .Fn malloc | ||
| 181 | will dump statistics in a file called | ||
| 182 | .Pa malloc.out | ||
| 183 | at exit. | ||
| 177 | This option requires the library to have been compiled with -DMALLOC_STATS in | 184 | This option requires the library to have been compiled with -DMALLOC_STATS in |
| 178 | order to have any effect. | 185 | order to have any effect. |
| 179 | .Pp | 186 | .Pp |
| 180 | .It J | 187 | .It Cm J |
| 181 | ``junk'' fill some junk into the area allocated. | 188 | .Dq Junk . |
| 182 | Currently junk is bytes of 0xd0, this is pronounced ``Duh'' :-) | 189 | Fill some junk into the area allocated. |
| 190 | Currently junk is bytes of 0xd0; this is pronounced | ||
| 191 | .Dq Duh . | ||
| 192 | \&:-) | ||
| 183 | .Pp | 193 | .Pp |
| 184 | .It H | 194 | .It Cm H |
| 185 | ``hint'' pass a hint to the kernel about pages we don't use. If the | 195 | .Dq Hint . |
| 186 | machine is paging a lot this may help a bit. | 196 | Pass a hint to the kernel about pages we don't use. |
| 197 | If the machine is paging a lot this may help a bit. | ||
| 187 | .Pp | 198 | .Pp |
| 188 | .It N | 199 | .It Cm N |
| 189 | Do not output warning messages when encountering possible corruption | 200 | Do not output warning messages when encountering possible corruption |
| 190 | or bad pointers. | 201 | or bad pointers. |
| 191 | .Pp | 202 | .Pp |
| 192 | .It R | 203 | .It Cm R |
| 193 | ``realloc'' always reallocate when | 204 | .Dq realloc . |
| 205 | Always reallocate when | ||
| 194 | .Fn realloc | 206 | .Fn realloc |
| 195 | is called, even if the initial allocation was big enough. | 207 | is called, even if the initial allocation was big enough. |
| 196 | This can substantially aid in compacting memory. | 208 | This can substantially aid in compacting memory. |
| 197 | .Pp | 209 | .Pp |
| 198 | .It U | 210 | .It Cm U |
| 199 | ``utrace'' generate entries for | 211 | .Dq utrace . |
| 212 | Generate entries for | ||
| 200 | .Xr ktrace 1 | 213 | .Xr ktrace 1 |
| 201 | for all operations. | 214 | for all operations. |
| 202 | Consult the source for this one. | 215 | Consult the source for this one. |
| 203 | .Pp | 216 | .Pp |
| 204 | .It X | 217 | .It Cm X |
| 205 | ``xmalloc'' | 218 | .Dq xmalloc . |
| 206 | rather than return failure, | 219 | rather than return failure, |
| 207 | .Xr abort 3 | 220 | .Xr abort 3 |
| 208 | the program with a diagnostic message on stderr. | 221 | the program with a diagnostic message on stderr. |
| @@ -213,23 +226,31 @@ extern char *malloc_options; | |||
| 213 | malloc_options = "X"; | 226 | malloc_options = "X"; |
| 214 | .Ed | 227 | .Ed |
| 215 | .Pp | 228 | .Pp |
| 216 | .It Z | 229 | .It Cm Z |
| 217 | ``zero'' fill some junk into the area allocated (see ``J''), | 230 | .Dq Zero . |
| 231 | Fill some junk into the area allocated (see | ||
| 232 | .Cm J ) , | ||
| 218 | except for the exact length the user asked for, which is zeroed. | 233 | except for the exact length the user asked for, which is zeroed. |
| 219 | .Pp | 234 | .Pp |
| 220 | .It < | 235 | .It Cm < |
| 221 | ``Half the cache size'' Reduce the size of the cache by a factor of two. | 236 | .Dq Half the cache size . |
| 237 | Reduce the size of the cache by a factor of two. | ||
| 222 | .Pp | 238 | .Pp |
| 223 | .It > | 239 | .It Cm > |
| 224 | ``Double the cache size'' Double the size of the cache by a factor of two. | 240 | .Dq Double the cache size . |
| 241 | Double the size of the cache by a factor of two. | ||
| 225 | .El | 242 | .El |
| 226 | .Pp | 243 | .Pp |
| 227 | So to set a systemwide reduction of cache size and coredumps on problems | 244 | So to set a systemwide reduction of cache size and coredumps on problems |
| 228 | one would: | 245 | one would: |
| 229 | .Li ln -s 'A<' /etc/malloc.conf | 246 | .Li ln -s 'A<' /etc/malloc.conf |
| 230 | .Pp | 247 | .Pp |
| 231 | The ``J'' and ``Z'' is mostly for testing and debugging, | 248 | The |
| 232 | if a program changes behavior if either of these options are used, | 249 | .Cm J |
| 250 | and | ||
| 251 | .Cm Z | ||
| 252 | is mostly for testing and debugging. | ||
| 253 | If a program changes behavior if either of these options are used, | ||
| 233 | it is buggy. | 254 | it is buggy. |
| 234 | .Pp | 255 | .Pp |
| 235 | The default cache size is 16 pages. | 256 | The default cache size is 16 pages. |
| @@ -240,8 +261,7 @@ The | |||
| 240 | .Fn malloc | 261 | .Fn malloc |
| 241 | and | 262 | and |
| 242 | .Fn calloc | 263 | .Fn calloc |
| 243 | functions return | 264 | functions return a pointer to the allocated space if successful; otherwise, |
| 244 | a pointer to the allocated space if successful; otherwise, | ||
| 245 | a null pointer is returned and | 265 | a null pointer is returned and |
| 246 | .Va errno | 266 | .Va errno |
| 247 | is set to | 267 | is set to |
| @@ -260,11 +280,11 @@ if successful; otherwise, a null pointer is returned and | |||
| 260 | .Va errno | 280 | .Va errno |
| 261 | is set to | 281 | is set to |
| 262 | .Er ENOMEM . | 282 | .Er ENOMEM . |
| 263 | .Sh MESSAGES | 283 | .Sh DIAGNOSTICS |
| 264 | If | 284 | If |
| 265 | .Fn malloc , | 285 | .Fn malloc , |
| 266 | .Fn calloc , | 286 | .Fn calloc , |
| 267 | .Fn realloc | 287 | .Fn realloc , |
| 268 | or | 288 | or |
| 269 | .Fn free | 289 | .Fn free |
| 270 | detect an error or warning condition, | 290 | detect an error or warning condition, |
| @@ -272,77 +292,84 @@ a message will be printed to file descriptor | |||
| 272 | 2 (not using stdio). | 292 | 2 (not using stdio). |
| 273 | Errors will always result in the process being | 293 | Errors will always result in the process being |
| 274 | .Xr abort 3 'ed. | 294 | .Xr abort 3 'ed. |
| 275 | If the ``A'' option has been specified, warnings will also | 295 | If the |
| 296 | .Cm A | ||
| 297 | option has been specified, warnings will also | ||
| 276 | .Xr abort 3 | 298 | .Xr abort 3 |
| 277 | the process. | 299 | the process. |
| 278 | .Pp | 300 | .Pp |
| 279 | Here is a brief description of the error messages and what they mean: | 301 | Here is a brief description of the error messages and what they mean: |
| 280 | .Pp | 302 | .Bl -tag -width Fl |
| 281 | ``(ES): mumble mumble mumble'': | 303 | .It Dq (ES): mumble mumble mumble |
| 282 | malloc have been compiled with -DEXTRA_SANITY and something looks | 304 | .Fn malloc |
| 283 | fishy in there. Consult sources and or wizards. | 305 | has been compiled with |
| 284 | .Pp | 306 | .Dv \&-DEXTRA_SANITY |
| 285 | ``allocation failed'' | 307 | and something looks fishy in there. |
| 286 | if the ``A'' option is specified it is an error for | 308 | Consult sources and/or wizards. |
| 309 | .It Dq allocation failed | ||
| 310 | If the | ||
| 311 | .Cm A | ||
| 312 | option is specified it is an error for | ||
| 287 | .Fn malloc , | 313 | .Fn malloc , |
| 288 | .Fn calloc | 314 | .Fn calloc , |
| 289 | or | 315 | or |
| 290 | .Fn realloc | 316 | .Fn realloc |
| 291 | to return | 317 | to return |
| 292 | .Dv NULL . | 318 | .Dv NULL . |
| 293 | .Pp | 319 | .It Dq mmap(2) failed, check limits. |
| 294 | ``mmap(2) failed, check limits.'' | 320 | This is a rather weird condition that is most likely to indicate a |
| 295 | This is a rather weird condition that is most likely to mean that | 321 | seriously overloaded system or a |
| 296 | the system is seriously overloaded or that your ulimits are sick. | 322 | .Xr ulimit 1 |
| 297 | .Pp | 323 | restriction. |
| 298 | ``freelist is destroyed.'' | 324 | .It Dq freelist is destroyed. |
| 299 | mallocs internal freelist has been stomped on. | 325 | .Fn malloc Ns 's |
| 326 | internal freelist has been stomped on. | ||
| 327 | .El | ||
| 300 | .Pp | 328 | .Pp |
| 301 | Here is a brief description of the warning messages and what they mean: | 329 | Here is a brief description of the warning messages and what they mean: |
| 302 | .Pp | 330 | .Bl -tag -width Fl |
| 303 | ``chunk/page is already free.'' | 331 | .It Dq chunk/page is already free. |
| 304 | A pointer to a free chunk is attempted freed again. | 332 | A pointer to a free chunk is attempted freed again. |
| 305 | .Pp | 333 | .It Dq junk pointer, too high to make sense. |
| 306 | ``junk pointer, too high to make sense.'' | 334 | The pointer doesn't make sense. |
| 307 | The pointer doesn't make sense. It's above the area of memory that | 335 | It's above the area of memory that |
| 308 | .Fn malloc | 336 | .Fn malloc |
| 309 | knows something about. | 337 | knows something about. |
| 310 | This could be a pointer from some | 338 | This could be a pointer from some |
| 311 | .Xr mmap 2 'ed | 339 | .Xr mmap 2 'ed |
| 312 | memory. | 340 | memory. |
| 313 | .Pp | 341 | .It Dq junk pointer, too low to make sense. |
| 314 | ``junk pointer, too low to make sense.'' | 342 | The pointer doesn't make sense. |
| 315 | The pointer doesn't make sense. It's below the area of memory that | 343 | It's below the area of memory that |
| 316 | .Fn malloc | 344 | .Fn malloc |
| 317 | knows something about. | 345 | knows something about. |
| 318 | This pointer probably came from your data or bss segments. | 346 | This pointer probably came from your data or bss segments. |
| 319 | .Pp | 347 | .It Dq malloc() has never been called. |
| 320 | ``malloc() has never been called.'' | ||
| 321 | Nothing has ever been allocated, yet something is being freed or | 348 | Nothing has ever been allocated, yet something is being freed or |
| 322 | realloc'ed. | 349 | realloc'ed. |
| 323 | .Pp | 350 | .It Dq modified (chunk-/page-) pointer. |
| 324 | ``modified (chunk-/page-) pointer.'' | ||
| 325 | The pointer passed to free or realloc has been modified. | 351 | The pointer passed to free or realloc has been modified. |
| 326 | .Pp | 352 | .It Dq pointer to wrong page. |
| 327 | ``pointer to wrong page.'' | ||
| 328 | The pointer that | 353 | The pointer that |
| 329 | .Fn malloc | 354 | .Fn malloc |
| 330 | is trying to free is not pointing to | 355 | is trying to free is not pointing to |
| 331 | a sensible page. | 356 | a sensible page. |
| 332 | .Pp | 357 | .It Dq recursive call. |
| 333 | ``recursive call.'' | 358 | An attempt was made to call recursively into these functions, i.e., from a |
| 334 | You have tried to call recursively into these functions. | 359 | signal handler. |
| 335 | I can only imagine this as happening if you call one of these | 360 | This behavior is not supported. |
| 336 | functions from a signal handler, which happens to be called | 361 | In particular, signal handlers should |
| 337 | while you're already in here. | 362 | .Em not |
| 338 | Well, sorry to say: that's not supported. | 363 | use any of the |
| 339 | If this is a problem for you I'd like to hear about it. It | 364 | .Fn malloc |
| 340 | would be possible to add a sigblock() around this package, | 365 | functions nor utilize any other functions which may call |
| 341 | but it would have a performance penalty that is not acceptable | 366 | .Fn malloc |
| 342 | as the default. | 367 | (e.g., |
| 343 | .Pp | 368 | .Xr stdio 3 |
| 344 | ``unknown char in MALLOC_OPTIONS'' | 369 | routines). |
| 345 | we found something we didn't understand. | 370 | .It Dq unknown char in MALLOC_OPTIONS |
| 371 | We found something we didn't understand. | ||
| 372 | .El | ||
| 346 | .Sh FILES | 373 | .Sh FILES |
| 347 | .Bl -tag -width "/etc/malloc.conf" | 374 | .Bl -tag -width "/etc/malloc.conf" |
| 348 | .It Pa /etc/malloc.conf | 375 | .It Pa /etc/malloc.conf |
