Changeset 953
- Timestamp:
- 06/17/07 23:01:43 (1 year ago)
- Files:
-
- 1.8.2/branches/devel/hdrs/csrimalloc.h (modified) (2 diffs)
- 1.8.2/branches/devel/src/csrimalloc.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.2/branches/devel/hdrs/csrimalloc.h
r932 r953 22 22 /* Tracing malloc definitions - helps find leaks */ 23 23 24 extern univptr_t trace__malloc 25 _((size_t nbytes, const char *fname, int linenum)); 26 extern univptr_t trace__calloc 27 _((size_t nelem, size_t elsize, const char *fname, int linenum)); 28 extern univptr_t trace__realloc 29 _((univptr_t cp, size_t nbytes, const char *fname, int linenum)); 30 extern univptr_t trace__valloc _((size_t size, const char *fname, int linenum)); 31 extern univptr_t trace__memalign 32 _((size_t alignment, size_t size, const char *fname, int linenum)); 33 extern univptr_t trace__emalloc 34 _((size_t nbytes, const char *fname, int linenum)); 35 extern univptr_t trace__ecalloc 36 _((size_t nelem, size_t sz, const char *fname, int linenum)); 37 extern univptr_t trace__erealloc 38 _((univptr_t ptr, size_t nbytes, const char *fname, int linenum)); 39 extern char *trace__strdup _((const char *s, const char *fname, int linenum)); 40 extern char *trace__strsave _((const char *s, const char *fname, int linenum)); 41 extern void trace__free _((univptr_t cp, const char *fname, int linenum)); 42 extern void trace__cfree _((univptr_t cp, const char *fname, int linenum)); 24 univptr_t trace__malloc(size_t nbytes, const char *fname, int linenum); 25 univptr_t trace__calloc 26 (size_t nelem, size_t elsize, const char *fname, int linenum); 27 univptr_t trace__realloc 28 (univptr_t cp, size_t nbytes, const char *fname, int linenum); 29 univptr_t trace__valloc(size_t size, const char *fname, int linenum); 30 univptr_t trace__memalign 31 (size_t alignment, size_t size, const char *fname, int linenum); 32 univptr_t trace__emalloc(size_t nbytes, const char *fname, int linenum); 33 univptr_t trace__ecalloc 34 (size_t nelem, size_t sz, const char *fname, int linenum); 35 univptr_t trace__erealloc 36 (univptr_t ptr, size_t nbytes, const char *fname, int linenum); 37 char *trace__strdup(const char *s, const char *fname, int linenum); 38 char *trace__strsave(const char *s, const char *fname, int linenum); 39 void trace__free(univptr_t cp, const char *fname, int linenum); 40 void trace__cfree(univptr_t cp, const char *fname, int linenum); 43 41 44 42 #define malloc(x) trace__malloc((x), __FILE__, __LINE__) … … 58 56 #else /* CSRI_TRACE */ 59 57 60 extern univptr_t malloc _((size_t nbytes));61 extern univptr_t calloc _((size_t nelem, size_t elsize));62 extern univptr_t realloc _((univptr_t cp, size_t nbytes));63 extern univptr_t valloc _((size_t size));64 extern univptr_t memalign _((size_t alignment, size_t size));65 extern univptr_t emalloc _((size_t nbytes));66 extern univptr_t ecalloc _((size_t nelem, size_t sz));67 extern univptr_t erealloc _((univptr_t ptr, size_t nbytes));68 extern char *strdup _((const char *s));69 extern char *strsave _((const char *s));70 extern Free_t free _((univptr_t cp));71 extern Free_t cfree _((univptr_t cp));58 univptr_t malloc(size_t nbytes); 59 univptr_t calloc(size_t nelem, size_t elsize); 60 univptr_t realloc(univptr_t cp, size_t nbytes); 61 univptr_t valloc(size_t size); 62 univptr_t memalign(size_t alignment, size_t size); 63 univptr_t emalloc(size_t nbytes); 64 univptr_t ecalloc(size_t nelem, size_t sz); 65 univptr_t erealloc(univptr_t ptr, size_t nbytes); 66 char *strdup(const char *s); 67 char *strsave(const char *s); 68 void free(univptr_t cp); 69 void cfree(univptr_t cp); 72 70 73 71 #endif /* CSRI_TRACE */ 74 72 75 extern void mal_debug _((int level));76 extern void mal_dumpleaktrace _((FILE * fp));77 extern void mal_heapdump _((FILE * fp));78 extern void mal_leaktrace _((int value));79 extern void mal_sbrkset _((int n));80 extern void mal_slopset _((int n));81 extern void mal_statsdump _((FILE * fp));82 extern void mal_setstatsfile _((FILE * fp));83 extern void mal_trace _((int value));84 extern int mal_verify _((int fullcheck));85 extern void mal_mmap _((char *fname));73 void mal_debug(int level); 74 void mal_dumpleaktrace(FILE * fp); 75 void mal_heapdump(FILE * fp); 76 void mal_leaktrace(int value); 77 void mal_sbrkset(int n); 78 void mal_slopset(int n); 79 void mal_statsdump(FILE * fp); 80 void mal_setstatsfile(FILE * fp); 81 void mal_trace(int value); 82 int mal_verify(int fullcheck); 83 void mal_mmap(char *fname); 86 84 87 85 1.8.2/branches/devel/src/csrimalloc.c
r932 r953 38 38 #undef cfree(p) 39 39 #undef free(p) 40 extern char *strdup _((const char *));40 extern char *strdup(const char *); 41 41 #endif 42 42 … … 112 112 /* Character Handling: <string.h> */ 113 113 114 #if 0 115 /* We'd better not have to do this - Javelin */ 116 114 117 #ifndef HAS_MEMSET 115 118 extern univptr_t memset proto((univptr_t, int, memsize_t)); … … 120 123 #endif 121 124 122 #if 0123 /* We'd better not have to do this - Javelin */124 125 extern char *strcpy proto((char *, const char *)); 125 126 extern memsize_t strlen proto((const char *)); … … 785 786 #endif /* CSRI_DEBUG */ 786 787 787 univptr_t (*_malloc_memfunc) proto((size_t)) = _mal_sbrk;788 univptr_t(*_malloc_memfunc) proto((size_t)) = _mal_sbrk; 788 789 789 790 #ifndef __GLOBALS_H__ … … 794 795 */ 795 796 796 extern 797 size_t _malloc_minchunk; 798 799 extern Word *_malloc_rovers[]; 800 extern const 801 size_t _malloc_binmax[]; 802 extern int 803 _malloc_firstbin; 804 extern int 805 _malloc_lastbin; 806 extern Word *_malloc_hiword; 807 extern Word *_malloc_loword; 808 809 extern 810 size_t _malloc_sbrkunits; 811 812 extern Word *_malloc_mem; 813 814 extern int 815 _malloc_tracing; /* No tracing */ 816 extern char 817 _malloc_statsbuf[]; 818 819 extern int 820 _malloc_leaktrace; 797 extern 798 size_t 799 _malloc_minchunk; 800 801 extern Word * 802 _malloc_rovers[]; 803 extern const 804 size_t 805 _malloc_binmax[]; 806 extern int 807 _malloc_firstbin; 808 extern int 809 _malloc_lastbin; 810 extern Word * 811 _malloc_hiword; 812 extern Word * 813 _malloc_loword; 814 815 extern 816 size_t 817 _malloc_sbrkunits; 818 819 extern Word * 820 _malloc_mem; 821 822 extern int 823 _malloc_tracing; /* No tracing */ 824 extern char 825 _malloc_statsbuf[]; 826 827 extern int 828 _malloc_leaktrace; 821 829 822 830 #ifdef CSRI_PROFILESIZES 823 extern int824 _malloc_scount[];831 extern int 832 _malloc_scount[]; 825 833 #endif /* CSRI_PROFILESIZES */ 826 834 … … 831 839 * malloc/free/realloc/memalign. (the rest call these) 832 840 */ 833 extern int834 _malloc_debugging;841 extern int 842 _malloc_debugging; 835 843 #endif /* CSRI_DEBUG */ 836 844 837 extern 838 univptr_t (*_malloc_memfunc) proto((size_t)); 839 840 extern int 841 __m_prblock proto((univptr_t, int, FILE *)); 845 extern 846 univptr_t(*_malloc_memfunc) 847 proto((size_t)); 848 849 extern int 850 __m_prblock 851 proto((univptr_t, int, FILE *)); 842 852 843 853 #endif /* __GLOBALS_H__ */ /* Do not add anything after this line */ … … 857 867 #define SPTREE_H 858 868 859 typedef struct _spblk { 860 struct _spblk *leftlink; 861 struct _spblk *rightlink; 862 struct _spblk *uplink; 863 864 univptr_t 865 key; /* formerly time/timetyp */ 866 univptr_t 867 data; /* formerly aux/auxtype */ 868 univptr_t 869 datb; 870 } SPBLK; 871 872 typedef struct { 873 SPBLK *root; /* root node */ 874 875 /* Statistics, not strictly necessary, but handy for tuning */ 876 877 int 878 lookups; /* number of splookup()s */ 879 int 880 lkpcmps; /* number of lookup comparisons */ 881 882 int 883 enqs; /* number of spenq()s */ 884 int 885 enqcmps; /* compares in spenq */ 886 887 int 888 splays; 889 int 890 splayloops; 891 892 } SPTREE; 869 typedef struct _spblk { 870 struct _spblk * 871 leftlink; 872 struct _spblk * 873 rightlink; 874 struct _spblk * 875 uplink; 876 877 univptr_t 878 key; /* formerly time/timetyp */ 879 univptr_t 880 data; /* formerly aux/auxtype */ 881 univptr_t 882 datb; 883 } SPBLK; 884 885 typedef struct { 886 SPBLK * 887 root; /* root node */ 888 889 /* Statistics, not strictly necessary, but handy for tuning */ 890 891 int 892 lookups; /* number of splookup()s */ 893 int 894 lkpcmps; /* number of lookup comparisons */ 895 896 int 897 enqs; /* number of spenq()s */ 898 int 899 enqcmps; /* compares in spenq */ 900 901 int 902 splays; 903 int 904 splayloops; 905 906 } SPTREE; 893 907 894 908 #if defined(__STDC__) … … 900 914 /* sptree.c */ 901 915 /* init tree */ 902 extern SPTREE *__spinit __proto((void)); 916 extern SPTREE * 917 __spinit 918 __proto((void)); 903 919 /* find key in a tree */ 904 extern SPBLK *__splookup __proto((univptr_t, SPTREE *)); 920 extern SPBLK * 921 __splookup 922 __proto((univptr_t, SPTREE *)); 905 923 /* enter an item, allocating or replacing */ 906 extern SPBLK *__spadd __proto((univptr_t, univptr_t, univptr_t, SPTREE *)); 924 extern SPBLK * 925 __spadd 926 __proto((univptr_t, univptr_t, univptr_t, SPTREE *)); 907 927 /* scan forward through tree */ 908 extern void 909 __spscan __proto((void (*)__proto((SPBLK *)), SPBLK *, SPTREE *)); 928 extern void 929 __spscan 930 __proto((void (*)__proto((SPBLK *)), SPBLK *, SPTREE *)); 910 931 /* return tree statistics */ 911 extern char *__spstats __proto((SPTREE *)); 932 extern char * 933 __spstats 934 __proto((SPTREE *)); 912 935 /* delete node from tree */ 913 extern void 914 __spdelete __proto((SPBLK *, SPTREE *)); 936 extern void 937 __spdelete 938 __proto((SPBLK *, SPTREE *)); 915 939 916 940 #undef __proto … … 920 944 #ifndef __CSRI_TRACE_H__ 921 945 #define __CSRI_TRACE_H__ 922 extern void 923 __m_install_record proto((univptr_t, const char *)); 924 extern void 925 __m_delete_record proto((univptr_t)); 946 extern void 947 __m_install_record 948 proto((univptr_t, const char *)); 949 extern void 950 __m_delete_record 951 proto((univptr_t)); 926 952 927 953 #define RECORD_FILE_AND_LINE(addr, fname, linenum) \ … … 944 970 #ifdef CSRI_TRACE 945 971 /* Tracing malloc definitions - helps find leaks */ 972 univptr_t 973 trace__malloc(size_t nbytes, const char *fname, int linenum); 974 univptr_t 975 trace__calloc(size_t nelem, size_t elsize, const char *fname, int linenum); 976 univptr_t 977 trace__realloc(univptr_t cp, size_t nbytes, const char *fname, int linenum); 978 univptr_t 979 trace__valloc(size_t size, const char *fname, int linenum); 980 univptr_t 981 trace__memalign 982 (size_t alignment, size_t size, const char *fname, int linenum); 983 univptr_t 984 trace__emalloc(size_t nbytes, const char *fname, int linenum); 946 985 univptr_t 947 trace__ malloc _((size_t nbytes, const char *fname, int linenum));986 trace__ecalloc(size_t nelem, size_t sz, const char *fname, int linenum); 948 987 univptr_t 949 trace__calloc _((size_t nelem, size_t elsize, const char *fname, int linenum)); 950 univptr_t 951 trace__realloc _((univptr_t cp, size_t nbytes, const char *fname, int linenum)); 952 univptr_t trace__valloc _((size_t size, const char *fname, int linenum)); 953 univptr_t 954 trace__memalign 955 _((size_t alignment, size_t size, const char *fname, int linenum)); 956 univptr_t trace__emalloc _((size_t nbytes, const char *fname, int linenum)); 957 univptr_t 958 trace__ecalloc _((size_t nelem, size_t sz, const char *fname, int linenum)); 959 univptr_t 960 trace__erealloc 961 _((univptr_t ptr, size_t nbytes, const char *fname, int linenum)); 962 char *trace__strdup _((const char *s, const char *fname, int linenum)); 963 char *trace__strsave _((const char *s, const char *fname, int linenum)); 964 void 965 trace__free _((univptr_t cp, const char *fname, int linenum)); 966 void 967 trace__cfree _((univptr_t cp, const char *fname, int linenum)); 988 trace__erealloc(univptr_t ptr, size_t nbytes, const char *fname, int linenum); 989 char *trace__strdup(const char *s, const char *fname, int linenum); 990 char *trace__strsave(const char *s, const char *fname, int linenum); 991 void 992 trace__free(univptr_t cp, const char *fname, int linenum); 993 void 994 trace__cfree(univptr_t cp, const char *fname, int linenum); 968 995 #else /* CSRI_TRACE */ 969 univptr_t 970 malloc _((size_t nbytes)); 971 univptr_t 972 calloc _((size_t nelem, size_t elsize)); 973 univptr_t 974 realloc _((univptr_t cp, size_t nbytes)); 975 univptr_t 976 valloc _((size_t size)); 977 univptr_t 978 memalign _((size_t alignment, size_t size)); 979 univptr_t 980 emalloc _((size_t nbytes)); 981 univptr_t 982 ecalloc _((size_t nelem, size_t sz)); 983 univptr_t 984 erealloc _((univptr_t ptr, size_t nbytes)); 985 Free_t free _((univptr_t cp)); 986 Free_t cfree _((univptr_t cp)); 996 univptr_t 997 malloc(size_t nbytes); 998 univptr_t 999 calloc(size_t nelem, size_t elsize); 1000 univptr_t 1001 realloc(univptr_t cp, size_t nbytes); 1002 univptr_t 1003 valloc(size_t size); 1004 univptr_t 1005 memalign(size_t alignment, size_t size); 1006 univptr_t 1007 emalloc(size_t nbytes); 1008 univptr_t 1009 ecalloc(size_t nelem, size_t sz); 1010 univptr_t 1011 erealloc(univptr_t ptr, size_t nbytes); 1012 Free_t 1013 free(univptr_t cp); 1014 Free_t 1015 cfree(univptr_t cp); 987 1016 #endif /* CSRI_TRACE */ 988 1017 989 int990 __m_botch991 _((const char *s1, const char *s2, univptr_t p,992 int is_end_ptr, const char *filename, int linenumber));993 void994 __m_prnode _((SPBLK * spblk));995 void996 mal_contents _((FILE * fp));1018 int 1019 __m_botch 1020 (const char *s1, const char *s2, univptr_t p, 1021 int is_end_ptr, const char *filename, int linenumber); 1022 void 1023 __m_prnode(SPBLK * spblk); 1024 void 1025 mal_contents(FILE * fp); 997 1026 #ifdef CSRI_DEBUG 998 void999 mal_debug _((int level));1000 int1001 mal_verify _((int fullcheck));1002 #endif 1003 void1004 mal_dumpleaktrace _((FILE * fp));1005 void1006 mal_heapdump _((FILE * fp));1007 void1008 mal_leaktrace _((int value));1009 void1010 mal_sbrkset _((int n));1011 void1012 mal_slopset _((int n));1027 void 1028 mal_debug(int level); 1029 int 1030 mal_verify(int fullcheck); 1031 #endif 1032 void 1033 mal_dumpleaktrace(FILE * fp); 1034 void 1035 mal_heapdump(FILE * fp); 1036 void 1037 mal_leaktrace(int value); 1038 void 1039 mal_sbrkset(int n); 1040 void 1041 mal_slopset(int n); 1013 1042 #ifdef CSRI_PROFILESIZES 1014 void1015 mal_statsdump _((FILE * fp));1016 #endif 1017 void1018 mal_trace _((int value));1019 void1020 mal_mmap _((char *fname));1043 void 1044 mal_statsdump(FILE * fp); 1045 #endif 1046 void 1047 mal_trace(int value); 1048 void 1049 mal_mmap(char *fname); 1021 1050 1022 1051 #ifdef CSRI_TRACE … … 1040 1069 univptr_t 1041 1070 trace__erealloc(ptr, nbytes, fname, linenum) 1042 univptr_t 1043 ptr; 1071 univptr_t ptr; 1044 1072 size_t nbytes; 1045 1073 const char *fname; … … 1111 1139 univptr_t 1112 1140 trace__realloc(cp, nbytes, fname, linenum) 1113 univptr_t 1114 cp; 1141 univptr_t cp; 1115 1142 size_t nbytes; 1116 1143 const char *fname; … … 1470 1497 univptr_t 1471 1498 erealloc(ptr, nbytes) 1472 univptr_t 1473 ptr; 1499 univptr_t ptr; 1474 1500 size_t nbytes; 1475 1501 { … … 1565 1591 if ((char *) p + nbytes > mmf.i_end) { 1566 1592 errno = ENOMEM; 1567 return (univptr_t) - 1;1593 return (univptr_t) - 1; 1568 1594 } 1569 1595 mmf.i_alloced += nbytes; … … 1578 1604 if (mmap_filename == NULL) { 1579 1605 errno = ENOMEM; 1580 return (univptr_t) - 1;1606 return (univptr_t) - 1; 1581 1607 } 1582 1608 } 1583 1609 mmf.i_fd = open(mmap_filename, O_RDWR, 0666); 1584 1610 if (mmf.i_fd < 0 || fstat(mmf.i_fd, &stbuf) < 0) 1585 return (univptr_t) - 1;1611 return (univptr_t) - 1; 1586 1612 if (stbuf.st_size < nbytes) { 1587 1613 errno = ENOMEM; 1588 return (univptr_t) - 1;1614 return (univptr_t) - 1; 1589 1615 } 1590 1616 mmf.i_size = stbuf.st_size; … … 1592 1618 MAP_SHARED, mmf.i_fd, (off_t) 0); 1593 1619 if (mmf.i_data == (caddr_t) - 1) 1594 return (univptr_t) - 1;1620 return (univptr_t) - 1; 1595 1621 mmf.i_end = mmf.i_data + mmf.i_size; 1596 1622 mmf.i_alloced = nbytes; … … 1604 1630 size_t nbytes __attribute__ ((__unused__)); 1605 1631 { 1606 return (univptr_t) - 1;1632 return (univptr_t) - 1; 1607 1633 } 1608 1634 … … 1737 1763 } 1738 1764 1739 static void __m_count _((SPBLK * spblk));1765 static void __m_count(SPBLK * spblk); 1740 1766 1741 1767 static void … … 1859 1885 } 1860 1886 1861 static int grabhunk _((size_t));1887 static int grabhunk(size_t); 1862 1888 1863 1889 static int … … 1881 1907 _malloc_sbrkunits); 1882 1908 morecore = sbrkwords * sizeof(Word) + SBRKEXTRA; 1883 if ((cp = (*_malloc_memfunc) (morecore)) == (univptr_t) - 1)1909 if ((cp = (*_malloc_memfunc) (morecore)) == (univptr_t) - 1) 1884 1910 return (0); 1885 1911 /* … … 2061 2087 Free_t 2062 2088 free(cp) 2063 univptr_t 2064 cp; 2089 univptr_t cp; 2065 2090 { 2066 2091 /* … … 2198 2223 univptr_t 2199 2224 realloc(cp, nbytes) 2200 univptr_t 2201 cp; 2225 univptr_t cp; 2202 2226 size_t nbytes; 2203 2227 { … … 2313 2337 Free_t 2314 2338 cfree(cp) 2315 univptr_t 2316 cp; 2339 univptr_t cp; 2317 2340 { 2318 2341 #ifdef INT_FREE
