1 /* 2 * (c) Copyright 1990, 1991, 1992 Conor P. Cahill (uunet!virtech!cpcahil). 3 * You may copy, distribute, and use this software as long as this 4 * copyright statement is not removed. 5 */ 6 /* 7 * $Id: malloc.h.org,v 1.31 1992/06/22 23:40:10 cpcahil Exp $ 8 */ 9 10 #ifndef _DEBUG_MALLOC_INC 11 #define _DEBUG_MALLOC_INC 1 12 13 #ifdef force_cproto_to_use_defines 14 15 /* 16 * these are just here because cproto used the c-preprocessor to generate 17 * the prototypes and if they were left as #defines the prototypes.h file 18 * would have the contents of the define, not the define itself 19 */ 20 21 typedef char DATATYPE; 22 typedef int SIZETYPE; 23 typedef void VOIDTYPE; 24 typedef char MEMDATA; 25 typedef int MEMSIZE; 26 typedef int STRSIZE; 27 28 #ifdef WRTSIZE 29 #undef WRTSIZE 30 #endif 31 typedef unsigned int WRTSIZE; 32 33 /* 34 * for now, define CONST as const. A sed script in the makefile will change 35 * this back to CONST in the prototypes.h file. 36 */ 37 #define CONST const 38 39 #else /* force_cproto_to_use_defines */ 40 41 /* 42 * The following entries are automatically added by the Configure script. 43 * If they are not correct for your system, then Configure is not handling 44 * your system correctly. Please report this to the author along with 45 * a description of your system and the correct values 46 */ 47 48 49 50 #if __GNUC__ && __STDC__ && __cplusplus 51 52 #define VOIDTYPE void 53 #define CONST const 54 #define DATATYPE void 55 #define SIZETYPE size_t 56 #define MEMDATA void 57 #define MEMSIZE size_t 58 #define MEMCMPTYPE unsigned char 59 #define STRSIZE size_t 60 #define STRCMPTYPE unsigned char 61 62 #else /* __GNUC__ && __STDC__ && __cplusplus */ 63 64 #define VOIDTYPE void 65 #define CONST const 66 #define DATATYPE void 67 #define SIZETYPE size_t 68 #define MEMDATA void 69 #define MEMSIZE int 70 #define MEMCMPTYPE unsigned char 71 #define STRSIZE size_t 72 #define STRCMPTYPE unsigned char 73 74 #endif /* __GNUC__ && __STDC__ && __cplusplus */ 75 76 /* 77 * END of automatic configuration stuff. 78 */ 79 80 /* 81 * if DATATYPE is not defined, then the configure script must have had a 82 * problem, or was used with a different compiler. So we have to stop 83 * here and get the user to fix the problem. 84 */ 85 #ifndef DATATYPE 86 /* 87 * the following string should cause a comilation error and get the 88 * user to look at this stuff to find out what is wrong. 89 */ 90 "This file is not configured correctly for this system. Run configure 91 and check its results" 92 char * malloc(); /* DON'T REMOVE THIS LINE if you get a compiler error 93 here it is because the malloc.h file is not 94 configured correctly See the readme/problems 95 files for more info */ 96 97 #endif /* DATATYPE */ 98 99 #endif /* force_cproto_to_use_defines */ 100 101 #define VOIDCAST (VOIDTYPE) 102 103 /* 104 * since we redefine much of the stuff that is #defined in string.h and 105 * memory.h, we should do what we can to make sure that they don't get 106 * included after us. This is typically accomplished by a special symbol 107 * (similar to _DEBUG_MALLOC_INC defined above) that is #defined when the 108 * file is included. Since we don't want the file to be included we will 109 * #define the symbol ourselves. These will typically have to change from 110 * one system to another. I have put in several standard mechanisms used to 111 * support this mechanism, so hopefully you won't have to modify this file. 112 */ 113 #ifndef _H_STRING 114 #define _H_STRING 1 115 #endif 116 #ifndef __STRING_H 117 #define __STRING_H 1 118 #endif 119 #ifndef _STRING_H_ 120 #define _STRING_H_ 1 121 #endif 122 #ifndef _STRING_H 123 #define _STRING_H 1 124 #endif 125 #ifndef _STRING_INCLUDED 126 #define _STRING_INCLUDED 1 127 #endif 128 #ifndef __string_h 129 #define __string_h 1 130 #endif 131 #ifndef _string_h 132 #define _string_h 1 133 #endif 134 #ifndef _strings_h 135 #define _strings_h 1 136 #endif 137 #ifndef __strings_h 138 #define __strings_h 1 139 #endif 140 #ifndef _H_MEMORY 141 #define _H_MEMORY 1 142 #endif 143 #ifndef __MEMORY_H 144 #define __MEMORY_H 1 145 #endif 146 #ifndef _MEMORY_H_ 147 #define _MEMORY_H_ 1 148 #endif 149 #ifndef _MEMORY_H 150 #define _MEMORY_H 1 151 #endif 152 #ifndef _MEMORY_INCLUDED 153 #define _MEMORY_INCLUDED 1 154 #endif 155 #ifndef __memory_h 156 #define __memory_h 1 157 #endif 158 #ifndef _memory_h 159 #define _memory_h 1 160 #endif 161 162 /* 163 * Malloc warning/fatal error handler defines... 164 */ 165 #define M_HANDLE_DUMP 0x80 /* 128 */ 166 #define M_HANDLE_IGNORE 0 167 #define M_HANDLE_ABORT 1 168 #define M_HANDLE_EXIT 2 169 #define M_HANDLE_CORE 3 170 171 /* 172 * Mallopt commands and defaults 173 * 174 * the first four settings are ignored by the debugging mallopt, but are 175 * here to maintain compatibility with the system malloc.h. 176 */ 177 #define M_MXFAST 1 /* ignored by mallopt */ 178 #define M_NLBLKS 2 /* ignored by mallopt */ 179 #define M_GRAIN 3 /* ignored by mallopt */ 180 #define M_KEEP 4 /* ignored by mallopt */ 181 #define MALLOC_WARN 100 /* set malloc warning handling */ 182 #define MALLOC_FATAL 101 /* set malloc fatal handling */ 183 #define MALLOC_ERRFILE 102 /* specify malloc error file */ 184 #define MALLOC_CKCHAIN 103 /* turn on chain checking */ 185 #define MALLOC_FILLAREA 104 /* turn off area filling */ 186 #define MALLOC_LOWFRAG 105 /* use best fit allocation mech */ 187 #define MALLOC_CKDATA 106 /* turn off/on data checking */ 188 #define MALLOC_REUSE 107 /* turn off/on freed seg reuse */ 189 #define MALLOC_SHOWLINKS 108 /* turn off/on adjacent link disp */ 190 191 union malloptarg 192 { 193 int i; 194 char * str; 195 }; 196 197 /* 198 * Malloc warning/fatal error codes 199 */ 200 201 #define M_CODE_CHAIN_BROKE 1 /* malloc chain is broken */ 202 #define M_CODE_NO_END 2 /* chain end != endptr */ 203 #define M_CODE_BAD_PTR 3 /* pointer not in malloc area */ 204 #define M_CODE_BAD_MAGIC 4 /* bad magic number in header */ 205 #define M_CODE_BAD_CONNECT 5 /* chain poingers corrupt */ 206 #define M_CODE_OVERRUN 6 /* data overrun in malloc seg */ 207 #define M_CODE_REUSE 7 /* reuse of freed area */ 208 #define M_CODE_NOT_INUSE 8 /* pointer is not in use */ 209 #define M_CODE_NOMORE_MEM 9 /* no more memory available */ 210 #define M_CODE_OUTOF_BOUNDS 10 /* gone beyound bounds */ 211 #define M_CODE_FREELIST_BAD 11 /* inuse segment on freelist */ 212 #define M_CODE_NOBOUND 12 /* can't calculate boundry */ 213 #define M_CODE_STK_NOCUR 13 /* no current element on stack */ 214 #define M_CODE_STK_BADFUNC 14 /* current func doesn't match */ 215 #define M_CODE_UNDERRUN 15 /* data underrun in malloc seg */ 216 217 #ifndef __STDCARGS 218 #if __STDC__ || __cplusplus 219 #define __STDCARGS(a) a 220 #else 221 #define __STDCARGS(a) () 222 #endif 223 #endif 224 225 #if __cplusplus 226 extern "C" { 227 #endif 228 229 VOIDTYPE malloc_dump __STDCARGS((int)); 230 VOIDTYPE malloc_list __STDCARGS((int,unsigned long, unsigned long)); 231 int mallopt __STDCARGS((int, union malloptarg)); 232 DATATYPE * debug_calloc __STDCARGS((CONST char *,int,SIZETYPE,SIZETYPE)); 233 VOIDTYPE debug_cfree __STDCARGS((CONST char *, int, DATATYPE *)); 234 VOIDTYPE debug_free __STDCARGS((CONST char *, int, DATATYPE *)); 235 DATATYPE * debug_malloc __STDCARGS((CONST char *,int, SIZETYPE)); 236 DATATYPE * debug_realloc __STDCARGS((CONST char *,int, 237 DATATYPE *,SIZETYPE)); 238 unsigned long DBmalloc_size __STDCARGS((CONST char *,int,unsigned long *)); 239 int DBmalloc_chain_check __STDCARGS((CONST char *,int,int)); 240 241 void StackEnter __STDCARGS((CONST char *, CONST char *, int)); 242 void StackLeave __STDCARGS((CONST char *, CONST char *, int)); 243 244 /* 245 * X allocation related prototypes 246 */ 247 char * debug_XtMalloc __STDCARGS((CONST char *, int, unsigned int)); 248 char * debug_XtRealloc __STDCARGS((CONST char *, int, 249 char *, unsigned int)); 250 char * debug_XtCalloc __STDCARGS((CONST char *, int, 251 unsigned int, unsigned int)); 252 void debug_XtFree __STDCARGS((CONST char *, int, char *)); 253 void * debug_XtBCopy __STDCARGS((CONST char *, int, char *, 254 char *, int)); 255 extern void (*XtAllocErrorHandler) __STDCARGS((CONST char *)); 256 257 /* 258 * memory(3) related prototypes 259 */ 260 MEMDATA * DBmemccpy __STDCARGS((CONST char *file, int line, 261 MEMDATA *ptr1, CONST MEMDATA *ptr2, 262 int ch, MEMSIZE len)); 263 MEMDATA * DBmemchr __STDCARGS((CONST char *file, int line, 264 CONST MEMDATA *ptr1, int ch, 265 MEMSIZE len)); 266 MEMDATA * DBmemmove __STDCARGS((CONST char *file, int line, 267 MEMDATA *ptr1, CONST MEMDATA *ptr2, 268 MEMSIZE len)); 269 MEMDATA * DBmemcpy __STDCARGS((CONST char *file, int line, 270 MEMDATA *ptr1, CONST MEMDATA *ptr2, 271 MEMSIZE len)); 272 int DBmemcmp __STDCARGS((CONST char *file, int line, 273 CONST MEMDATA *ptr1, 274 CONST MEMDATA *ptr2, MEMSIZE len)); 275 MEMDATA * DBmemset __STDCARGS((CONST char *file, int line, 276 MEMDATA *ptr1, int ch, MEMSIZE len)); 277 MEMDATA * DBbcopy __STDCARGS((CONST char *file, int line, 278 CONST MEMDATA *ptr2, MEMDATA *ptr1, 279 MEMSIZE len)); 280 MEMDATA * DBbzero __STDCARGS((CONST char *file, int line, 281 MEMDATA *ptr1, MEMSIZE len)); 282 int DBbcmp __STDCARGS((CONST char *file, int line, 283 CONST MEMDATA *ptr2, 284 CONST MEMDATA *ptr1, MEMSIZE len)); 285 286 /* 287 * string(3) related prototypes 288 */ 289 char * DBstrcat __STDCARGS((CONST char *file,int line, char *str1, 290 CONST char *str2)); 291 char * DBstrdup __STDCARGS((CONST char *file, int line, 292 CONST char *str1)); 293 char * DBstrncat __STDCARGS((CONST char *file, int line, char *str1, 294 CONST char *str2, STRSIZE len)); 295 int DBstrcmp __STDCARGS((CONST char *file, int line, 296 CONST char *str1, CONST char *str2)); 297 int DBstrncmp __STDCARGS((CONST char *file, int line, 298 CONST char *str1, CONST char *str2, 299 STRSIZE len)); 300 int DBstricmp __STDCARGS((CONST char *file, int line, 301 CONST char *str1, CONST char *str2)); 302 int DBstrincmp __STDCARGS((CONST char *file, int line, 303 CONST char *str1, CONST char *str2, 304 STRSIZE len)); 305 char * DBstrcpy __STDCARGS((CONST char *file, int line, char *str1, 306 CONST char *str2)); 307 char * DBstrncpy __STDCARGS((CONST char *file, int line, char *str1, 308 CONST char *str2, STRSIZE len)); 309 STRSIZE DBstrlen __STDCARGS((CONST char *file, int line, 310 CONST char *str1)); 311 char * DBstrchr __STDCARGS((CONST char *file, int line, 312 CONST char *str1, int c)); 313 char * DBstrrchr __STDCARGS((CONST char *file, int line, 314 CONST char *str1, int c)); 315 char * DBindex __STDCARGS((CONST char *file, int line, 316 CONST char *str1, int c)); 317 char * DBrindex __STDCARGS((CONST char *file, int line, 318 CONST char *str1, int c)); 319 char * DBstrpbrk __STDCARGS((CONST char *file, int line, 320 CONST char *str1, CONST char *str2)); 321 STRSIZE DBstrspn __STDCARGS((CONST char *file, int line, 322 CONST char *str1, CONST char *str2)); 323 STRSIZE DBstrcspn __STDCARGS((CONST char *file, int line, 324 CONST char *str1, CONST char *str2)); 325 char * DBstrstr __STDCARGS((CONST char *file, int line, 326 CONST char *str1, CONST char *str2)); 327 char * DBstrtok __STDCARGS((CONST char *file, int line, char *str1, 328 CONST char *str2)); 329 330 #if __cplusplus 331 }; 332 #endif 333 334 /* 335 * Macro which enables logging of the file and line number for each allocation 336 * so that it is easier to determine where the offending malloc comes from. 337 * 338 * NOTE that only code re-compiled with this include file will have this 339 * additional info. Calls from libraries that have not been recompiled will 340 * just have a null string for this info. 341 */ 342 #ifndef IN_MALLOC_CODE 343 344 /* 345 * allocation functions 346 */ 347 #define malloc(len) debug_malloc( __FILE__,__LINE__, (len)) 348 #define realloc(ptr,len) debug_realloc(__FILE__,__LINE__, (ptr), (len)) 349 #define calloc(numelem,size) debug_calloc(__FILE__,__LINE__,(numelem),(size)) 350 #define cfree(ptr) debug_cfree(__FILE__,__LINE__,(ptr)) 351 #define free(ptr) debug_free(__FILE__,__LINE__,(ptr)) 352 #define malloc_size(histptr) DBmalloc_size(__FILE__,__LINE__,(histptr)) 353 #define malloc_chain_check(todo) DBmalloc_chain_check(__FILE__,__LINE__,(todo)) 354 355 /* 356 * X allocation routines 357 */ 358 #define XtCalloc(_num,_size) debug_XtCalloc(__FILE__,__LINE__,_num,_size) 359 #define XtMalloc(_size) debug_XtMalloc(__FILE__,__LINE__,_size) 360 #define XtRealloc(_ptr,_size) debug_XtRealloc(__FILE__,__LINE__,_ptr,_size) 361 #define XtFree(_ptr) debug_XtFree(__FILE__,__LINE__,_ptr) 362 #define _XtBCopy(ptr1,ptr2,len) debug_XtBcopy(__FILE__,__LINE__,ptr1,ptr2,len) 363 364 /* 365 * Other allocation functions 366 */ 367 #define _malloc(_size) debug_malloc(__FILE__,__LINE__,_size) 368 #define _realloc(_ptr,_size) debug_realloc(__FILE__,__LINE__,_ptr,_size) 369 #define _calloc(_num,_size) debug_calloc(__FILE__,__LINE__,_num,_size) 370 #define _free(_ptr) debug_free(__FILE__,__LINE__,_ptr) 371 372 /* 373 * memory(3) related functions 374 */ 375 #ifdef bcopy 376 #undef bcopy 377 #endif 378 #ifdef bzero 379 #undef bzero 380 #endif 381 #ifdef bcmp 382 #undef bcmp 383 #endif 384 #define memccpy(ptr1,ptr2,ch,len) DBmemccpy(__FILE__,__LINE__,ptr1,ptr2,ch,len) 385 #define memchr(ptr1,ch,len) DBmemchr(__FILE__,__LINE__,ptr1,ch,len) 386 #define memmove(ptr1,ptr2,len) DBmemmove(__FILE__,__LINE__,ptr1, ptr2, len) 387 #define memcpy(ptr1,ptr2,len) DBmemcpy(__FILE__, __LINE__, ptr1, ptr2, len) 388 #define memcmp(ptr1,ptr2,len) DBmemcmp(__FILE__,__LINE__,ptr1, ptr2, len) 389 #define memset(ptr1,ch,len) DBmemset(__FILE__,__LINE__,ptr1, ch, len) 390 #define bcopy(ptr2,ptr1,len) DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len) 391 #define bzero(ptr1,len) DBbzero(__FILE__,__LINE__,ptr1,len) 392 #define bcmp(ptr2,ptr1,len) DBbcmp(__FILE__, __LINE__, ptr2, ptr1, len) 393 394 #define _bcopy(ptr2,ptr1,len) DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len) 395 #define _bzero(ptr1,len) DBbzero(__FILE__,__LINE__,ptr1,len) 396 #define _bcmp(ptr2,ptr1,len) DBbcmp(__FILE__,__LINE__,ptr2,ptr1,len) 397 #define __dg_bcopy(ptr2,ptr1,len) DBbcopy(__FILE__,__LINE__,ptr2,ptr1,len) 398 #define __dg_bzero(ptr1,len) DBbzero(__FILE__,__LINE__,ptr1,len) 399 #define __dg_bcmp(ptr2,ptr1,len) DBbcmp(__FILE__,__LINE__,ptr2,ptr1,len) 400 401 /* 402 * string(3) related functions 403 */ 404 #ifdef index 405 #undef index 406 #endif 407 #ifdef rindex 408 #undef rindex 409 #endif 410 #ifdef strcpy 411 #undef strcpy 412 #endif 413 #ifdef strcpy 414 #undef strcmp 415 #endif 416 #define index(str1,c) DBindex(__FILE__, __LINE__, str1, c) 417 #define rindex(str1,c) DBrindex(__FILE__, __LINE__, str1, c) 418 #define strcat(str1,str2) DBstrcat(__FILE__,__LINE__,str1,str2) 419 #define strchr(str1,c) DBstrchr(__FILE__, __LINE__, str1,c) 420 #define strcmp(str1,str2) DBstrcmp(__FILE__, __LINE__, str1, str2) 421 #define strcpy(str1,str2) DBstrcpy(__FILE__, __LINE__, str1, str2) 422 #define strcspn(str1,str2) DBstrcspn(__FILE__, __LINE__, str1,str2) 423 #define strdup(str1) DBstrdup(__FILE__, __LINE__, str1) 424 #define stricmp(str1,str2) DBstricmp(__FILE__, __LINE__, str1, str2) 425 #define strincmp(str1,str2,len) DBstrincmp(__FILE__, __LINE__, str1,str2,len) 426 #define strlen(str1) DBstrlen(__FILE__, __LINE__, str1) 427 #define strncat(str1,str2,len) DBstrncat(__FILE__, __LINE__, str1,str2,len) 428 #define strncpy(str1,str2,len) DBstrncpy(__FILE__,__LINE__,str1,str2,len) 429 #define strncmp(str1,str2,len) DBstrncmp(__FILE__, __LINE__, str1,str2,len) 430 #define strpbrk(str1,str2) DBstrpbrk(__FILE__, __LINE__, str1,str2) 431 #define strrchr(str1,c) DBstrrchr(__FILE__,__LINE__,str1,c) 432 #define strspn(str1,str2) DBstrspn(__FILE__, __LINE__, str1,str2) 433 #define strstr(str1,str2) DBstrstr(__FILE__, __LINE__, str1, str2) 434 #define strtok(str1,str2) DBstrtok(__FILE__, __LINE__, str1, str2) 435 436 /* 437 * malloc stack related functions 438 */ 439 #define malloc_enter(func) StackEnter(func,__FILE__,__LINE__) 440 #define malloc_leave(func) StackLeave(func,__FILE__,__LINE__) 441 442 #endif /* IN_MALLOC_CODE */ 443 444 #endif /* _DEBUG_MALLOC_INC */ 445 446 /* 447 * $Log: malloc.h.org,v $ 448 * Revision 1.31 1992/06/22 23:40:10 cpcahil 449 * many fixes for working on small int systems 450 * 451 * Revision 1.30 1992/05/06 04:53:29 cpcahil 452 * performance enhancments 453 * 454 * Revision 1.29 1992/04/22 18:17:32 cpcahil 455 * added support for Xt Alloc functions, linted code 456 * 457 * Revision 1.28 1992/04/13 19:08:18 cpcahil 458 * fixed case insensitive stuff 459 * 460 * Revision 1.27 1992/04/13 18:41:18 cpcahil 461 * added case insensitive string comparison routines 462 * 463 * Revision 1.26 1992/04/13 17:26:25 cpcahil 464 * minor portability changes 465 * 466 * Revision 1.25 1992/04/13 14:13:18 cpcahil 467 * cleanup of log message. 468 * 469 * Revision 1.24 1992/04/13 03:09:14 cpcahil 470 * lots of changes. 471 * 472 * Revision 1.23 1992/03/01 12:42:38 cpcahil 473 * added support for managing freed areas and fixed doublword bndr problems 474 * 475 * Revision 1.22 1992/02/07 15:51:07 cpcahil 476 * mods for sun4 477 * 478 * Revision 1.21 1992/01/29 01:35:32 cpcahil 479 * added sgi definition. 480 * 481 * Revision 1.20 1992/01/28 21:42:25 cpcahil 482 * changes for the ibmRS6000 483 * 484 * Revision 1.19 1992/01/28 18:05:37 cpcahil 485 * misc fixes for patch 7 486 * 487 * Revision 1.18 1992/01/22 16:21:35 cpcahil 488 * added code to prevent inclusions of string.h and memory.h after malloc.h 489 * was included. 490 * 491 * Revision 1.17 1992/01/10 17:26:46 cpcahil 492 * fixed prototypes use of void. 493 * 494 * Revision 1.16 1992/01/10 16:53:39 cpcahil 495 * added more info on sizetype and datatype. added support for overriding 496 * use of void type. 497 * 498 * Revision 1.15 1992/01/09 17:19:11 cpcahil 499 * put the close brace in the correct position. 500 * 501 * Revision 1.14 1992/01/09 17:12:36 cpcahil 502 * added code to support inclusion in C++ modules 503 * 504 * Revision 1.13 1991/12/31 21:31:26 cpcahil 505 * changes for patch 6. See CHANGES file for more info 506 * 507 * Revision 1.12 1991/12/26 22:31:29 cpcahil 508 * added check to make sure file is not included twice. 509 * 510 * Revision 1.11 1991/12/06 17:58:46 cpcahil 511 * added cfree() for compatibility with some wierd systems 512 * 513 * Revision 1.10 91/12/06 08:54:18 cpcahil 514 * cleanup of __STDC__ usage and addition of CHANGES file 515 * 516 * Revision 1.9 91/12/04 09:23:40 cpcahil 517 * several performance enhancements including addition of free list 518 * 519 * Revision 1.8 91/12/02 19:10:11 cpcahil 520 * changes for patch release 5 521 * 522 * Revision 1.7 91/11/25 14:42:00 cpcahil 523 * Final changes in preparation for patch 4 release 524 * 525 * Revision 1.6 91/11/24 00:49:28 cpcahil 526 * first cut at patch 4 527 * 528 * Revision 1.5 91/11/20 11:54:10 cpcahil 529 * interim checkin 530 * 531 * Revision 1.4 90/08/29 22:23:38 cpcahil 532 * fixed mallopt to use a union as an argument. 533 * 534 * Revision 1.3 90/05/11 11:04:10 cpcahil 535 * took out some extraneous lines 536 * 537 * Revision 1.2 90/05/11 00:13:09 cpcahil 538 * added copyright statment 539 * 540 * Revision 1.1 90/02/23 07:09:03 cpcahil 541 * Initial revision 542 * 543 */ 544