Changeset 4c51931
- Timestamp:
- 06/03/15 01:17:08 (10 years ago)
- Branches:
- master
- Children:
- 3c9fc94
- Parents:
- ed8b809
- git-author:
- Hal Finkel <hfinkel@…> (06/03/15 01:17:08)
- git-committer:
- Hal Finkel <hfinkel@…> (06/03/15 01:17:08)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
memlog.cpp
red8b809 r4c51931 14 14 15 15 #include <limits.h> 16 #include <errno.h> 16 17 #include <malloc.h> 17 18 #include <execinfo.h> … … 40 41 // -Wl,--wrap,malloc,--wrap,free,--wrap,realloc,--wrap,calloc,--wrap,memalign /path/to/memlog_s.o -lpthread -ldl 41 42 42 FILE *log_file = 0;43 static FILE *log_file = 0; 43 44 static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; 44 45 … … 49 50 50 51 #ifdef __bgq__ 51 int on_bgq = 0; 52 #endif 53 54 void *initial_brk = 0; 52 static int on_bgq = 0; 53 #endif 54 55 static void *initial_brk = 0; 56 57 static unordered_map<void *, Dl_info> *dladdr_cache = 0; 55 58 56 59 __attribute__((__constructor__)) … … 111 114 (void) fflush(log_file); 112 115 (void) fclose(log_file); 116 117 if (dladdr_cache) 118 delete dladdr_cache; 113 119 } 114 120 … … 116 122 // we need to cache the lookup results. 117 123 static int dladdr_cached(void * addr, Dl_info *info) { 118 static unordered_map<void *, Dl_info> dladdr_cache; 119 120 auto I = dladdr_cache.find(addr); 121 if (I == dladdr_cache.end()) { 124 if (!dladdr_cache) 125 dladdr_cache = new unordered_map<void *, Dl_info>; 126 127 auto I = dladdr_cache->find(addr); 128 if (I == dladdr_cache->end()) { 122 129 int r; 123 130 if (!(r = dladdr(addr, info))) 124 131 memset(info, 0, sizeof(Dl_info)); 125 132 126 dladdr_cache .insert(make_pair(addr, *info));133 dladdr_cache->insert(make_pair(addr, *info)); 127 134 return r; 128 135 } … … 246 253 247 254 #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 static int (*__real_posix_memalign)(void **memptr, size_t alignment, 256 size_t size) = 0; 257 258 static void *(*__real_mmap)(void *addr, size_t length, int prot, int flags, 259 int fd, off_t offset) = 0; 260 static void *(*__real_mmap64)(void *addr, size_t length, int prot, int flags, 261 int fd, off64_t offset) = 0; 262 static int (*__real_munmap)(void *addr, size_t length) = 0; 255 263 #else 256 264 extern "C" {
Note: See TracChangeset
for help on using the changeset viewer.