Ticket #24806: tor-0.3.2.9-mtrace.patch

File tor-0.3.2.9-mtrace.patch, 5.3 KB (added by starlight, 20 months ago)

mtrace patch

  • src/common/util.h

    Do not run production with this patch.  Eliminates
    memory exhaustion check in tor_malloc_().
    
    OpenSSL his it's own memory thunks and so without
    call-arcs the utlity of the output with this patch
    is limited.
    
    To achieve goal of feature-on-demand with good performance,
    create revised mtrace() integrated module that collects
    full stack trace and writes records in binary.  Write
    C++ program that reads binary file, subtracting frees
    and finally summarizing Valgrind-style by call-arcs
    with count.
    
    FIXED SIZE RECORD:
       time seconds
       time nanoseconds
       thread/task ID
       action:  0=free, 1=malloc, 2=calloc, 3=realloc
       address
       size
       caller00
       caller01
       ...
       caller09
    
    old new  
    8888  STMT_END
    8989#endif /* defined(USE_DMALLOC) */
    9090
     91#if 0
    9192#define tor_malloc(size)       tor_malloc_(size DMALLOC_ARGS)
    9293#define tor_malloc_zero(size)  tor_malloc_zero_(size DMALLOC_ARGS)
    9394#define tor_calloc(nmemb,size) tor_calloc_(nmemb, size DMALLOC_ARGS)
    9495#define tor_realloc(ptr, size) tor_realloc_(ptr, size DMALLOC_ARGS)
     96#else
     97#define tor_malloc(size)       malloc(size)
     98#define tor_malloc_zero(size)  calloc(1, size)
     99#define tor_calloc(nmemb,size) calloc(nmemb, size)
     100#define tor_realloc(ptr, size) realloc(ptr, size)
     101#endif
    95102#define tor_reallocarray(ptr, sz1, sz2) \
    96103  tor_reallocarray_((ptr), (sz1), (sz2) DMALLOC_ARGS)
    97104#define tor_strdup(s)          tor_strdup_(s DMALLOC_ARGS)
  • src/or/or.h

    old new  
    105105#define SIGNEWNYM 129
    106106#define SIGCLEARDNSCACHE 130
    107107#define SIGHEARTBEAT 131
     108#define SIGMTRACEON 132
     109#define SIGMTRACEOFF 133
    108110
    109111#if (SIZEOF_CELL_T != 0)
    110112/* On Irix, stdlib.h defines a cell_t type, so we need to make sure
  • src/or/control.c

    old new  
    15061506  { SIGNEWNYM, "NEWNYM" },
    15071507  { SIGCLEARDNSCACHE, "CLEARDNSCACHE"},
    15081508  { SIGHEARTBEAT, "HEARTBEAT"},
     1509  { SIGMTRACEON, "MTRACE" },
     1510  { SIGMTRACEOFF, "MUNTRACE" },
    15091511  { 0, NULL },
    15101512};
    15111513
     
    62416243    case SIGUSR2:
    62426244      signal_string = "DEBUG";
    62436245      break;
     6246    case SIGMTRACEON:
     6247      signal_string = "MTRACE";
     6248      break;
     6249    case SIGMTRACEOFF:
     6250      signal_string = "MUNTRACE";
     6251      break;
    62446252    case SIGNEWNYM:
    62456253      signal_string = "NEWNYM";
    62466254      break;
  • src/or/main.c

    old new  
    110110#include "ext_orport.h"
    111111#ifdef USE_DMALLOC
    112112#include <dmalloc.h>
     113#else
     114#include <mcheck.h>
    113115#endif
    114116#include "memarea.h"
    115117#include "sandbox.h"
     
    27042706static void
    27052707process_signal(int sig)
    27062708{
     2709#ifdef SIGRTMIN
     2710       if (sig == SIGRTMIN+6) { sig = SIGMTRACEON;  }
     2711  else if (sig == SIGRTMIN+7) { sig = SIGMTRACEOFF; }
     2712#endif
    27072713  switch (sig)
    27082714    {
    27092715    case SIGTERM:
     
    27382744                "Send HUP to change back.");
    27392745      control_event_signal(sig);
    27402746      break;
     2747    case SIGMTRACEON:
     2748#ifndef USE_DMALLOC
     2749      mtrace();
     2750      log_notice(LD_GENERAL,"Caught RTMIN+6 activated mtrace()");
     2751#endif
     2752      control_event_signal(sig);
     2753      break;
     2754    case SIGMTRACEOFF:
     2755#ifndef USE_DMALLOC
     2756      muntrace();
     2757      log_notice(LD_GENERAL,"Caught RTMIN+7 deactivated mtrace()");
     2758#endif
     2759      control_event_signal(sig);
     2760      break;
    27412761    case SIGHUP:
    27422762#ifdef HAVE_SYSTEMD
    27432763      sd_notify(0, "RELOADING=1");
     
    29472967#ifdef SIGUSR2
    29482968  { SIGUSR2, UNIX_ONLY, NULL }, /* go to loglevel debug */
    29492969#endif
     2970#ifdef SIGRTMIN
     2971  { SIGMTRACEON,  UNIX_ONLY, NULL },  /* activate mtrace() */
     2972  { SIGMTRACEOFF, UNIX_ONLY, NULL },  /* deactivate mtrace() */
     2973#endif
    29502974#ifdef SIGHUP
    29512975  { SIGHUP, UNIX_ONLY, NULL }, /* to reload config, retry conns, etc */
    29522976#endif
     
    29712995  if (is_parent) {
    29722996    for (i = 0; signal_handlers[i].signal_value >= 0; ++i) {
    29732997      if (signal_handlers[i].try_to_register) {
     2998#ifdef SIGRTMIN
     2999        /* fixup variable signal numbers */
     3000        if (signal_handlers[i].signal_value == SIGMTRACEON) {
     3001          signal_handlers[i].signal_value = SIGRTMIN+6;
     3002        } else
     3003        if (signal_handlers[i].signal_value == SIGMTRACEOFF) {
     3004          signal_handlers[i].signal_value = SIGRTMIN+7;
     3005        }
     3006#endif
    29743007        signal_handlers[i].signal_event =
    29753008          tor_evsignal_new(tor_libevent_get_base(),
    29763009                           signal_handlers[i].signal_value,
     
    29933026    action.sa_flags = 0;
    29943027    sigemptyset(&action.sa_mask);
    29953028    action.sa_handler = SIG_IGN;
    2996     sigaction(SIGINT,  &action, NULL);
    2997     sigaction(SIGTERM, &action, NULL);
    2998     sigaction(SIGPIPE, &action, NULL);
    2999     sigaction(SIGUSR1, &action, NULL);
    3000     sigaction(SIGUSR2, &action, NULL);
    3001     sigaction(SIGHUP,  &action, NULL);
     3029    sigaction(SIGINT,     &action, NULL);
     3030    sigaction(SIGTERM,    &action, NULL);
     3031    sigaction(SIGPIPE,    &action, NULL);
     3032    sigaction(SIGUSR1,    &action, NULL);
     3033    sigaction(SIGUSR2,    &action, NULL);
     3034#ifdef SIGRTMIN
     3035    sigaction(SIGRTMIN+6, &action, NULL);
     3036    sigaction(SIGRTMIN+7, &action, NULL);
     3037#endif
     3038    sigaction(SIGHUP,     &action, NULL);
    30023039#ifdef SIGXFSZ
    3003     sigaction(SIGXFSZ, &action, NULL);
     3040    sigaction(SIGXFSZ,    &action, NULL);
    30043041#endif
    30053042#endif /* !defined(_WIN32) */
    30063043  }