home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / reviewed / volume02 / malloclb / part02 < prev    next >
Encoding:
Internet Message Format  |  1992-03-31  |  56.2 KB

  1. From: Conor P. Cahill <cpcahil%virtech@uunet.UU.NET>
  2. Subject: v02i003: malloclib - Malloc Debugging Library, Part02/05
  3. Newsgroups: comp.sources.reviewed
  4. Approved: csr@calvin.dgbt.doc.ca
  5.  
  6. Submitted-by: Conor P. Cahill <cpcahil%virtech@uunet.UU.NET>
  7. Posting-number: Volume 2, Issue 3
  8. Archive-name: malloclib/part02
  9.  
  10. #! /bin/sh
  11. # This is a shell archive.  Remove anything before this line, then unpack
  12. # it by saving it into a file and typing "sh file".  To overwrite existing
  13. # files, type "sh file -c".  You can also feed this as standard input via
  14. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  15. # will see the following message at the end:
  16. #        "End of archive 2 (of 5)."
  17. # Contents:  free.c m_init.c m_perror.c malloc.3 malloc.h
  18. # Wrapped by cpcahil@virtech on Tue Jan 28 16:46:33 1992
  19. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  20. if test -f 'free.c' -a "${1}" != "-c" ; then 
  21.   echo shar: Will not clobber existing file \"'free.c'\"
  22. else
  23. echo shar: Extracting \"'free.c'\" \(6163 characters\)
  24. sed "s/^X//" >'free.c' <<'END_OF_FILE'
  25. X/*
  26. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  27. X * You may copy, distribute, and use this software as long as this
  28. X * copyright statement is not removed.
  29. X */
  30. X#include <stdio.h>
  31. X#include "mallocint.h"
  32. X#include "debug.h"
  33. X
  34. X/*
  35. X * Function:    free()
  36. X *
  37. X * Purpose:    to deallocate malloced data
  38. X *
  39. X * Arguments:    ptr    - pointer to data area to deallocate
  40. X *
  41. X * Returns:    nothing of any value
  42. X *
  43. X * Narrative:
  44. X *        verify pointer is within malloc region
  45. X *        get mlist pointer from passed address
  46. X *        verify magic number
  47. X *        verify inuse flag
  48. X *        verify pointer connections with surrounding segments
  49. X *        turn off inuse flag
  50. X *        verify no data overrun into non-malloced area at end of segment
  51. X *        IF possible join segment with next segment
  52. X *        IF possible join segment with previous segment
  53. X *        Clear all data in segment (to make sure it isn't reused)
  54. X *
  55. X */
  56. X#ifndef lint
  57. Xstatic
  58. Xchar rcs_hdr[] = "$Id: free.c,v 1.17 1992/01/28 14:30:18 cpcahil Exp $";
  59. X#endif
  60. X
  61. XVOIDTYPE
  62. Xfree(cptr)
  63. X    DATATYPE    * cptr;
  64. X{
  65. X    debug_free((char *)NULL, 0, cptr);
  66. X}
  67. X
  68. XVOIDTYPE
  69. Xdebug_free(file,line,cptr)
  70. X    const char    * file;
  71. X    int          line;
  72. X    DATATYPE    * cptr;
  73. X{
  74. X    DBFfree("free",file,line,cptr);
  75. X}
  76. X
  77. XVOIDTYPE
  78. XDBFfree(func,file,line,cptr)
  79. X    const char    * func;
  80. X    const char    * file;
  81. X    int          line;
  82. X    DATATYPE    * cptr;
  83. X{
  84. X    int              i;
  85. X    register struct mlist    * oldptr;
  86. X    register struct mlist    * ptr;
  87. X
  88. X    /*
  89. X     * initialize the malloc sub-system.
  90. X     */
  91. X    MALLOC_INIT();
  92. X
  93. X    /*
  94. X     * IF malloc chain checking is on, go do it.
  95. X     */
  96. X    if( malloc_checking )
  97. X    {
  98. X        VOIDCAST DBFmalloc_chain_check(func,file,line,1);
  99. X    }
  100. X
  101. X#if __STDC__ && ! defined(NO_ANSI_NULLS)
  102. X
  103. X    if( cptr == NULL )
  104. X    {
  105. X        return;
  106. X    }
  107. X
  108. X#endif
  109. X
  110. X    /*
  111. X     * verify that cptr is within the malloc region...
  112. X     */
  113. X    if( cptr < malloc_data_start || cptr > malloc_data_end )
  114. X    {
  115. X        malloc_errno = M_CODE_BAD_PTR;
  116. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  117. X        return;
  118. X    }
  119. X
  120. X    /* 
  121. X     * convert pointer to mlist struct pointer.  To do this we must 
  122. X     * move the pointer backwards the correct number of bytes...
  123. X     */
  124. X    
  125. X    ptr = (struct mlist *) (((char *)cptr) - M_SIZE);
  126. X
  127. X    /*
  128. X     * check the magic number 
  129. X     */    
  130. X    if( (ptr->flag&M_MAGIC_BITS) != M_MAGIC )
  131. X    {
  132. X        malloc_errno = M_CODE_BAD_MAGIC;
  133. X        malloc_warning(func,file,line,(struct mlist *)NULL);
  134. X        return;
  135. X    }
  136. X
  137. X    /*
  138. X     * if this segment is not flagged as being in use
  139. X     */
  140. X    if( ! (ptr->flag & M_INUSE) )
  141. X    {
  142. X        malloc_errno = M_CODE_NOT_INUSE;
  143. X        malloc_warning(func,file,line,ptr);
  144. X        return;
  145. X    }
  146. X
  147. X    /*
  148. X     * check to see that the pointers are still connected
  149. X     */
  150. X     if( (ptr->prev && (ptr->prev->next != ptr) ) ||
  151. X        (ptr->next && (ptr->next->prev != ptr) ) ||
  152. X        ((ptr->next == NULL) && (ptr->prev == NULL)) )
  153. X    {
  154. X        malloc_errno = M_CODE_BAD_CONNECT;
  155. X        malloc_warning(func,file,line,ptr);
  156. X        return;
  157. X    }
  158. X
  159. X    /*
  160. X     * if we are filling the area with fill bytes, check to see if the
  161. X     * program has gone beyond the end of the assigned area
  162. X     */
  163. X    if( malloc_fill_area )
  164. X    {
  165. X        for(i=ptr->r_size; i < ptr->s.size; i++)
  166. X        {
  167. X            if( ptr->data[i] != M_FILL )
  168. X            {
  169. X                malloc_errno = M_CODE_OVERRUN;
  170. X                malloc_warning(func,file,line,ptr);
  171. X                break;
  172. X            }
  173. X        }
  174. X    }
  175. X
  176. X    /*
  177. X     * flag block as freed
  178. X     */
  179. X    ptr->flag &= ~M_INUSE;
  180. X
  181. X    DEBUG3(10,"pointers: prev: 0x%.7x,  ptr: 0x%.7x, next: 0x%.7x",
  182. X            ptr->prev, ptr, ptr->next);
  183. X    
  184. X    DEBUG3(10,"size:     prev: %9d,  ptr: %9d, next: %9d",
  185. X            ptr->prev->s.size, ptr->s.size, ptr->next->s.size);
  186. X    
  187. X    DEBUG3(10,"flags:    prev: 0x%.7x,  ptr: 0x%.7x, next: 0x%.7x",
  188. X            ptr->prev->flag, ptr->flag, ptr->next->flag);
  189. X    
  190. X    /*
  191. X     * check to see if this block can be combined with the next and/or
  192. X     * previous block.  Since it may be joined with the previous block
  193. X     * we will save a pointer to the previous block and test to verify
  194. X     * if it is joined (it's next ptr will no longer point to ptr).
  195. X      */
  196. X    malloc_join(ptr,ptr->next,0,0);
  197. X    
  198. X    oldptr = ptr->prev;
  199. X
  200. X    malloc_join(ptr->prev, ptr,0,0);
  201. X
  202. X    if( oldptr->next != ptr )
  203. X    {
  204. X        DEBUG0(10,"Oldptr was changed");
  205. X        ptr = oldptr;
  206. X    }
  207. X    /*
  208. X     * else, since the oldptr did not change, ptr is now a new free segment
  209. X     * that must be added to the free list, so go do it.
  210. X     */
  211. X    else
  212. X    {
  213. X        malloc_freeseg(M_FREE_ADD,ptr);
  214. X    }
  215. X    
  216. X    /*
  217. X     * fill this block with '\02's to ensure that nobody is using a 
  218. X     * pointer to already freed data...
  219. X     */
  220. X    if( malloc_fill_area )
  221. X    {
  222. X        malloc_aligned_memset(ptr->data,M_FREE_FILL,(int)ptr->s.size);
  223. X    }
  224. X
  225. X}
  226. X
  227. X/*
  228. X * $Log: free.c,v $
  229. X * Revision 1.17  1992/01/28  14:30:18  cpcahil
  230. X * Changes from the c.s.r second review
  231. X *
  232. X * Revision 1.16  1992/01/10  17:28:03  cpcahil
  233. X * Added support for overriding void datatype
  234. X *
  235. X * Revision 1.15  1991/12/06  17:58:44  cpcahil
  236. X * added cfree() for compatibility with some wierd systems
  237. X *
  238. X * Revision 1.14  91/12/06  08:54:17  cpcahil
  239. X * cleanup of __STDC__ usage and addition of CHANGES file
  240. X * 
  241. X * Revision 1.13  91/12/04  09:23:37  cpcahil
  242. X * several performance enhancements including addition of free list
  243. X * 
  244. X * Revision 1.12  91/12/02  19:10:09  cpcahil
  245. X * changes for patch release 5
  246. X * 
  247. X * Revision 1.11  91/11/25  14:41:53  cpcahil
  248. X * Final changes in preparation for patch 4 release
  249. X * 
  250. X * Revision 1.10  91/11/24  00:49:25  cpcahil
  251. X * first cut at patch 4
  252. X * 
  253. X * Revision 1.9  90/08/29  21:22:48  cpcahil
  254. X * miscellaneous lint fixes
  255. X * 
  256. X * Revision 1.8  90/05/11  00:13:08  cpcahil
  257. X * added copyright statment
  258. X * 
  259. X * Revision 1.7  90/02/25  11:00:18  cpcahil
  260. X * added support for malloc chain checking.
  261. X * 
  262. X * Revision 1.6  90/02/24  21:50:18  cpcahil
  263. X * lots of lint fixes
  264. X * 
  265. X * Revision 1.5  90/02/24  17:29:13  cpcahil
  266. X * changed $Header to $Id so full path wouldnt be included as part of rcs 
  267. X * id string
  268. X * 
  269. X * Revision 1.4  90/02/24  15:15:32  cpcahil
  270. X * 1. changed ALREADY_FREE errno to NOT_INUSE so that the same errno could
  271. X *    be used by both free and realloc (since it was the same error).
  272. X * 2. fixed coding bug
  273. X * 
  274. X * Revision 1.3  90/02/24  14:23:45  cpcahil
  275. X * fixed malloc_warning calls
  276. X * 
  277. X * Revision 1.2  90/02/24  13:59:10  cpcahil
  278. X * added function header.
  279. X * Modified calls to malloc_warning/malloc_fatal to use new code error messages
  280. X * Added support for malloc_errno setting of error codes.
  281. X * 
  282. X * Revision 1.1  90/02/22  23:17:43  cpcahil
  283. X * Initial revision
  284. X * 
  285. X */
  286. END_OF_FILE
  287. if test 6163 -ne `wc -c <'free.c'`; then
  288.     echo shar: \"'free.c'\" unpacked with wrong size!
  289. fi
  290. # end of 'free.c'
  291. fi
  292. if test -f 'm_init.c' -a "${1}" != "-c" ; then 
  293.   echo shar: Will not clobber existing file \"'m_init.c'\"
  294. else
  295. echo shar: Extracting \"'m_init.c'\" \(2609 characters\)
  296. sed "s/^X//" >'m_init.c' <<'END_OF_FILE'
  297. X/*
  298. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  299. X * You may copy, distribute, and use this software as long as this
  300. X * copyright statement is not removed.
  301. X */
  302. X
  303. X#ifndef lint
  304. Xstatic
  305. Xchar rcs_hdr[] = "$Id: m_init.c,v 1.11 1992/01/10 17:28:03 cpcahil Exp $";
  306. X#endif
  307. X
  308. X#include <stdio.h>
  309. X#include "mallocint.h"
  310. X
  311. X/*
  312. X * Function:    malloc_init()
  313. X *
  314. X * Purpose:    to initialize the pointers and variables use by the
  315. X *        malloc() debugging library
  316. X *
  317. X * Arguments:    none
  318. X *
  319. X * Returns:    nothing of any value
  320. X *
  321. X * Narrative:    Just initialize all the needed variables.  Use mallopt
  322. X *        to set options taken from the environment.
  323. X *
  324. X */
  325. XVOIDTYPE
  326. Xmalloc_init()
  327. X{
  328. X    char            * cptr;
  329. X    char            * getenv();
  330. X    union malloptarg      m;
  331. X
  332. X    /*
  333. X      * If already initialized...
  334. X     */
  335. X    if( malloc_data_start != (char *) 0)
  336. X    {
  337. X        return;
  338. X    }
  339. X
  340. X
  341. X    malloc_data_start = sbrk(0);
  342. X    malloc_data_end = malloc_data_start;
  343. X    malloc_start.s.size = 0;
  344. X    malloc_end = &malloc_start;
  345. X    
  346. X    if( (cptr=getenv("MALLOC_WARN")) != NULL )
  347. X    {
  348. X        m.i = atoi(cptr);
  349. X        VOIDCAST mallopt(MALLOC_WARN,m);
  350. X    }
  351. X
  352. X    if( (cptr=getenv("MALLOC_FATAL")) != NULL)
  353. X    {
  354. X        m.i = atoi(cptr);
  355. X        VOIDCAST mallopt(MALLOC_FATAL,m);
  356. X    }
  357. X
  358. X    if( (cptr=getenv("MALLOC_CKCHAIN")) != NULL)
  359. X    {
  360. X        m.i = atoi(cptr);
  361. X        VOIDCAST mallopt(MALLOC_CKCHAIN,m);
  362. X    }
  363. X
  364. X    if( (cptr=getenv("MALLOC_LOWFRAG")) != NULL)
  365. X    {
  366. X        m.i = atoi(cptr);
  367. X        VOIDCAST mallopt(MALLOC_LOWFRAG,m);
  368. X    }
  369. X
  370. X    if( (cptr=getenv("MALLOC_ERRFILE")) != NULL)
  371. X    {
  372. X        m.str = cptr;
  373. X        VOIDCAST mallopt(MALLOC_ERRFILE,m);
  374. X    }
  375. X
  376. X    if( (cptr=getenv("MALLOC_FILLAREA")) != NULL)
  377. X    {
  378. X        m.i = atoi(cptr);
  379. X        VOIDCAST mallopt(MALLOC_FILLAREA,m);
  380. X    }
  381. X
  382. X}
  383. X
  384. X/*
  385. X * $Log: m_init.c,v $
  386. X * Revision 1.11  1992/01/10  17:28:03  cpcahil
  387. X * Added support for overriding void datatype
  388. X *
  389. X * Revision 1.10  1991/12/31  21:31:26  cpcahil
  390. X * changes for patch 6.  See CHANGES file for more info
  391. X *
  392. X * Revision 1.9  1991/12/04  09:23:38  cpcahil
  393. X * several performance enhancements including addition of free list
  394. X *
  395. X * Revision 1.8  91/11/25  14:41:54  cpcahil
  396. X * Final changes in preparation for patch 4 release
  397. X * 
  398. X * Revision 1.7  91/11/24  00:49:26  cpcahil
  399. X * first cut at patch 4
  400. X * 
  401. X * Revision 1.6  90/08/29  22:23:21  cpcahil
  402. X * fixed mallopt to use a union as an argument.
  403. X * 
  404. X * Revision 1.5  90/08/29  21:22:50  cpcahil
  405. X * miscellaneous lint fixes
  406. X * 
  407. X * Revision 1.4  90/05/11  15:53:35  cpcahil
  408. X * fixed bug in initialization code.
  409. X * 
  410. X * Revision 1.3  90/05/11  00:13:08  cpcahil
  411. X * added copyright statment
  412. X * 
  413. X * Revision 1.2  90/02/24  21:50:20  cpcahil
  414. X * lots of lint fixes
  415. X * 
  416. X * Revision 1.1  90/02/24  17:10:53  cpcahil
  417. X * Initial revision
  418. X * 
  419. X */
  420. END_OF_FILE
  421. if test 2609 -ne `wc -c <'m_init.c'`; then
  422.     echo shar: \"'m_init.c'\" unpacked with wrong size!
  423. fi
  424. # end of 'm_init.c'
  425. fi
  426. if test -f 'm_perror.c' -a "${1}" != "-c" ; then 
  427.   echo shar: Will not clobber existing file \"'m_perror.c'\"
  428. else
  429. echo shar: Extracting \"'m_perror.c'\" \(2419 characters\)
  430. sed "s/^X//" >'m_perror.c' <<'END_OF_FILE'
  431. X/*
  432. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  433. X * You may copy, distribute, and use this software as long as this
  434. X * copyright statement is not removed.
  435. X */
  436. X
  437. X#ifndef lint
  438. Xstatic
  439. Xchar rcsid[] = "$Id: m_perror.c,v 1.9 1992/01/10 17:28:03 cpcahil Exp $";
  440. X#endif
  441. X
  442. X#include "mallocint.h"
  443. X
  444. X/*
  445. X * malloc errno error strings...
  446. X */
  447. X
  448. Xchar *malloc_err_strings[] = 
  449. X{
  450. X    "No errors",
  451. X    "Malloc chain is corrupted, pointers out of order",
  452. X    "Malloc chain is corrupted, end before end pointer",
  453. X    "Pointer is not within malloc area",
  454. X    "Malloc region does not have valid magic number in header",
  455. X    "Pointers between this segment and ajoining segments are invalid",
  456. X    "Data has overrun beyond requested number of bytes",
  457. X    "Data in free'd area has been modified",
  458. X    "Data are is not in use (can't be freed or realloced)",
  459. X    "Unable to get additional memory from the system",
  460. X    "Pointer within malloc region, but outside of malloc data bounds",
  461. X    "Malloc segment in free list is in-use",
  462. X    (char *) 0
  463. X};
  464. X
  465. X/*
  466. X * Function:    malloc_perror()
  467. X *
  468. X * Purpose:    to print malloc_errno error message
  469. X *
  470. X * Arguments:    str    - string to print with error message
  471. X *
  472. X * Returns:    nothing of any value
  473. X *
  474. X * Narrative:
  475. X */
  476. XVOIDTYPE
  477. Xmalloc_perror(str)
  478. X    char    * str;
  479. X{
  480. X    register char     * s;
  481. X    register char     * t;
  482. X
  483. X    if( str && *str)
  484. X    {
  485. X        for(s=str; *s; s++)
  486. X        {
  487. X            /* do nothing */;
  488. X        }
  489. X
  490. X        VOIDCAST write(2,str,(unsigned)(s-str));
  491. X        VOIDCAST write(2,": ",(unsigned)2);
  492. X    }
  493. X
  494. X    t = malloc_err_strings[malloc_errno];
  495. X
  496. X    for(s=t; *s; s++)
  497. X    {
  498. X        /* do nothing */;
  499. X    }
  500. X
  501. X    VOIDCAST write(2,t,(unsigned)(s-t));
  502. X
  503. X    VOIDCAST write(2,"\n",(unsigned)1);
  504. X}
  505. X
  506. X/*
  507. X * $Log: m_perror.c,v $
  508. X * Revision 1.9  1992/01/10  17:28:03  cpcahil
  509. X * Added support for overriding void datatype
  510. X *
  511. X * Revision 1.8  1991/12/04  09:23:38  cpcahil
  512. X * several performance enhancements including addition of free list
  513. X *
  514. X * Revision 1.7  91/11/25  14:41:55  cpcahil
  515. X * Final changes in preparation for patch 4 release
  516. X * 
  517. X * Revision 1.6  91/11/24  00:49:27  cpcahil
  518. X * first cut at patch 4
  519. X * 
  520. X * Revision 1.5  90/08/29  21:25:08  cpcahil
  521. X * added additional error message that was missing (and 
  522. X * caused a core dump)
  523. X * 
  524. X * Revision 1.4  90/05/11  00:13:08  cpcahil
  525. X * added copyright statment
  526. X * 
  527. X * Revision 1.3  90/02/24  21:50:21  cpcahil
  528. X * lots of lint fixes
  529. X * 
  530. X * Revision 1.2  90/02/24  17:39:55  cpcahil
  531. X * 1. added function header
  532. X * 2. added rcs id and log strings.
  533. X * 
  534. X */
  535. END_OF_FILE
  536. if test 2419 -ne `wc -c <'m_perror.c'`; then
  537.     echo shar: \"'m_perror.c'\" unpacked with wrong size!
  538. fi
  539. # end of 'm_perror.c'
  540. fi
  541. if test -f 'malloc.3' -a "${1}" != "-c" ; then 
  542.   echo shar: Will not clobber existing file \"'malloc.3'\"
  543. else
  544. echo shar: Extracting \"'malloc.3'\" \(27763 characters\)
  545. sed "s/^X//" >'malloc.3' <<'END_OF_FILE'
  546. X.TH DEBUG_MALLOC 3 "VTI" "" "1.4"
  547. X.ds ]T 
  548. X'\"/*
  549. X'\" * (c) Copyright 1990,1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  550. X'\" * You may copy, distribute, and use this software as long as this
  551. X'\" * copyright statement is not removed.
  552. X'\" */
  553. X'\" 
  554. X'\" $Id: malloc.3,v 1.11 1992/01/28 18:01:06 cpcahil Exp $
  555. X'\" 
  556. X'\" eX macro -  this macro is used to set up code/picture examples.  It changes
  557. X'\"             the point size & type of font, indents the example 1/2 inch,
  558. X'\"        and turns off fill mode.  To use it just place a .eX before and
  559. X'\"        after your example
  560. X.de eX
  561. X.ie \\n(eX>0 \{\
  562. X.nr eX 0
  563. X.ft
  564. X.fi
  565. X.vs
  566. X.ps
  567. X.in
  568. X.sp \}
  569. X.el \{\
  570. X.nr eX 1
  571. X.br
  572. X.ne 5
  573. X.sp
  574. X.nf
  575. X.ie \\n(.$>0 .in +\\$1
  576. X.el .in +.5i
  577. X.ie \\n(.$=2 .ps -\\$2
  578. X.el .ps -2
  579. X.ie \\n(.$=2 .vs -\\$2
  580. X.el .vs -2
  581. X.ft CW \}
  582. X..
  583. X.nr eX 0
  584. X'\" 
  585. X'\" fake set of VL LI and LE macros for man pages.  This set does handle nested
  586. X'\" calls, but does absolutely NO error checking (so you better do it right).
  587. X'\" 
  588. X.de VL
  589. X.br
  590. X.ie t .nr VL 0\\$1
  591. X.el .nr VL 0\\$1*2
  592. X.ds VS \\$1 \\*(VS
  593. X.in +\\n(VL
  594. X.if t .in +.25i
  595. X..
  596. X.de LI
  597. X.br
  598. X.ti -\\n(VL
  599. X.nr Vw \\n(VLm-\w'\\$1'
  600. X.if \w'\\$1' \&\\$1\h'\\n(Vwu'\&\\c
  601. X..
  602. X.de LE
  603. X.br
  604. X.Le \\*(VS 
  605. X..
  606. X.de Le
  607. X.in -\\n(VL
  608. X.if t .in -.25i
  609. X.ie t .nr VL \\$2
  610. X.el .nr VL \\$2*2
  611. X.ds VS \\$2 \\$3 \\$4 \\$5 \\$6 \\$7
  612. X..
  613. X.ds VS
  614. X.nr VL 0
  615. X.deMP
  616. X.sp\\n(PDu
  617. X..
  618. X.SH NAME
  619. Xmalloc \t- debugging malloc library
  620. X.SH SYNOPSIS
  621. X.nf
  622. X\fB#include <malloc.h>
  623. X.MP
  624. Xchar * calloc(nelem,elsize);
  625. Xunsigned nelem, elsize;
  626. X.MP
  627. Xvoid cfree(ptr)
  628. Xchar * ptr;
  629. X.MP
  630. Xvoid free(ptr);
  631. Xchar * ptr;
  632. X.MP
  633. Xchar * malloc(size);
  634. Xunsigned size;
  635. X.MP
  636. Xint malloc_chain_check(flag);
  637. Xint flag;
  638. X.MP
  639. Xvoid malloc_dump(fd);
  640. Xint fd;
  641. X.MP
  642. Xvoid malloc_list(fd,histid1,histid2);
  643. Xint fd;
  644. Xunsigned long histid1, histid2;
  645. X.MP
  646. Xunsigned long malloc_size(histidptr);
  647. Xunsigned long * histidptr;
  648. X.MP
  649. Xint mallopt(cmd,val);
  650. Xint cmd; 
  651. Xunion malloptarg val;
  652. X.MP
  653. Xchar * realloc(ptr,size);
  654. Xchar * ptr;
  655. Xunsigned size;\fP
  656. X.fi
  657. X.SH DESCRIPTION
  658. XThis malloc library is a replacement for the standard library to be used
  659. Xduring software development/debugging.  See the standard malloc(3) pages
  660. Xfor more information on the use of the following functions:
  661. X.MP
  662. X.nf
  663. X.in +.5i
  664. X\fBcalloc\fP(), \fBcfree\fP(), \fBfree\fP(), \fBmalloc\fP(), \fBrealloc\fP()
  665. X.in -.5i
  666. X.fi
  667. X.MP
  668. XThis library differs from the standard malloc library in the
  669. Xfollowing ways:
  670. X.P
  671. X1. Each malloc segment contains a magic number so that free can 
  672. Xverify that the pointer passed points to a valid malloc segment.
  673. X.P
  674. X2. Each malloc segment is filled with a non-zero pattern so that code that
  675. Xdepends upon malloc segments being null will fail.
  676. X.P
  677. X3. The size of each segment will be at least 1 byte larger than requested
  678. Xand the extra bytes will be filled with a non-zero pattern.  When free is
  679. Xcalled, it will verify that you did not go beyond the number of bytes 
  680. Xyou asked for.
  681. X.P
  682. X4. When a segment is freed, it will be filled with a different non-zero pattern
  683. Xto ensure that the program doesn't depend upon the use of already freed data.
  684. X.P
  685. X.ne 5
  686. X5. Whenever any of the string or memory functions (str*, b*, mem*) are 
  687. Xcalled with a pointer that is within the malloc arena,  the operation is
  688. Xchecked to verify that it does not overrun the malloced segment.  A failure
  689. Xof this check is considered a "warning level error" (described later) and
  690. Xis handled accordingly.
  691. X.P
  692. X6. Run time checking can include verification of the malloc chain at each
  693. Xand every call to one of the malloc functions or manually by calling the
  694. Xmalloc_chain_check function.
  695. X.P
  696. X.br
  697. X.ne 15
  698. XWhen a problem is found, the following error message is displayed:
  699. X.eX
  700. XMALLOC Warning from funcname() (called from filename.c line ###):
  701. XWarning message goes here
  702. X.eX
  703. X\fBfuncname\fP is the name of the function that has found the problem
  704. Xand will usually be an entry point into the library.  The information
  705. Xthat identifies where the function is called from will only be 
  706. Xavailable if the source module was compiled with the \fBmalloc.h\fP
  707. Xfile included.
  708. X.P
  709. XIf the error is caused by a problem in the malloc chain and the offending
  710. Xchain element can be identified, the following information is also
  711. Xdisplayed (NOTE: this is just a guess by the software, it may not
  712. Xbe the actual culprit):
  713. X.eX
  714. XThis error is *probably* associated with the following allocation:
  715. X
  716. X   A call to malloc for 33 bytes in program.c on line 834.
  717. X   This was the 172nd call to malloc.
  718. X.eX
  719. X.br
  720. X.ne 15
  721. XThis example assumes that \fBprogram.c\fP included the debugging 
  722. Xlibrary \fBmalloc.h\fP file.  If not, the identification information
  723. Xwill be as follows:
  724. X.eX
  725. XThis error is *probably* associated with the following allocation:
  726. X
  727. X   A call to malloc for 33 bytes in an unknown file.
  728. X   This was the 172nd call to malloc.
  729. X.eX
  730. XThe identification of which call to malloc is associated with the 
  731. Xproblem is helpful in that it gives you the information necessary
  732. Xto set the breakpoint on the allocation function for that particular
  733. Xinvocation (breakpoints usually can have counters associated with
  734. Xthem).  The counters for the three primary allocation entry points (malloc,
  735. Xcalloc, and realloc) are managed separately.
  736. X.P
  737. X.br
  738. X.ne 5
  739. XNOTE 1: if you want to set a breakpoint to capture this invocation
  740. Xof malloc, the actual function that is being called is \fBdebug_malloc\fP
  741. X(or \fBdebug_realloc\fP for \fBrealloc\fP and \fBdebug_calloc\fP for
  742. X\fBcalloc\fP) and that is where the breakpoint should be set.
  743. X.P
  744. X.br
  745. X.ne 19
  746. XNOTE 2: Since the software is guessing at the offending malloc
  747. Xchain segment, it is possible that one of the nearby segments 
  748. Xis actually the culprit.  If the environment variable \s-2MALLOC_SHOW_LINKS\s+2
  749. Xis set, both the segment preceding and the segment following the accused
  750. Xsegment will also be identified.  The following is a sample output:
  751. X.eX
  752. XThis error is *probably* associated with the following allocation:
  753. X
  754. X    A call to malloc for 33 bytes in an unknown file.
  755. X    This was the 172nd call to malloc.
  756. X
  757. X    The malloc chain element prior to the suspect allocation is from:
  758. X
  759. X    A call to calloc for 512 bytes in main.c line 16.
  760. X    This was the 4th call to calloc.  This block has been freed.
  761. X    The malloc chain element following the suspect allocation is from: 
  762. X
  763. X    A call to realloc for 4096 bytes in func.c line 376.
  764. X    This was the 1st call to realloc.
  765. X.eX
  766. X.br
  767. X.ne 15
  768. XOnce the error message has been displayed, the software will then 
  769. Xdetermine how to handle the error.  This handling will be based upon
  770. Xthe type of error level (warning or fatal) and the error handling in effect
  771. Xfor that error level (as specified by calls to mallopt or via environment
  772. Xvariables).  The coding for the error handling is as follows:
  773. X.MP
  774. X.VL 3
  775. X.LI "\0\00"
  776. Xcontinue operations
  777. X.LI "\0\01"
  778. Xdrop core and exit
  779. X.LI "\0\02"
  780. Xjust exit
  781. X.LI "\0\03"
  782. Xdrop core, but continue executing.  Core files will
  783. Xbe placed into core.[PID].[counter] i.e: core.00123.001
  784. X.LI "128"
  785. Xdump malloc chain and continue
  786. X.LI "129"
  787. Xdump malloc chain, dump core, and exit
  788. X.LI "130"
  789. Xdump malloc chain, exit
  790. X.LI "131"
  791. Xdump malloc chain, dump core, continue processing
  792. X.LE
  793. X.P
  794. X\fBmallopt\fP() is used to set the malloc debugging options. The
  795. Xfollowing options can be set:
  796. X.MP
  797. X.VL 10
  798. X.LI "\s-2MALLOC_WARN(100)\s+2"
  799. Xset the error handling for warning level errors.  \fBval.i\fP is
  800. Xan integer that can contain any one of the following values:
  801. X.MP
  802. X.VL 10
  803. X.LI "\s-2M_HANDLE_IGNORE(0)\s+2"
  804. Xignore error
  805. X.LI "\s-2M_HANDLE_ABORT(1)\s+2"
  806. Xdrop core and exit
  807. X.LI "\s-2M_HANDLE_EXIT(2)\s+2"
  808. Xjust exit (no core drop)
  809. X.LI "\s-2M_HANDLE_CORE(3)\s+2"
  810. Xdrop core, but keep on going
  811. X.LE
  812. X.MP
  813. XIn addition, \s-2M_HANDLE_DUMP\s+2(128) may be or'd in to cause a dump
  814. Xof the current malloc chain.
  815. X.MP
  816. X.LI "\s-2MALLOC_FATAL(101)\s+2"
  817. Xset the error handling for fatal level errors.  \fBval.i\fP is
  818. Xequivalent to \fBval.i\fP for MALLOC_WARN.
  819. X.MP
  820. X.LI "\s-2MALLOC_ERRFILE(102)\s+2"
  821. Xset the destination for malloc error messages.  \fBval.str\fP
  822. Xis a pointer to a character string containing the name of the file to be used
  823. Xfor error messages.
  824. X.MP
  825. X.ne 3
  826. X.LI "\s-2MALLOC_CKCHAIN(103)\s+2"
  827. Xset the malloc chain checking flag.  If \fBval.i\fP is
  828. Xnon-zero, chain checking at every call to malloc is turned on.
  829. X.MP
  830. X.LI "\s-2MALLOC_FILLAREA(104)\s+2"
  831. Xset the malloc fill area flag.  If \fBval.i\fP is zero, malloc and free will
  832. Xnot fill allocated/freed memory regions with special fill patterns.  Utilizing
  833. Xthis feature increases the performance of the library while decreasing the
  834. Xeffectiveness of tracking down overrun problems.  It is strongly recommended
  835. Xthat this option not be used.
  836. X.MP
  837. X.LI "\s-2MALLOC_LOWFRAG(105)\s+2"
  838. Xset the malloc allocation fragmentation handling level.  By default, malloc
  839. Xuses a first fit algorithm for new allocations.  Under certain allocation
  840. Xscenarios, this can lead to significant memory fragmentation because of
  841. Xthe fact that little allocations can break big blocks up.
  842. X.MP
  843. XIf \fBval.i\fP is non-zero, malloc uses a best fit algorithm which will reduce
  844. Xfragmentation.  This mechanism, while using less memory, is slower because
  845. Xthe entire free list is checked instead of just checking until we find a
  846. Xsegment that is at least big enough.  Normally you will not need to set
  847. Xthis variable.
  848. X.LE
  849. X.MP
  850. X.ne 10
  851. XFor example, to set up the session to generate a core file for
  852. Xevery malloc warning, to drop core and exit on a malloc fatal, and 
  853. Xto log all messages to the file "malloc_log" do the following:
  854. X.eX
  855. X#include <malloc.h>
  856. Xunion malloptarg  m;
  857. X
  858. Xm.i = 131;
  859. Xmallopt(MALLOC_WARN,m);
  860. X
  861. Xm.i = 1;
  862. Xmallopt(MALLOC_FATAL,m);
  863. X
  864. Xm.str = "malloc_log";
  865. Xmallopt(MALLOC_ERRFILE,m);
  866. X.eX
  867. X\fBmallopt\fP() can be used to set/alter the debugging options at any
  868. Xtime (i.e. you may want to turn on chain-checking after the program startup if
  869. Xthe program startup does a lot of allocations which are known to be OK).
  870. X.P
  871. X.ne 5
  872. X\fBmalloc_chain_check\fP() will check the status of the malloc arena.
  873. XIf \fBflag\fP is non-zero, an error found in the chain will cause a 
  874. Xfatal error.  \fBmalloc_chain_check\fP() returns zero when there are no
  875. Xproblems found in the malloc chain, non-zero otherwise.
  876. X.P
  877. X.ne 5
  878. X\fBmalloc_dump\fP() will dump a list of all in-use malloc segments 
  879. Xand the first few bytes of each segment.  If the environment variable
  880. X\s-1MALLOC_DETAIL\s+1 is set, all segments (including those that have
  881. Xbeen freed) are listed and additional internal information is displayed.
  882. X\fBfd\fP is the file descriptor to write the data to.
  883. X.P
  884. X.ne 6
  885. X\fBmalloc_list\fP() will dump a list in the same format as \fBmalloc_dump\fP but
  886. Xonly the items that are still in use and which have been allocated within
  887. Xthe malloc history id range specified by \fBhistid1\fP and
  888. X\fBhistid2\fP, inclusive.  The \fBhistid\fPs are obtained from calls
  889. Xto \fBmalloc_size\fP(). This is especially useful in tracking down memory
  890. Xleaks.  \fBfd\fP is the file descriptor to write the data to.
  891. X.P
  892. X.ne 6
  893. X\fBmalloc_size\fP() returns the amount of malloc data that is currently
  894. Xin use (in bytes).  If \fBhistidptr\fP is not NULL, it is taken to be a pointer
  895. Xto a place to store the current malloc history id which can be used later
  896. Xwhen \fBmalloc_list\fP is called to list items that are still in use.
  897. X.P
  898. X.ne 10
  899. XThe following example shows the typical use of the \fBmalloc_size\fP and
  900. X\fBmalloc_list\fP functions in tracking down memory leaks:
  901. X.eX
  902. Xunsigned long    histid1, histid2, orig_size, current_size;
  903. X
  904. Xorig_size = malloc_size(&histid1);
  905. X
  906. X/* ..... go do lots of stuff ...... */
  907. X
  908. Xcurrent_size = malloc_size(&histid2);
  909. X
  910. Xif( current_size != orig_size )
  911. X{
  912. X    malloc_list(2,histid1,histid2);
  913. X}
  914. X.eX
  915. X.br
  916. X.ne 20
  917. X.SH "USAGE"
  918. XThe library can be used in several modes, each increasingly intrusive (i.e. 
  919. Xrequiring changes to be made to the build process and/or source code).  However,
  920. Xthe extra cost of a little intrusiveness is repaid in much better problem
  921. Xidentification.  Each mode is built upon the previous modes and therefore
  922. Xrequires the changes and/or commands specified in the lower modes.
  923. X.P
  924. X.ne 10
  925. X\fBMODE 1 - library substitution\fP
  926. X.P
  927. XThe simplest use is to just link the object module with the \fBlibdbmalloc.a\fP.
  928. XBe sure to have this library before the C library (\fBlibc.a\fP) on the
  929. Xlink command (this is automatic if you use \fBcc\fP to link and specify the 
  930. Xdebug library without specifying the C library).
  931. X.P
  932. XThis mode links in all of the debug versions of the library modules and
  933. Xwill trap as many errors as it can (yes, there are errors that the malloc
  934. Xlibrary cannot catch).  Environment variables can be used to control the
  935. Xbehavior of the library.
  936. X.P
  937. X.ne 15
  938. X\fBMODE 2 - malloc.h inclusion\fP
  939. X.P
  940. XThis mode involves including the \fBmalloc.h\fP file included with the 
  941. Xdebugging library.  The malloc.h file includes macros that will identify
  942. Xthe source line and file name for each debugging function called.  This
  943. Xis how the library is able to tell you that it was the call to malloc
  944. Xon line 55 in file junk.c.
  945. X.P
  946. X.ne 8
  947. XTypically you should always include malloc.h in your source files and just
  948. Xuse the -I INCLUDEDIR directive for the compiler to point the compiler to
  949. Xthe debugging version of the header file instead of the normal file.  That
  950. Xway you don't have to change the source files when you want to turn off
  951. Xthe debugging library.
  952. X.P
  953. XNOTE: Once you compile code in this mode, you must recompile the code 
  954. Xwithout the debugging malloc.h include file in order to get the software
  955. Xto use the non-debugging functions.
  956. X.P
  957. X.ne 10
  958. X\fBMODE 3 - run-time specification of options\fP
  959. X.P
  960. XEnvironment variables can be used to control the behavior of the debugging
  961. Xlibrary to some extent.  However, this control is very coarse in that
  962. Xyou only have one setting available for the entire running of the program.
  963. X.P
  964. XThis can be a problem if you want to turn on malloc chain checking, but
  965. Xknow that the problem occurs between a relatively narrow portion of the
  966. Xcode and don't want to take the hit of having chain checking on for the
  967. Xentire program execution.  
  968. X.P
  969. X.ne 15
  970. XThe solution to this problem is to include calls to mallopt() with the
  971. Xdebugging options which set the appropriate modes when you want them set.
  972. XSince you don't want to have to change the code to remove and add these
  973. Xfunctions every time you decide to include malloc debugging or not, the 
  974. X\fBmalloc.h\fP file defines the preprocessor symbol \s-2_DEBUG_MALLOC_INC\s+2
  975. Xwhich can be used in your code as follows:
  976. X.eX
  977. X#ifdef _DEBUG_MALLOC_INC
  978. X    mallopt(.... );
  979. X#endif
  980. X.eX
  981. XIn addition to setting behavior options, you might want to make use of
  982. Xthe memory leak detection routines in this mode.  These calls should
  983. Xalso be surrounded by #ifdefs for the debug malloc symbol so that you
  984. Xcan leave them in the code and automatically get
  985. Xthe increased functionality whenever you compile with the debugging library.
  986. X.br
  987. X.ne 15
  988. X.SH "ENVIRONMENT VARIABLES"
  989. XEnvironment variables can be used to control error handling, error logging
  990. Xand malloc chain checking at run time.  The following environment variables
  991. Xare used:
  992. X.P
  993. X.VL 10
  994. X.br
  995. X.ne 4
  996. X.LI "\s-2MALLOC_CKCHAIN\s+2"
  997. Xif 1, turns on malloc chain checking at every call to any
  998. Xof the malloc functions.
  999. X.br
  1000. X.ne 4
  1001. X.LI "\s-2MALLOC_DETAIL\s+2"
  1002. Xif set, \fBmalloc_dump\fP shows some internal detail for each 
  1003. Xentry in the chain.  This info is probably only of use if you are debugging 
  1004. Xthe malloc library itself.
  1005. X.br
  1006. X.ne 4
  1007. X.LI "\s-2MALLOC_ERRFILE\s+2"
  1008. Xspecifies the error log file for error messages.  
  1009. X.br
  1010. X.ne 4
  1011. X.LI "\s-2MALLOC_FATAL\s+2"
  1012. Xspecifies the error handling for fatal errors
  1013. X.br
  1014. X.ne 4
  1015. X.LI "\s-2MALLOC_FILLAREA\s+2"
  1016. Xspecifies the fill area flag setting.  If zero, malloc/free area filling 
  1017. Xand checking is disabled (thereby increasing performance, while decreasing
  1018. Xeffectiveness of the library).
  1019. X.br
  1020. X.ne 4
  1021. X.LI "\s-2MALLOC_LOWFRAG\s+2"
  1022. Xif 1, turns on best fit allocation algorithm.  Otherwise, first fit algorithm
  1023. Xis used for finding allocation segments (which can cause memory fragmentation).
  1024. X.br
  1025. X.ne 4
  1026. X.LI "\s-2MALLOC_SHOW_LINKS\s+2"
  1027. Xwhen an error is found, the suspected allocation is
  1028. Xdisplayed.  However, since it is possible that the next or previous allocation
  1029. Xin the malloc chain was the actual culprit these links may be of interest.
  1030. XIf this variable is set to non-zero (i.e. 1) the links will also be shown.
  1031. X.br
  1032. X.ne 2
  1033. X.LI "\s-2MALLOC_WARN\s+2"
  1034. Xspecifies the error handling for warning errors
  1035. X.LE
  1036. X.P
  1037. XAs an example, to set up the session to generate a core file for
  1038. Xevery malloc warning, to drop core and exit on a malloc fatal, and 
  1039. Xto log all messages to the file "malloc_log" do the following:
  1040. X.eX
  1041. XMALLOC_WARN=131
  1042. XMALLOC_FATAL=1
  1043. XMALLOC_ERRFILE=malloc_log
  1044. X
  1045. Xexport MALLOC_WARN MALLOC_FATAL MALLOC_ERRFILE
  1046. X.eX
  1047. X.br
  1048. X.ne 15
  1049. X.SH "ERROR MESSAGES"
  1050. XThe following error messages are reported by the library:
  1051. X.VL 15
  1052. X.br
  1053. X.MP
  1054. X.ne 6
  1055. X.LI "\s-2M_CODE_BAD_CONNECT(5)\s+2"
  1056. XPointers between this segment and adjoining segments are invalid.
  1057. X.MP
  1058. XThis error indicates that the malloc chain has been corrupted.
  1059. XThis is most often caused by an overwrite of the malloc header
  1060. Xby an access via the previous malloc segment.
  1061. X.br
  1062. X.MP
  1063. X.ne 6
  1064. X.LI "\s-2M_CODE_BAD_MAGIC(4)\s+2"
  1065. XMalloc region does not have a valid magic number in header.
  1066. X.MP
  1067. XThis error is caused by several mechanisms including \fBfree\fP()ing
  1068. Xthe same pointer twice or a pointer that was not returned by \fBmalloc\fP(),
  1069. Xor writing beyond the end of a segment.
  1070. X.br
  1071. X.MP
  1072. X.ne 6
  1073. X.LI "\s-2M_CODE_BAD_PTR(3)\s+2"
  1074. XPointer is not within malloc region.
  1075. X.MP
  1076. XThe pointer passed to \fBfree\fP or\fPrealloc\fP is not pointer 
  1077. Xreturned by \fBmalloc\fP.  Another cause is corruption of the
  1078. Xmalloc chain by writing beyond the end of a segment.
  1079. X.br
  1080. X.MP
  1081. X.ne 6
  1082. X.LI "\s-2M_CODE_CHAIN_BROKE(1)\s+2"
  1083. XMalloc chain is corrupted, pointers out of order.
  1084. X.MP
  1085. XCorruption has been detected in the malloc chain that is
  1086. Xrelated to the relative positions of the malloc chain segments
  1087. Xin memory.  This is an indication that someone has overwritten
  1088. Xbeyond the amount they allocated.
  1089. X.br
  1090. X.MP
  1091. X.ne 6
  1092. X.LI "\s-2M_CODE_FREELIST_BAD(11)\s+2"
  1093. XMalloc segment in free list is in-use.
  1094. X.MP
  1095. XA segment that is in the free-list is flagged as in-use.  This is usually
  1096. Xcaused by overwriting from the previous segment in the malloc chain.
  1097. X.br
  1098. X.MP
  1099. X.ne 6
  1100. X.LI "\s-2M_CODE_NOMORE_MEM(9)\s+2"
  1101. XUnable to get additional memory from the system.
  1102. X.MP
  1103. XThe system call \fBsbrk\fP failed to obtain more memory
  1104. Xfor the program.
  1105. X.br
  1106. X.MP
  1107. X.ne 6
  1108. X.LI "\s-2M_CODE_NOT_INUSE(8)\s+2"
  1109. XData is not in use (can't be freed or reallocated).
  1110. X.MP
  1111. XA pointer to a malloc segment has been passed to \fBfree\fP() or
  1112. X\fBrealloc\fP(), but this segment has already been freed.
  1113. X.br
  1114. X.MP
  1115. X.ne 6
  1116. X.LI "\s-2M_CODE_NO_END(2)\s+2"
  1117. XMalloc chain is corrupted, end before end pointer.
  1118. X.MP
  1119. XYet another overwrite problem.   This error means that we got to 
  1120. Xwhat we believe is the end of the chain, but it does not match
  1121. Xthe recorded end of the chain.
  1122. X.br
  1123. X.MP
  1124. X.ne 6
  1125. X.LI "\s-2M_CODE_OUTOF_BOUNDS(10)\s+2"
  1126. XPointer within malloc region, but outside of malloc data bounds.
  1127. X.MP
  1128. XThis is caused by a call to one of the string/memory functions
  1129. Xthat attempt to read/write bytes that are not included in
  1130. Xthe allocation associated with that memory.  This is the
  1131. Xmost typical error that you will see from the malloc library.
  1132. X.br
  1133. X.MP
  1134. X.ne 6
  1135. X.LI "\s-2M_CODE_OVERRUN(6)\s+2"
  1136. XData has overrun beyond requested number of bytes.
  1137. X.MP
  1138. XThis error is detected by \fBfree\fP() and indicates that the
  1139. Xcurrent segment has written data beyond the number of bytes that
  1140. Xit requested.  This only catches overwrites when they are within
  1141. Xthe extra space allocated with each segment (this can range from
  1142. Xone to eight bytes).  If the overwrite occurs further along it
  1143. Xwill usually cause some corruption in the malloc chain.
  1144. X.br
  1145. X.MP
  1146. X.ne 6
  1147. X.LI "\s-2M_CODE_REUSE(7)\s+2"
  1148. XData in free'd area has been modified.
  1149. X.MP
  1150. XData in a freed segment has been modified.  This usually indicates
  1151. Xthat the program is using a pointer after it called free, but it
  1152. Xmay also be caused by an overwrite from a previous segment in 
  1153. Xthe chain.
  1154. X.LE
  1155. X.P
  1156. X.br
  1157. X.ne 15
  1158. X.SH "DUMP OUTPUT"
  1159. XSample dump/list output:
  1160. X.eX
  1161. X************************** Dump of Malloc Chain ****************************
  1162. XPOINTER     FILE  WHERE         LINE      ALLOC        DATA     HEX DUMP   
  1163. XTO DATA      ALLOCATED         NUMBER     FUNCT       LENGTH  OF BYTES 1-7 
  1164. X-------- -------------------- ------- -------------- ------- --------------
  1165. X0x403DB4 testerr.c                 15 malloc(1)           40 01010101010101  
  1166. X0x403E0C testerr.c                 16 realloc(1)          20 01010101010101  
  1167. X.eX
  1168. XThe info in each column is as follows:
  1169. X.MP
  1170. X.VL 10
  1171. X.br
  1172. X.ne 4
  1173. X.LI "\s-2POINTER\s+2"
  1174. Xthe pointer returned by the allocation function (the pointer
  1175. Xthe the allocated data area).
  1176. X.MP
  1177. X.br
  1178. X.ne 8
  1179. X.LI "\s-2FILE\s+2"
  1180. Xthe name of the file where the allocation function was called.  This
  1181. Xinformation is only available if the source file includes the \fBmalloc.h\fP
  1182. Xfile from this library (as opposed to the system include file).  If
  1183. Xthe source file did not include this file, the file will be listed
  1184. Xas unknown and the line number will be blank.
  1185. XNote that any malloc calls from system libraries will probably not have been
  1186. Xcompiled with the \fBmalloc.h\fP file included and will therefore
  1187. Xappear as unknown.
  1188. X.MP
  1189. X.br
  1190. X.ne 4
  1191. X.LI "\s-2LINE NUM\s+2"
  1192. XThe line number of the line that called the allocation function.  This 
  1193. Xfield will be left blank if the \fBmalloc.h\fP from this library
  1194. Xwas not included in the source file when it was compiled. 
  1195. X.MP
  1196. X.br
  1197. X.ne 5
  1198. X.LI "\s-2ALLOC FUNC\s+2"
  1199. XThe allocation function called: \fBmalloc\fP, \fBrealloc\fP, or \fBcalloc\fP.
  1200. XThe number in parenthesis following the function name is the call number
  1201. Xfor that particular function.  For example: malloc(1) means that this
  1202. Xallocation was the 1st call to malloc.
  1203. X.MP
  1204. X.br
  1205. X.ne 2
  1206. X.LI "\s-2DATA LEN\s+2"
  1207. XThe number of bytes allocated.
  1208. X.MP
  1209. X.br
  1210. X.ne 6
  1211. X.LI "\s-2HEX DUMP\s+2"
  1212. XA hexidecimal dump of the first seven bytes in the allocated data.  This example
  1213. Xshows the bytes filled with 0x01s which happen to be the fill pattern used
  1214. Xby the malloc library (to make sure that one doesn't depend upon the 
  1215. Xfact that some calls to malloc result in NULL bytes).  So the
  1216. Xallocations that are shown haven't stored any data in the area yet.
  1217. X.LE
  1218. X.MP
  1219. X.br
  1220. X.ne 15
  1221. XIf the environment variable \s-2MALLOC_DETAIL\s+2 is defined, the 
  1222. Xfollowing additional information will be included:
  1223. X.eX
  1224. X************************************************************** Du... 
  1225. X                             FREE     FREE                  ACTUAL SIZE    ...
  1226. X  PTR      NEXT     PREV     NEXT     PREV      FLAGS       INT    HEX     ...
  1227. X-------- -------- -------- -------- -------- ---------- -------- --------- ...
  1228. X0x403C94 0x403CEC 0x40326C 0x000000 0x000000 0x03156111       48(0x000030) ...
  1229. X0x403CEC 0x403D2C 0x403C94 0x000000 0x000000 0x03156121       24(0x000018) ...
  1230. X0x403D2C 0x403D6C 0x403CEC 0x000000 0x403D6C 0x03156120       24(0x000018) ...
  1231. X0x403D6C 0x000000 0x403D2C 0x403D2C 0x000000 0x03156120       24(0x000018) ...
  1232. X
  1233. XMalloc start:      0x40326C
  1234. XMalloc end:        0x403D2C
  1235. XMalloc data start: 0x403C94
  1236. XMalloc data end:   0x405C94
  1237. XMalloc free list:  0x403D6C
  1238. X                -> 0x403D2C
  1239. X.eX
  1240. XNOTE that I cut off the example at the point where the normal output
  1241. Xwould begin (hence the ...).
  1242. X.MP
  1243. XThe info in each column is as follows:
  1244. X.MP
  1245. X.VL 8
  1246. X.LI "\s-2PTR\s+2"
  1247. XThe malloc chain pointer for the segment (the address of the segment).
  1248. X.MP
  1249. X.LI "\s-2NEXT\s+2"
  1250. XThe pointer to the next segment in the chain.
  1251. X.MP
  1252. X.LI "\s-2PREV\s+2"
  1253. XThe pointer to the previous segment in the chain.
  1254. X.MP
  1255. X.LI "\s-2FREE NEXT\s+2"
  1256. XThe pointer to the next segment in the free list.
  1257. X.MP
  1258. X.LI "\s-2FREE PREV\s+2"
  1259. XThe pointer to the previous segment in the free list.
  1260. X.MP
  1261. X.ne 10
  1262. X.LI "\s-2FLAGS\s+2"
  1263. XThe flags associated with this segment.  This is a long
  1264. Xinteger which contains the following fields
  1265. X.MP
  1266. X.VL 6
  1267. X.LI "0xFFFFFF00"
  1268. Xthe magic number.  This should be 0x03156100 (probably 
  1269. Xsomeone's birthday).
  1270. X.MP
  1271. X.LI "0x00000070"
  1272. Xthe type of allocation function. Malloc (x010), realloc (0x20), or
  1273. Xcalloc (0x30) are the only valid values for this field).
  1274. X.MP
  1275. X.LI "0x00000001"
  1276. Xthe in-use flag.  if this value is non-zero, the indicated segment
  1277. Xis currently in use (not freed).
  1278. X.LE
  1279. X.MP
  1280. X.LI "\s-2ACTUAL SIZE\s+2"
  1281. XThe actual size reserved for the allocation in both decimal and
  1282. Xhex.  This will be at least one byte more than the requested size, and
  1283. Xas much as 8, so that we can check to see if the allocation has been
  1284. Xoverrun.
  1285. X.LE
  1286. X.MP
  1287. XMalloc \fBstart\fP and \fBend\fP are pointers to the first and
  1288. Xlast malloc chain segment, respectively.
  1289. X.MP
  1290. XMalloc \fBdata start\fP and \fBdata end\fP are the lowest and highest
  1291. Xdata bytes managed my the malloc sub-system.  These are only used as
  1292. Xa quick check to see if a pointer is in the malloc region before we
  1293. Xgo hunting down the chain trying to identify the segment it belongs to.
  1294. X.MP
  1295. XMalloc \fBfree list\fP is a chain of the elements in the free list (so 
  1296. Xit is easier for the programmer to follow the free list if they choose 
  1297. Xto).  The address of each element in the list follows below the list head.
  1298. X.br
  1299. X.ne 15
  1300. X.SH PERFORMANCE
  1301. XThis malloc library and its associated string and memory functions are
  1302. Xmuch less efficient than the standard functions due in part to the extra
  1303. Xerror checking.  You do not want to use this library when generating a
  1304. Xproduction (i.e. releasable) version of your software.  It should only
  1305. Xbe used during development and testing.
  1306. X.P
  1307. X.ne 10
  1308. XThe following environment variable settings will give you the best
  1309. Xperformance (at the expense of some additional error checking):
  1310. X.eX
  1311. XMALLOC_CKCHAIN=0
  1312. XMALLOC_FILLAREA=0
  1313. XMALLOC_LOWFRAG=0
  1314. X.eX
  1315. XWe strongly recommend against setting MALLOC_FILLAREA to zero because, while
  1316. Xit will increase the performance considerably, it takes away the capability
  1317. Xto uncover small malloc overruns which don't overrite the pointers surrounding
  1318. Xthe malloc regions.
  1319. X.P
  1320. X.ne 5
  1321. XAnyway, with these settings, the malloc library runs at about 1/2 the
  1322. Xspeed (things only take twice as long) as the standard library.  If you program
  1323. Xspends most of its time in malloc, it will still be slow (but perhaps this is
  1324. Xan indication that you need to consider changing the way you are using 
  1325. Xmalloc).
  1326. X.br
  1327. X.ne 15
  1328. X.SH WARNINGS
  1329. XThe include file for this library "malloc.h" should be included after
  1330. Xthe includes for any system related information.  This is because "malloc.h"
  1331. Xredefines several system functions including string and memory routines
  1332. Xand this will usually cause compilation errors if malloc.h is processed
  1333. Xfirst (of course, the compile errors will talk about errors in the other
  1334. Xsystem include files like string.h).
  1335. X.P
  1336. XThere is a possibility that the use of \fBsbrk\fP() by other modules
  1337. Xwill cause this library to get confused and possibly report 
  1338. Xsome pointers as bad when the really aren't part of the malloc chain
  1339. Xitself.  Therefore the direct use of \fBsbrk\fP() is strongly discouraged.
  1340. X.P
  1341. XThis library attempts to trap errors and exit/handle them gracefully.  
  1342. XHowever, the nature of the problems may be such that it causes the 
  1343. Xcode in the library itself to crash.  There is no way to avoid this,
  1344. Xbut if it does occur,  turn on chain checking to narrow the place where
  1345. Xit will occur.
  1346. X.P
  1347. XThe functions in this library will often conflict with duplicate functions
  1348. Xin shared library versions of libc.a.  This is usually due to the 
  1349. Xfact that some shared library modules have explicit references to shared
  1350. Xlibrary versions of the debug functions.  The only way around this is
  1351. Xto not use the shared library when linking.
  1352. X.P
  1353. XThis malloc library, like most malloc libraries, is not re-entrant 
  1354. Xand therefore should not be called from interrupt handlers because of the
  1355. Xpotential for receiving an interrupt in the middle of a call to malloc
  1356. Xwhich would really mess things up.
  1357. X.SH SEE ALSO
  1358. Xmalloc(3)
  1359. X.SH AUTHOR
  1360. X.nf
  1361. XConor P. Cahill
  1362. XVirtual Technologies Incorporated
  1363. X46030 Manekin Plaza, Suite 160
  1364. XSterling VA 22170
  1365. X703-430-9247
  1366. X.MP
  1367. Xuunet!virtech!cpcahil
  1368. END_OF_FILE
  1369. if test 27763 -ne `wc -c <'malloc.3'`; then
  1370.     echo shar: \"'malloc.3'\" unpacked with wrong size!
  1371. fi
  1372. # end of 'malloc.3'
  1373. fi
  1374. if test -f 'malloc.h' -a "${1}" != "-c" ; then 
  1375.   echo shar: Will not clobber existing file \"'malloc.h'\"
  1376. else
  1377. echo shar: Extracting \"'malloc.h'\" \(13852 characters\)
  1378. sed "s/^X//" >'malloc.h' <<'END_OF_FILE'
  1379. X/*
  1380. X * (c) Copyright 1990, 1991 Conor P. Cahill (uunet!virtech!cpcahil).  
  1381. X * You may copy, distribute, and use this software as long as this
  1382. X * copyright statement is not removed.
  1383. X */
  1384. X/*
  1385. X * $Id: malloc.h,v 1.20 1992/01/28 21:42:25 cpcahil Exp $
  1386. X */
  1387. X
  1388. X#ifndef _DEBUG_MALLOC_INC
  1389. X#define _DEBUG_MALLOC_INC 1
  1390. X
  1391. X/*
  1392. X * The following lines will probably need to be changed depending
  1393. X * upon the OS to which this library is ported.  Typically, older BSD
  1394. X * systems will need:
  1395. X *
  1396. X *        typedef char    DATATYPE;
  1397. X *        typedef int    SIZETYPE;
  1398. X *        typedef int    VOIDTYPE;
  1399. X *
  1400. X * System V style systems with compilers that understand void will usually
  1401. X * use:
  1402. X *
  1403. X *        typedef char    DATATYPE;
  1404. X *        typedef int    SIZETYPE;
  1405. X *        typedef void    VOIDTYPE;
  1406. X *
  1407. X * ANSI-C and/or c++ compilers will usually use:
  1408. X *
  1409. X *        typedef void    DATATYPE;
  1410. X *        typedef int    SIZETYPE;
  1411. X *        typedef void    VOIDTYPE;
  1412. X *
  1413. X * (Note: while the library can be linked with c++ modules, it itself 
  1414. X *  cannot be compiled with c++ - yet.  This header file has been modified
  1415. X *  so that it can be included by C++ modules that use malloc)
  1416. X * 
  1417. X * And some other systems will require sizetype to be one of the following:
  1418. X * 
  1419. X *         typedef unsigned int    SIZETYPE;
  1420. X * or
  1421. X *
  1422. X *        typedef size_t        SIZETYPE;
  1423. X *
  1424. X * Because I am lazy, I have setup #ifdefs for the few systems that I normally
  1425. X * test the library on (so if you are on one of these systems, you are lucky
  1426. X * and don't have to worry about changing it - hopefully)
  1427. X * 
  1428. X * NOTE: for those of you who are wondering why I dont just use a command line
  1429. X * option on the compiler (set via the makefile) to determint these settings:
  1430. X * the reason is that this file must be able to be included in existing 
  1431. X * software modules with no changes to the code and with as little changes
  1432. X * as possible to the command line.  It is easier to edit this file once, when
  1433. X * you install the system, than have to specify three -Ds on each compile 
  1434. X * when it is used.
  1435. X *
  1436. X * NOTE2: if void is not supported, then you also need to disable or remove
  1437. X * the VOIDCAST #define
  1438. X */
  1439. X
  1440. X#if __hpux    /* HP/UX (at least 8.0 and above) */
  1441. X        typedef    void    DATATYPE;
  1442. X        typedef size_t    SIZETYPE;
  1443. X        typedef void    VOIDTYPE;
  1444. X#else
  1445. X#if i386
  1446. X#if __STDC__ || __cplusplus
  1447. X        typedef void        DATATYPE;
  1448. X        typedef unsigned int    SIZETYPE;
  1449. X        typedef void        VOIDTYPE;
  1450. X#else
  1451. X        typedef char        DATATYPE;
  1452. X        typedef int        SIZETYPE;
  1453. X        typedef void        VOIDTYPE;
  1454. X#endif /* __STDC__ */
  1455. X#else  /* i386     */
  1456. X#if _IBMR2
  1457. X        typedef void        DATATYPE;
  1458. X        typedef unsigned long    SIZETYPE;
  1459. X        typedef void        VOIDTYPE;
  1460. X#else  /* _IBMR2   */
  1461. X    "you need to define entries here"
  1462. X#endif /* _IBMR2   */
  1463. X#endif /* i386     */
  1464. X#endif /* __hpux   */
  1465. X
  1466. X/*
  1467. X * Comment out the following line if your compiler doesn't support the VOID
  1468. X * data type.
  1469. X */
  1470. X#define VOIDCAST (void)
  1471. X
  1472. X/*
  1473. X * since we redefine much of the stuff that is #defined in string.h and 
  1474. X * memory.h, we should do what we can to make sure that they don't get 
  1475. X * included after us.  This is typically accomplished by a special symbol
  1476. X * (similar to _DEBUG_MALLOC_INC defined above) that is #defined when the
  1477. X * file is included.  Since we don't want the file to be included we will
  1478. X * #define the symbol ourselves.  These will typically have to change from
  1479. X * one system to another.  I have put in several standard mechanisms used to
  1480. X * support this mechanism, so hopefully you won't have to modify this file.
  1481. X */
  1482. X#ifndef _H_STRING
  1483. X#define _H_STRING        1
  1484. X#endif 
  1485. X#ifndef __STRING_H
  1486. X#define __STRING_H        1
  1487. X#endif 
  1488. X#ifndef _STRING_H_
  1489. X#define _STRING_H_        1
  1490. X#endif 
  1491. X#ifndef _STRING_INCLUDED
  1492. X#define _STRING_INCLUDED    1
  1493. X#endif
  1494. X#ifndef _H_MEMORY
  1495. X#define _H_MEMORY        1
  1496. X#endif
  1497. X#ifndef __MEMORY_H
  1498. X#define __MEMORY_H        1
  1499. X#endif
  1500. X#ifndef _MEMORY_H_
  1501. X#define _MEMORY_H_        1
  1502. X#endif
  1503. X#ifndef _MEMORY_INCLUDED
  1504. X#define _MEMORY_INCLUDED    1
  1505. X#endif
  1506. X
  1507. X/*
  1508. X * Malloc warning/fatal error handler defines...
  1509. X */
  1510. X#define M_HANDLE_DUMP    0x80  /* 128 */
  1511. X#define M_HANDLE_IGNORE    0
  1512. X#define M_HANDLE_ABORT    1
  1513. X#define M_HANDLE_EXIT    2
  1514. X#define M_HANDLE_CORE    3
  1515. X    
  1516. X/*
  1517. X * Mallopt commands and defaults
  1518. X *
  1519. X * the first four settings are ignored by the debugging mallopt, but are
  1520. X * here to maintain compatibility with the system malloc.h.
  1521. X */
  1522. X#define M_MXFAST    1        /* ignored by mallopt        */
  1523. X#define M_NLBLKS    2        /* ignored by mallopt        */
  1524. X#define M_GRAIN        3        /* ignored by mallopt        */
  1525. X#define M_KEEP        4        /* ignored by mallopt        */
  1526. X#define MALLOC_WARN    100        /* set malloc warning handling    */
  1527. X#define MALLOC_FATAL    101        /* set malloc fatal handling    */
  1528. X#define MALLOC_ERRFILE    102        /* specify malloc error file    */
  1529. X#define MALLOC_CKCHAIN    103        /* turn on chain checking    */
  1530. X#define MALLOC_FILLAREA    104        /* turn off area filling    */
  1531. X#define MALLOC_LOWFRAG    105        /* use best fit allocation mech    */
  1532. X
  1533. Xunion malloptarg
  1534. X{
  1535. X    int      i;
  1536. X    char    * str;
  1537. X};
  1538. X
  1539. X/*
  1540. X * Malloc warning/fatal error codes
  1541. X */
  1542. X
  1543. X#define M_CODE_CHAIN_BROKE    1    /* malloc chain is broken    */
  1544. X#define M_CODE_NO_END        2    /* chain end != endptr        */
  1545. X#define M_CODE_BAD_PTR        3    /* pointer not in malloc area    */
  1546. X#define M_CODE_BAD_MAGIC    4    /* bad magic number in header    */
  1547. X#define M_CODE_BAD_CONNECT    5    /* chain poingers corrupt    */
  1548. X#define M_CODE_OVERRUN        6    /* data overrun in malloc seg    */
  1549. X#define M_CODE_REUSE        7    /* reuse of freed area        */
  1550. X#define M_CODE_NOT_INUSE    8    /* pointer is not in use    */
  1551. X#define M_CODE_NOMORE_MEM    9    /* no more memory available    */
  1552. X#define M_CODE_OUTOF_BOUNDS    10    /* gone beyound bounds         */
  1553. X#define M_CODE_FREELIST_BAD    11    /* inuse segment on freelist    */
  1554. X
  1555. X#ifndef __stdcargs
  1556. X#if  __STDC__ || __cplusplus
  1557. X#define __stdcargs(a) a
  1558. X#else
  1559. X#define __stdcargs(a) ()
  1560. X#endif
  1561. X#endif
  1562. X
  1563. X#if __cplusplus
  1564. Xextern "C" {
  1565. X#endif
  1566. X
  1567. XVOIDTYPE      malloc_dump __stdcargs((int));
  1568. XVOIDTYPE      malloc_list __stdcargs((int,unsigned long, unsigned long));
  1569. Xint          mallopt __stdcargs((int, union malloptarg));
  1570. XDATATYPE    * debug_calloc __stdcargs((const char *,int,SIZETYPE,SIZETYPE));
  1571. XVOIDTYPE      debug_cfree __stdcargs((const char *, int, DATATYPE *));
  1572. XVOIDTYPE      debug_free __stdcargs((const char *, int, DATATYPE *));
  1573. XDATATYPE    * debug_malloc __stdcargs((const char *,int, SIZETYPE));
  1574. XDATATYPE    * debug_realloc __stdcargs((const char *,int,
  1575. X                        DATATYPE *,SIZETYPE));
  1576. Xunsigned long      DBmalloc_size __stdcargs((const char *,int,unsigned long *));
  1577. Xint          DBmalloc_chain_check __stdcargs((const char *,int,int));
  1578. X
  1579. X/*
  1580. X * memory(3) related prototypes
  1581. X */
  1582. XDATATYPE     * DBmemccpy __stdcargs((const char *file, int line,
  1583. X                    DATATYPE *ptr1, const DATATYPE *ptr2,
  1584. X                    int ch, SIZETYPE len));
  1585. XDATATYPE     * DBmemchr __stdcargs((const char *file, int line,
  1586. X                    const DATATYPE *ptr1, int ch,
  1587. X                    SIZETYPE len));
  1588. XDATATYPE    * DBmemmove __stdcargs((const char *file, int line,
  1589. X                    DATATYPE *ptr1, const DATATYPE *ptr2,
  1590. X                    SIZETYPE len));
  1591. XDATATYPE    * DBmemcpy __stdcargs((const char *file, int line,
  1592. X                    DATATYPE *ptr1, const DATATYPE *ptr2,
  1593. X                    SIZETYPE len));
  1594. Xint          DBmemcmp __stdcargs((const char *file, int line,
  1595. X                    const DATATYPE *ptr1,
  1596. X                    const DATATYPE *ptr2, SIZETYPE len));
  1597. XDATATYPE    * DBmemset __stdcargs((const char *file, int line,
  1598. X                    DATATYPE *ptr1, int ch, SIZETYPE len));
  1599. XDATATYPE    * DBbcopy __stdcargs((const char *file, int line,
  1600. X                    const DATATYPE *ptr2, DATATYPE *ptr1,
  1601. X                    SIZETYPE len));
  1602. XDATATYPE     * DBbzero __stdcargs((const char *file, int line,
  1603. X                    DATATYPE *ptr1, SIZETYPE len));
  1604. Xint          DBbcmp __stdcargs((const char *file, int line,
  1605. X                    const DATATYPE *ptr2,
  1606. X                    const DATATYPE *ptr1, SIZETYPE len));
  1607. X
  1608. X/*
  1609. X * string(3) related prototypes
  1610. X */
  1611. Xchar        * DBstrcat __stdcargs((const char *file,int line, char *str1,
  1612. X                    const char *str2));
  1613. Xchar        * DBstrdup __stdcargs((const char *file, int line,
  1614. X                    const char *str1));
  1615. Xchar        * DBstrncat __stdcargs((const char *file, int line, char *str1,
  1616. X                    const char *str2, SIZETYPE len));
  1617. Xint          DBstrcmp __stdcargs((const char *file, int line,
  1618. X                    const char *str1, const char *str2));
  1619. Xint          DBstrncmp __stdcargs((const char *file, int line,
  1620. X                    const char *str1, const char *str2,
  1621. X                    SIZETYPE len));
  1622. Xchar        * DBstrcpy __stdcargs((const char *file, int line, char *str1,
  1623. X                    const char *str2));
  1624. Xchar        * DBstrncpy __stdcargs((const char *file, int line, char *str1,
  1625. X                    const char *str2, SIZETYPE len));
  1626. XSIZETYPE      DBstrlen __stdcargs((const char *file, int line,
  1627. X                    const char *str1));
  1628. Xchar        * DBstrchr __stdcargs((const char *file, int line,
  1629. X                    const char *str1, int c));
  1630. Xchar        * DBstrrchr __stdcargs((const char *file, int line,
  1631. X                    const char *str1, int c));
  1632. Xchar        * DBindex __stdcargs((const char *file, int line,
  1633. X                    const char *str1, int c));
  1634. Xchar        * DBrindex __stdcargs((const char *file, int line,
  1635. X                    const char *str1, int c));
  1636. Xchar        * DBstrpbrk __stdcargs((const char *file, int line,
  1637. X                    const char *str1, const char *str2));
  1638. XSIZETYPE      DBstrspn __stdcargs((const char *file, int line,
  1639. X                    const char *str1, const char *str2));
  1640. XSIZETYPE      DBstrcspn __stdcargs((const char *file, int line,
  1641. X                    const char *str1, const char *str2));
  1642. Xchar        * DBstrstr __stdcargs((const char *file, int line,
  1643. X                    const char *str1, const char *str2));
  1644. Xchar        * DBstrtok __stdcargs((const char *file, int line, char *str1,
  1645. X                    const char *str2));
  1646. X
  1647. X#if __cplusplus
  1648. X};
  1649. X#endif
  1650. X
  1651. X/*
  1652. X * Macro which enables logging of the file and line number for each allocation
  1653. X * so that it is easier to determine where the offending malloc comes from.
  1654. X *
  1655. X * NOTE that only code re-compiled with this include file will have this 
  1656. X * additional info.  Calls from libraries that have not been recompiled will
  1657. X * just have a null string for this info.
  1658. X */
  1659. X#ifndef IN_MALLOC_CODE
  1660. X
  1661. X/*
  1662. X * allocation functions
  1663. X */
  1664. X#define malloc(len)        debug_malloc( __FILE__,__LINE__, (len))
  1665. X#define realloc(ptr,len)    debug_realloc(__FILE__,__LINE__, (ptr), (len))
  1666. X#define calloc(numelem,size)    debug_calloc(__FILE__,__LINE__,(numelem),(size))
  1667. X#define cfree(ptr)        debug_cfree(__FILE__,__LINE__,(ptr))
  1668. X#define free(ptr)        debug_free(__FILE__,__LINE__,(ptr))
  1669. X#define malloc_size(histptr)    DBmalloc_size(__FILE__,__LINE__,(histptr))
  1670. X#define malloc_chain_check(todo) DBmalloc_chain_check(__FILE__,__LINE__,(todo))
  1671. X
  1672. X/*
  1673. X * memory(3) related functions
  1674. X */
  1675. X#define memccpy(ptr1,ptr2,ch,len) DBmemccpy(__FILE__,__LINE__,ptr1,ptr2,ch,len)
  1676. X#define memchr(ptr1,ch,len)      DBmemchr(__FILE__,__LINE__,ptr1,ch,len)
  1677. X#define memmove(ptr1,ptr2,len)    DBmemmove(__FILE__,__LINE__,ptr1, ptr2, len)
  1678. X#define memcpy(ptr1,ptr2,len)     DBmemcpy(__FILE__, __LINE__, ptr1, ptr2, len)
  1679. X#define memcmp(ptr1,ptr2,len)     DBmemcmp(__FILE__,__LINE__,ptr1, ptr2, len)
  1680. X#define memset(ptr1,ch,len)       DBmemset(__FILE__,__LINE__,ptr1, ch, len)
  1681. X#define bcopy(ptr2,ptr1,len)      DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len)
  1682. X#define bzero(ptr1,len)           DBbzero(__FILE__,__LINE__,ptr1,len)
  1683. X#define bcmp(ptr2,ptr1,len)       DBbcmp(__FILE__, __LINE__, ptr2, ptr1, len)
  1684. X
  1685. X/*
  1686. X * string(3) related functions
  1687. X */
  1688. X#define index(str1,c)          DBindex(__FILE__, __LINE__, str1, c)
  1689. X#define rindex(str1,c)          DBrindex(__FILE__, __LINE__, str1, c)
  1690. X#define strcat(str1,str2)      DBstrcat(__FILE__,__LINE__,str1,str2)
  1691. X#define strchr(str1,c)          DBstrchr(__FILE__, __LINE__, str1,c)
  1692. X#define strcmp(str1,str2)      DBstrcmp(__FILE__, __LINE__, str1, str2)
  1693. X#define strcpy(str1,str2)      DBstrcpy(__FILE__, __LINE__, str1, str2)
  1694. X#define strcspn(str1,str2)      DBstrcspn(__FILE__, __LINE__, str1,str2)
  1695. X#define strdup(str1)          DBstrdup(__FILE__, __LINE__, str1)
  1696. X#define strlen(str1)          DBstrlen(__FILE__, __LINE__, str1)
  1697. X#define strncat(str1,str2,len)      DBstrncat(__FILE__, __LINE__, str1,str2,len)
  1698. X#define strncpy(str1,str2,len)      DBstrncpy(__FILE__,__LINE__,str1,str2,len)
  1699. X#define strncmp(str1,str2,len)      DBstrncmp(__FILE__, __LINE__, str1,str2,len)
  1700. X#define strpbrk(str1,str2)      DBstrpbrk(__FILE__, __LINE__, str1,str2)
  1701. X#define strrchr(str1,c)          DBstrrchr(__FILE__,__LINE__,str1,c)
  1702. X#define strspn(str1,str2)      DBstrspn(__FILE__, __LINE__, str1,str2)
  1703. X#define strstr(str1,str2)      DBstrstr(__FILE__, __LINE__, str1, str2)
  1704. X#define strtok(str1,str2)      DBstrtok(__FILE__, __LINE__, str1, str2)
  1705. X
  1706. X#endif
  1707. X
  1708. X#endif /* _DEBUG_MALLOC_INC */
  1709. X
  1710. X/*
  1711. X * $Log: malloc.h,v $
  1712. X * Revision 1.20  1992/01/28  21:42:25  cpcahil
  1713. X * changes for the ibmRS6000
  1714. X *
  1715. X * Revision 1.19  1992/01/28  18:05:37  cpcahil
  1716. X * misc fixes for patch 7
  1717. X *
  1718. X * Revision 1.18  1992/01/22  16:21:35  cpcahil
  1719. X * added code to prevent inclusions of string.h and memory.h after malloc.h
  1720. X * was included.
  1721. X *
  1722. X * Revision 1.17  1992/01/10  17:26:46  cpcahil
  1723. X * fixed prototypes use of void.
  1724. X *
  1725. X * Revision 1.16  1992/01/10  16:53:39  cpcahil
  1726. X * added more info on sizetype and datatype. added support for overriding
  1727. X * use of void type.
  1728. X *
  1729. X * Revision 1.15  1992/01/09  17:19:11  cpcahil
  1730. X * put the close brace in the correct position.
  1731. X *
  1732. X * Revision 1.14  1992/01/09  17:12:36  cpcahil
  1733. X * added code to support inclusion in C++ modules
  1734. X *
  1735. X * Revision 1.13  1991/12/31  21:31:26  cpcahil
  1736. X * changes for patch 6.  See CHANGES file for more info
  1737. X *
  1738. X * Revision 1.12  1991/12/26  22:31:29  cpcahil
  1739. X * added check to make sure file is not included twice.
  1740. X *
  1741. X * Revision 1.11  1991/12/06  17:58:46  cpcahil
  1742. X * added cfree() for compatibility with some wierd systems
  1743. X *
  1744. X * Revision 1.10  91/12/06  08:54:18  cpcahil
  1745. X * cleanup of __STDC__ usage and addition of CHANGES file
  1746. X * 
  1747. X * Revision 1.9  91/12/04  09:23:40  cpcahil
  1748. X * several performance enhancements including addition of free list
  1749. X * 
  1750. X * Revision 1.8  91/12/02  19:10:11  cpcahil
  1751. X * changes for patch release 5
  1752. X * 
  1753. X * Revision 1.7  91/11/25  14:42:00  cpcahil
  1754. X * Final changes in preparation for patch 4 release
  1755. X * 
  1756. X * Revision 1.6  91/11/24  00:49:28  cpcahil
  1757. X * first cut at patch 4
  1758. X * 
  1759. X * Revision 1.5  91/11/20  11:54:10  cpcahil
  1760. X * interim checkin
  1761. X * 
  1762. X * Revision 1.4  90/08/29  22:23:38  cpcahil
  1763. X * fixed mallopt to use a union as an argument.
  1764. X * 
  1765. X * Revision 1.3  90/05/11  11:04:10  cpcahil
  1766. X * took out some extraneous lines
  1767. X * 
  1768. X * Revision 1.2  90/05/11  00:13:09  cpcahil
  1769. X * added copyright statment
  1770. X * 
  1771. X * Revision 1.1  90/02/23  07:09:03  cpcahil
  1772. X * Initial revision
  1773. X * 
  1774. X */
  1775. END_OF_FILE
  1776. if test 13852 -ne `wc -c <'malloc.h'`; then
  1777.     echo shar: \"'malloc.h'\" unpacked with wrong size!
  1778. fi
  1779. # end of 'malloc.h'
  1780. fi
  1781. echo shar: End of archive 2 \(of 5\).
  1782. cp /dev/null ark2isdone
  1783. MISSING=""
  1784. for I in 1 2 3 4 5 ; do
  1785.     if test ! -f ark${I}isdone ; then
  1786.     MISSING="${MISSING} ${I}"
  1787.     fi
  1788. done
  1789. if test "${MISSING}" = "" ; then
  1790.     echo You have unpacked all 5 archives.
  1791.     rm -f ark[1-9]isdone
  1792. else
  1793.     echo You still need to unpack the following archives:
  1794.     echo "        " ${MISSING}
  1795. fi
  1796. ##  End of shell archive.
  1797. exit 0
  1798.  
  1799. exit 0 # Just in case...
  1800.