Changeset 4258


Ignore:
Timestamp:
Jan 13, 2010, 12:54:31 AM (8 years ago)
Author:
Sam Hocevar
Message:

Add a workaround for OS X ignoring RLIMIT_RSS / RLIMIT_AS and getrusage()
not filling in RSS information. After each memory allocation, we ask the
Mach for the RSS value.

Location:
zzuf/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/configure.ac

    r4256 r4258  
    4646AC_SUBST(DLL_LDFLAGS)
    4747
    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)
     48AC_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)
    4949
    5050AC_CHECK_FUNCS(setenv waitpid setrlimit gettimeofday fork kill pipe _pipe)
  • zzuf/trunk/msvc/config.h

    r4248 r4258  
    6060/* #undef HAVE_LIBC_H */
    6161/* #undef HAVE_LSEEK64 */
     62/* #undef HAVE_MACH_TASK_H */
    6263#define HAVE_MALLOC_H 1
    6364/* #undef HAVE_MAP_FD */
  • zzuf/trunk/src/libzzuf/lib-mem.c

    r4253 r4258  
    6464#   include <libc.h>
    6565#endif
     66#if defined HAVE_MACH_TASK_H
     67#   include <mach/mach.h>
     68#   include <mach/task.h>
     69#endif
    6670
    6771#include "libzzuf.h"
     
    126130#define DUMMY_STOP ((uintptr_t)dummy_buffer + DUMMY_BYTES)
    127131
     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. */
     134static 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
    128148void _zz_mem_init(void)
    129149{
     
    172192    }
    173193    ret = ORIG(malloc)(size);
    174     if(ret == NULL && _zz_memory && errno == ENOMEM)
     194    if (_zz_memory && ((!ret && errno == ENOMEM)
     195                        || (ret && memory_exceeded())))
    175196        raise(SIGKILL);
    176197    return ret;
     
    217238    LOADSYM(realloc);
    218239    ret = ORIG(realloc)(ptr, size);
    219     if(ret == NULL && _zz_memory && errno == ENOMEM)
     240    if (_zz_memory && ((!ret && errno == ENOMEM)
     241                        || (ret && memory_exceeded())))
    220242        raise(SIGKILL);
    221243    return ret;
     
    228250    LOADSYM(valloc);
    229251    ret = ORIG(valloc)(size);
    230     if(ret == NULL && _zz_memory && errno == ENOMEM)
     252    if (_zz_memory && ((!ret && errno == ENOMEM)
     253                        || (ret && memory_exceeded())))
    231254        raise(SIGKILL);
    232255    return ret;
     
    240263    LOADSYM(memalign);
    241264    ret = ORIG(memalign)(boundary, size);
    242     if(ret == NULL && _zz_memory && errno == ENOMEM)
     265    if (_zz_memory && ((!ret && errno == ENOMEM)
     266                        || (ret && memory_exceeded())))
    243267        raise(SIGKILL);
    244268    return ret;
     
    252276    LOADSYM(posix_memalign);
    253277    ret = ORIG(posix_memalign)(memptr, alignment, size);
    254     if(ret == ENOMEM && _zz_memory)
     278    if (_zz_memory && ((!ret && errno == ENOMEM)
     279                        || (ret && memory_exceeded())))
    255280        raise(SIGKILL);
    256281    return ret;
  • zzuf/trunk/src/libzzuf/libzzuf.c

    r4253 r4258  
    8484 * variable.
    8585 */
    86 int _zz_memory = 0;
     86uint64_t _zz_memory = 0;
    8787
    8888/**
     
    176176
    177177    tmp = getenv("ZZUF_MEMORY");
    178     if(tmp && *tmp == '1')
    179         _zz_memory = 1;
     178    if(tmp)
     179        _zz_memory = atoll(tmp);
    180180
    181181    tmp = getenv("ZZUF_NETWORK");
  • zzuf/trunk/src/libzzuf/libzzuf.h

    r4253 r4258  
    2121extern int _zz_debugfd;
    2222extern int _zz_signal;
    23 extern int _zz_memory;
     23extern uint64_t _zz_memory;
    2424extern int _zz_network;
    2525extern int _zz_autoinc;
Note: See TracChangeset for help on using the changeset viewer.