- Timestamp:
- Jan 13, 2010, 12:54:31 AM (11 years ago)
- Location:
- zzuf/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/configure.ac
r4256 r4258 46 46 AC_SUBST(DLL_LDFLAGS) 47 47 48 AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/cdefs.h sys/socket.h netinet/in.h arpa/inet.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h )48 AC_CHECK_HEADERS(windows.h winsock2.h io.h process.h unistd.h inttypes.h stdint.h getopt.h libc.h malloc.h dlfcn.h regex.h sys/cdefs.h sys/socket.h netinet/in.h arpa/inet.h sys/uio.h aio.h sys/mman.h sys/wait.h sys/resource.h sys/time.h endian.h mach/task.h) 49 49 50 50 AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe) -
zzuf/trunk/msvc/config.h
r4248 r4258 60 60 /* #undef HAVE_LIBC_H */ 61 61 /* #undef HAVE_LSEEK64 */ 62 /* #undef HAVE_MACH_TASK_H */ 62 63 #define HAVE_MALLOC_H 1 63 64 /* #undef HAVE_MAP_FD */ -
zzuf/trunk/src/libzzuf/lib-mem.c
r4253 r4258 64 64 # include <libc.h> 65 65 #endif 66 #if defined HAVE_MACH_TASK_H 67 # include <mach/mach.h> 68 # include <mach/task.h> 69 #endif 66 70 67 71 #include "libzzuf.h" … … 126 130 #define DUMMY_STOP ((uintptr_t)dummy_buffer + DUMMY_BYTES) 127 131 132 /* setrlimit(RLIMIT_AS) is ignored on OS X, we need to check memory usage 133 * from inside the process. Oh, and getrusage() doesn't work either. */ 134 static int memory_exceeded(void) 135 { 136 #if defined HAVE_MACH_TASK_H 137 struct task_basic_info tbi; 138 mach_msg_type_number_t mmtn = TASK_BASIC_INFO_COUNT; 139 140 if (task_info(mach_task_self(), TASK_BASIC_INFO, 141 (task_info_t)&tbi, &mmtn) == KERN_SUCCESS 142 && tbi.resident_size > _zz_memory) 143 return 1; 144 #endif 145 return 0; 146 } 147 128 148 void _zz_mem_init(void) 129 149 { … … 172 192 } 173 193 ret = ORIG(malloc)(size); 174 if(ret == NULL && _zz_memory && errno == ENOMEM) 194 if (_zz_memory && ((!ret && errno == ENOMEM) 195 || (ret && memory_exceeded()))) 175 196 raise(SIGKILL); 176 197 return ret; … … 217 238 LOADSYM(realloc); 218 239 ret = ORIG(realloc)(ptr, size); 219 if(ret == NULL && _zz_memory && errno == ENOMEM) 240 if (_zz_memory && ((!ret && errno == ENOMEM) 241 || (ret && memory_exceeded()))) 220 242 raise(SIGKILL); 221 243 return ret; … … 228 250 LOADSYM(valloc); 229 251 ret = ORIG(valloc)(size); 230 if(ret == NULL && _zz_memory && errno == ENOMEM) 252 if (_zz_memory && ((!ret && errno == ENOMEM) 253 || (ret && memory_exceeded()))) 231 254 raise(SIGKILL); 232 255 return ret; … … 240 263 LOADSYM(memalign); 241 264 ret = ORIG(memalign)(boundary, size); 242 if(ret == NULL && _zz_memory && errno == ENOMEM) 265 if (_zz_memory && ((!ret && errno == ENOMEM) 266 || (ret && memory_exceeded()))) 243 267 raise(SIGKILL); 244 268 return ret; … … 252 276 LOADSYM(posix_memalign); 253 277 ret = ORIG(posix_memalign)(memptr, alignment, size); 254 if(ret == ENOMEM && _zz_memory) 278 if (_zz_memory && ((!ret && errno == ENOMEM) 279 || (ret && memory_exceeded()))) 255 280 raise(SIGKILL); 256 281 return ret; -
zzuf/trunk/src/libzzuf/libzzuf.c
r4253 r4258 84 84 * variable. 85 85 */ 86 int _zz_memory = 0;86 uint64_t _zz_memory = 0; 87 87 88 88 /** … … 176 176 177 177 tmp = getenv("ZZUF_MEMORY"); 178 if(tmp && *tmp == '1')179 _zz_memory = 1;178 if(tmp) 179 _zz_memory = atoll(tmp); 180 180 181 181 tmp = getenv("ZZUF_NETWORK"); -
zzuf/trunk/src/libzzuf/libzzuf.h
r4253 r4258 21 21 extern int _zz_debugfd; 22 22 extern int _zz_signal; 23 extern int _zz_memory;23 extern uint64_t _zz_memory; 24 24 extern int _zz_network; 25 25 extern int _zz_autoinc;
Note: See TracChangeset
for help on using the changeset viewer.