Changeset ed8b809
- Timestamp:
- 06/02/15 18:53:15 (10 years ago)
- Branches:
- master
- Children:
- 4c51931
- Parents:
- 6444e03
- git-author:
- Hal Finkel <hfinkel@…> (06/02/15 18:53:15)
- git-committer:
- Hal Finkel <hfinkel@…> (06/02/15 18:53:15)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
README
r192a260 red8b809 18 18 For statically-linked applications, add the following to your linker flags: 19 19 20 -Wl,--wrap,malloc,--wrap,free,--wrap,realloc,--wrap,calloc,--wrap,memalign \ 20 -Wl,--wrap,malloc,--wrap,valloc,--wrap,realloc,--wrap,calloc,--wrap,memalign,--wrap,free \ 21 -Wl,--wrap,posix_memalign,--wrap,mmap,--wrap,mmap64,--wrap,munmap \ 21 22 /path/to/memlog/memlog_s.o -lpthread -ldl 22 23 -
memlog.cpp
r6444e03 red8b809 54 54 void *initial_brk = 0; 55 55 56 #ifdef __PIC__57 typedef int (*__real_posix_memalign_t)(void **memptr, size_t alignment,58 size_t size);59 __real_posix_memalign_t __real_posix_memalign = 0;60 #else61 extern "C" {62 extern int __real_posix_memalign(void **memptr, size_t alignment, size_t size);63 }64 #endif65 66 56 __attribute__((__constructor__)) 67 57 static void record_init() { … … 255 245 } 256 246 247 #ifdef __PIC__ 248 int (*__real_posix_memalign)(void **memptr, size_t alignment, size_t size) = 0; 249 250 void *(*__real_mmap)(void *addr, size_t length, int prot, int flags, 251 int fd, off_t offset) = 0; 252 void *(*__real_mmap64)(void *addr, size_t length, int prot, int flags, 253 int fd, off64_t offset) = 0; 254 int (*__real_munmap)(void *addr, size_t length) = 0; 255 #else 256 extern "C" { 257 extern int __real_posix_memalign(void **memptr, size_t alignment, size_t size); 258 259 extern void *__real_mmap(void *addr, size_t length, int prot, int flags, 260 int fd, off_t offset); 261 extern void *__real_mmap64(void *addr, size_t length, int prot, int flags, 262 int fd, off64_t offset); 263 extern int __real_munmap(void *addr, size_t length); 264 } 265 #endif 266 257 267 // glibc exports its underlying malloc implementation under the name 258 268 // __libc_malloc so that hooks like this can use it. … … 265 275 extern void __libc_free(void *ptr); 266 276 267 extern void *__mmap(void *addr, size_t length, int prot, int flags,268 int fd, off_t offset);269 extern void *__mmap64(void *addr, size_t length, int prot, int flags,270 int fd, off64_t offset);271 extern int __munmap(void *addr, size_t length);272 273 277 #ifdef __PIC__ 274 278 #define FUNC(x) x … … 392 396 #ifdef __PIC__ 393 397 if (!__real_posix_memalign) 394 if (!(__real_posix_memalign = 395 (__real_posix_memalign_t) dlsym(RTLD_NEXT, "posix_memalign"))) 396 return -1; 398 if (!(*(void **) (&__real_posix_memalign) = 399 dlsym(RTLD_NEXT, "posix_memalign"))) { 400 return ELIBACC; 401 } 397 402 #endif 398 403 … … 417 422 __builtin_extract_return_addr(__builtin_return_address(0)); 418 423 419 if (in_malloc) 420 return __mmap(addr, length, prot, flags, fd, offset); 421 422 in_malloc = 1; 423 424 void *ptr = __mmap(addr, length, prot, flags, fd, offset); 424 #ifdef __PIC__ 425 if (!__real_mmap) 426 if (!(*(void **) (&__real_mmap) = dlsym(RTLD_NEXT, "mmap"))) { 427 errno = ELIBACC; 428 return MAP_FAILED; 429 } 430 #endif 431 432 if (in_malloc) 433 return __real_mmap(addr, length, prot, flags, fd, offset); 434 435 in_malloc = 1; 436 437 void *ptr = __real_mmap(addr, length, prot, flags, fd, offset); 425 438 426 439 if (ptr != MAP_FAILED) … … 437 450 __builtin_extract_return_addr(__builtin_return_address(0)); 438 451 439 if (in_malloc) 440 return __mmap64(addr, length, prot, flags, fd, offset); 441 442 in_malloc = 1; 443 444 void *ptr = __mmap64(addr, length, prot, flags, fd, offset); 452 #ifdef __PIC__ 453 if (!__real_mmap64) 454 if (!(*(void **) (&__real_mmap64) = dlsym(RTLD_NEXT, "mmap64"))) { 455 errno = ELIBACC; 456 return MAP_FAILED; 457 } 458 #endif 459 460 if (in_malloc) 461 return __real_mmap64(addr, length, prot, flags, fd, offset); 462 463 in_malloc = 1; 464 465 void *ptr = __real_mmap64(addr, length, prot, flags, fd, offset); 445 466 446 467 if (ptr != MAP_FAILED) … … 456 477 __builtin_extract_return_addr(__builtin_return_address(0)); 457 478 458 if (in_malloc) 459 return __munmap(addr, length); 479 #ifdef __PIC__ 480 if (!__real_munmap) 481 if (!(*(void **) (&__real_munmap) = dlsym(RTLD_NEXT, "munmap"))) { 482 errno = ELIBACC; 483 return -1; 484 } 485 #endif 486 487 if (in_malloc) 488 return __real_munmap(addr, length); 460 489 461 490 in_malloc = 1; … … 463 492 record_free(addr, caller); 464 493 465 int r = __ munmap(addr, length);494 int r = __real_munmap(addr, length); 466 495 467 496 in_malloc = 0;
Note: See TracChangeset
for help on using the changeset viewer.