Changeset 36
- Timestamp:
- 03/18/07 01:37:02 (6 years ago)
- Files:
-
- trunk/envvar.c (modified) (4 diffs)
- trunk/malloc.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/envvar.c
r2 r36 94 94 #endif 95 95 96 #ifdef __GLIBC__ 97 /* replace getenv() with a specialized version that doesn't 98 * need to allocate memory. We can't use strlen or strcmp 99 * here. */ 100 #include <unistd.h> 101 static char *safe_getenv(const char *name) 102 { 103 int i, l; 104 for (l = 0; name[l]; l++) 105 ; 106 for (i = 0; __environ[i]; i++) { 107 if (!memcmp(__environ[i], name, l) && __environ[i][l] == '=') { 108 return &__environ[i][l+1]; 109 } 110 } 111 return NULL; 112 } 113 #define getenv(x) safe_getenv(x) 114 #endif 115 96 116 static arg_process_t umem_log_process; 97 117 … … 554 574 STATE_START, 555 575 STATE_GETENV, 576 STATE_DLOPEN, 556 577 STATE_DLSYM, 557 578 STATE_FUNC, … … 577 598 where = "during getenv(3C) calls -- " 578 599 "getenv(3C) results ignored."; 600 break; 601 case STATE_DLOPEN: 602 where = "during dlopen(3C) call -- " 603 "_umem_*() results ignored."; 579 604 break; 580 605 case STATE_DLSYM: … … 624 649 # define dlerror() 0 625 650 #endif 651 state = STATE_DLOPEN; 626 652 /* get a handle to the "a.out" object */ 627 653 if ((h = dlopen(0, RTLD_FIRST | RTLD_LAZY)) != NULL) { trunk/malloc.c
r27 r36 42 42 #include "misc.h" 43 43 44 #ifdef __GLIBC__ 45 # include <malloc.h> 46 #endif 47 44 48 /* 45 49 * malloc_data_t is an 8-byte structure which is located "before" the pointer … … 59 63 } malloc_data_t; 60 64 65 #ifdef __GLIBC__ 66 static void *umem_malloc_hook(size_t size_arg, const void *caller) 67 #else 61 68 void * 62 69 malloc(size_t size_arg) 70 #endif 63 71 { 64 72 #ifdef _LP64 … … 121 129 } 122 130 131 #ifndef __GLIBC__ 123 132 void * 124 133 calloc(size_t nelem, size_t elsize) … … 139 148 return (retval); 140 149 } 150 #endif 141 151 142 152 /* … … 147 157 */ 148 158 159 #ifdef __GLIBC__ 160 static void *umem_memalign_hook(size_t size_arg, size_t align, const void *caller) 161 #else 149 162 void * 150 163 memalign(size_t align, size_t size_arg) 164 #endif 151 165 { 152 166 size_t size; … … 227 241 } 228 242 243 #ifndef __GLIBC__ 229 244 void * 230 245 valloc(size_t size) … … 232 247 return (memalign(pagesize, size)); 233 248 } 249 #endif 234 250 235 251 /* … … 377 393 } 378 394 395 #ifdef __GLIBC__ 396 static void umem_free_hook(void *buf, const void *caller) 397 #else 379 398 void 380 399 free(void *buf) 400 #endif 381 401 { 382 402 if (buf == NULL) … … 389 409 } 390 410 411 #ifdef __GLIBC__ 412 static void *umem_realloc_hook(void *buf_arg, size_t newsize, const void *caller) 413 #else 391 414 void * 392 415 realloc(void *buf_arg, size_t newsize) 416 #endif 393 417 { 394 418 size_t oldsize; … … 418 442 } 419 443 444 #ifdef __GLIBC__ 445 static void __attribute__((constructor)) umem_malloc_init_hook(void) 446 { 447 if (__malloc_hook != umem_malloc_hook) { 448 umem_startup(NULL, 0, 0, NULL, NULL); 449 __malloc_hook = umem_malloc_hook; 450 __free_hook = umem_free_hook; 451 __realloc_hook = umem_realloc_hook; 452 __memalign_hook = umem_memalign_hook; 453 } 454 } 455 456 void (*__malloc_initialize_hook)(void) = umem_malloc_init_hook; 457 458 #else 420 459 void __attribute__((constructor)) 421 460 __malloc_umem_init (void) 422 461 { 423 umem_startup(NULL, 0, 0, NULL, NULL); 424 } 462 umem_startup(NULL, 0, 0, NULL, NULL); 463 } 464 #endif 465
