Example #1
0
Bool clientobj_remove(const Addr addr, const ObjType t)
{
  DrdClientobj* p;

  if (s_trace_clientobj)
  {
    VG_(message)(Vg_UserMsg, "Removing client object 0x%lx of type %d",
                 addr, t);
#if 0
    VG_(get_and_pp_StackTrace)(VG_(get_running_tid)(),
                               VG_(clo_backtrace_size));
#endif
  }

  p = VG_(OSetGen_Lookup)(s_clientobj, &addr);
  tl_assert(p->any.type == t);
  p = VG_(OSetGen_Remove)(s_clientobj, &addr);
  if (p)
  {
    tl_assert(VG_(OSetGen_Lookup)(s_clientobj, &addr) == 0);
    drd_finish_suppression(p->any.a1, p->any.a2);
    tl_assert(p->any.cleanup);
    (*p->any.cleanup)(p);
    VG_(OSetGen_FreeNode)(s_clientobj, p);
    return True;
  }
  return False;
}
Example #2
0
/* after thread drd_joiner joined thread drd_joinee.                         */
void drd_post_thread_join(DrdThreadId drd_joiner, DrdThreadId drd_joinee)
{
  tl_assert(IsValidDrdThreadId(drd_joiner));
  tl_assert(IsValidDrdThreadId(drd_joinee));

  thread_new_segment(drd_joiner);
  thread_combine_vc(drd_joiner, drd_joinee);
  thread_new_segment(drd_joinee);

  if (s_drd_trace_fork_join)
  {
    const ThreadId joiner = DrdThreadIdToVgThreadId(drd_joiner);
    const ThreadId joinee = DrdThreadIdToVgThreadId(drd_joinee);
    const unsigned msg_size = 256;
    char* msg;

    msg = VG_(malloc)("drd.main.dptj.1", msg_size);
    tl_assert(msg);
    VG_(snprintf)(msg, msg_size,
                  "drd_post_thread_join joiner = %d/%d, joinee = %d/%d",
                  joiner, drd_joiner, joinee, drd_joinee);
    if (joiner)
    {
      VG_(snprintf)(msg + VG_(strlen)(msg), msg_size - VG_(strlen)(msg),
                    ", new vc: ");
      vc_snprint(msg + VG_(strlen)(msg), msg_size - VG_(strlen)(msg),
                 thread_get_vc(drd_joiner));
    }
    VG_(message)(Vg_DebugMsg, "%s", msg);
    VG_(free)(msg);
  }

  if (! s_drd_check_stack_accesses)
  {
    drd_finish_suppression(thread_get_stack_max(drd_joinee)
                           - thread_get_stack_size(drd_joinee),
                           thread_get_stack_max(drd_joinee));
  }
  thread_delete(drd_joinee);
  mutex_thread_delete(drd_joinee);
  cond_thread_delete(drd_joinee);
  semaphore_thread_delete(drd_joinee);
  barrier_thread_delete(drd_joinee);
}
static Bool drd_handle_client_request(ThreadId tid, UWord* arg, UWord* ret)
{
   UWord result = 0;

   switch (arg[0])
   {
   case VG_USERREQ__GET_THREAD_SELF:
      result = tid;
      break;

   case VG_USERREQ__SET_THREAD_NAME:
      thread_set_name_fmt(VgThreadIdToDrdThreadId(VG_(get_running_tid)()),
                          (char*)arg[1], arg[2]);
      break;

   case VG_USERREQ__DRD_START_SUPPRESSION:
      drd_start_suppression(arg[1], arg[1] + arg[2], "client");
      break;

   case VG_USERREQ__DRD_FINISH_SUPPRESSION:
      drd_finish_suppression(arg[1], arg[1] + arg[2]);
      break;

   case VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK:
      thread_set_stack_startup(thread_get_running_tid(),
                               VG_(get_SP)(VG_(get_running_tid)()));
      break;

   case VG_USERREQ__DRD_START_NEW_SEGMENT:
      thread_new_segment(PtThreadIdToDrdThreadId(arg[1]));
      break;

   case VG_USERREQ__DRD_START_RECORDING:
      thread_start_recording(PtThreadIdToDrdThreadId(arg[1]));
      break;

   case VG_USERREQ__DRD_STOP_RECORDING:
      thread_stop_recording(PtThreadIdToDrdThreadId(arg[1]));
      break;

   case VG_USERREQ__SET_PTHREADID:
      thread_set_pthreadid(thread_get_running_tid(), arg[1]);
      break;

   case VG_USERREQ__SET_JOINABLE:
      thread_set_joinable(PtThreadIdToDrdThreadId(arg[1]), (Bool)arg[2]);
      break;

   case VG_USERREQ__POST_THREAD_JOIN:
      tl_assert(arg[1]);
      drd_post_thread_join(thread_get_running_tid(),
                           PtThreadIdToDrdThreadId(arg[1]));
      break;

   case VG_USERREQ__PRE_MUTEX_INIT:
      drd_pre_mutex_init(arg[1], arg[2], arg[3]);
      break;

   case VG_USERREQ__POST_MUTEX_DESTROY:
      drd_post_mutex_destroy(arg[1], arg[2]);
      break;

   case VG_USERREQ__PRE_PTHREAD_MUTEX_LOCK:
      drd_pre_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
      break;

   case VG_USERREQ__POST_PTHREAD_MUTEX_LOCK:
      drd_post_mutex_lock(thread_get_running_tid(), arg[1], arg[2], arg[3]);
      break;

   case VG_USERREQ__PRE_PTHREAD_MUTEX_UNLOCK:
      drd_pre_mutex_unlock(thread_get_running_tid(), arg[1], arg[3]);
      break;

   case VG_USERREQ__SPIN_INIT_OR_UNLOCK:
      drd_spin_init_or_unlock(arg[1], arg[2]);
      break;

   case VG_USERREQ__POST_PTHREAD_COND_INIT:
      drd_post_cond_init(arg[1], arg[2]);
      break;

   case VG_USERREQ__PRE_PTHREAD_COND_DESTROY:
      drd_pre_cond_destroy(arg[1]);
      break;

   case VG_USERREQ__PRE_PTHREAD_COND_WAIT:
      drd_pre_cond_wait(arg[1]/*cond*/, arg[2]/*cond_size*/, arg[3]/*mutex*/);
      break;

   case VG_USERREQ__POST_PTHREAD_COND_WAIT:
      drd_post_cond_wait(arg[1]/*cond*/, arg[3]/*mutex*/,
                         arg[4]/*mutex_size*/);
      break;

   case VG_USERREQ__PRE_PTHREAD_COND_SIGNAL:
      drd_pre_cond_signal(arg[1]);
      break;

   case VG_USERREQ__PRE_PTHREAD_COND_BROADCAST:
      drd_pre_cond_broadcast(arg[1]);
      break;

   default:
      VG_(message)(Vg_DebugMsg, "Unrecognized client request 0x%lx 0x%lx",
                   arg[0], arg[1]);
      tl_assert(0);
      return False;
   }

   *ret = result;
   return True;
}
Example #4
0
static Bool drd_handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret)
{
  UWord result = 0;
  const DrdThreadId drd_tid = thread_get_running_tid();

  tl_assert(vg_tid == VG_(get_running_tid()));
  tl_assert(VgThreadIdToDrdThreadId(vg_tid) == drd_tid);

  switch (arg[0])
  {
  case VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID:
    result = vg_tid;
    break;

  case VG_USERREQ__DRD_GET_DRD_THREAD_ID:
    result = drd_tid;
    break;

  case VG_USERREQ__DRD_START_SUPPRESSION:
    drd_start_suppression(arg[1], arg[1] + arg[2], "client");
    break;

  case VG_USERREQ__DRD_FINISH_SUPPRESSION:
    drd_finish_suppression(arg[1], arg[1] + arg[2]);
    break;

  case VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK:
  {
    const Addr topmost_sp = highest_used_stack_address(vg_tid);
#if 0
    UInt nframes;
    const UInt n_ips = 20;
    Addr ips[n_ips], sps[n_ips], fps[n_ips];
    Char desc[128];
    unsigned i;

    nframes = VG_(get_StackTrace)(vg_tid, ips, n_ips, sps, fps, 0);

    VG_(message)(Vg_DebugMsg, "thread %d/%d", vg_tid, drd_tid);
    for (i = 0; i < nframes; i++)
    {
      VG_(describe_IP)(ips[i], desc, sizeof(desc));
      VG_(message)(Vg_DebugMsg, "[%2d] sp 0x%09lx fp 0x%09lx ip %s",
                   i, sps[i], fps[i], desc);
    }
#endif
    thread_set_stack_startup(drd_tid, VG_(get_SP)(vg_tid));
    drd_start_suppression(topmost_sp, VG_(thread_get_stack_max)(vg_tid),
                          "stack top");
    break;
  }

  case VG_USERREQ__DRD_START_NEW_SEGMENT:
    thread_new_segment(PtThreadIdToDrdThreadId(arg[1]));
    break;

  case VG_USERREQ__DRD_START_TRACE_ADDR:
    drd_start_tracing_address_range(arg[1], arg[1] + arg[2]);
    break;

  case VG_USERREQ__DRD_STOP_TRACE_ADDR:
    drd_stop_tracing_address_range(arg[1], arg[1] + arg[2]);
    break;

  case VG_USERREQ__DRD_STOP_RECORDING:
    thread_stop_recording(drd_tid);
    break;

  case VG_USERREQ__DRD_START_RECORDING:
    thread_start_recording(drd_tid);
    break;

  case VG_USERREQ__SET_PTHREADID:
    // pthread_self() returns 0 for programs not linked with libpthread.so.
    if (arg[1] != INVALID_POSIX_THREADID)
      thread_set_pthreadid(drd_tid, arg[1]);
    break;

  case VG_USERREQ__SET_JOINABLE:
    thread_set_joinable(PtThreadIdToDrdThreadId(arg[1]), (Bool)arg[2]);
    break;

  case VG_USERREQ__POST_THREAD_JOIN:
    tl_assert(arg[1]);
    drd_post_thread_join(drd_tid,
                         PtThreadIdToDrdThreadId(arg[1]));
    break;

  case VG_USERREQ__PRE_THREAD_CANCEL:
    tl_assert(arg[1]);
    drd_pre_thread_cancel(drd_tid, PtThreadIdToDrdThreadId(arg[1]));
    break;

  case VG_USERREQ__POST_THREAD_CANCEL:
    tl_assert(arg[1]);
    drd_post_thread_cancel(drd_tid, PtThreadIdToDrdThreadId(arg[1]), arg[2]);
    break;

  case VG_USERREQ__PRE_MUTEX_INIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_mutex_init(arg[1], arg[2]);
    break;

  case VG_USERREQ__POST_MUTEX_INIT:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_MUTEX_DESTROY:
    thread_enter_synchr(drd_tid);
    break;

  case VG_USERREQ__POST_MUTEX_DESTROY:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_post_mutex_destroy(arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_MUTEX_LOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_mutex_lock(arg[1], arg[2], arg[3]);
    break;

  case VG_USERREQ__POST_MUTEX_LOCK:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_post_mutex_lock(arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_MUTEX_UNLOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_mutex_unlock(arg[1], arg[2]);
    break;

  case VG_USERREQ__POST_MUTEX_UNLOCK:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_spin_init_or_unlock(arg[1]);
    break;

  case VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_COND_INIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_cond_init(arg[1]);
    break;

  case VG_USERREQ__POST_COND_INIT:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_COND_DESTROY:
    thread_enter_synchr(drd_tid);
    break;

  case VG_USERREQ__POST_COND_DESTROY:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_post_cond_destroy(arg[1]);
    break;

  case VG_USERREQ__PRE_COND_WAIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_cond_wait(arg[1], arg[2], arg[3]);
    break;

  case VG_USERREQ__POST_COND_WAIT:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_post_cond_wait(arg[1], arg[2], arg[3]);
    break;

  case VG_USERREQ__PRE_COND_SIGNAL:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_cond_signal(arg[1]);
    break;

  case VG_USERREQ__POST_COND_SIGNAL:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_COND_BROADCAST:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_pre_cond_broadcast(arg[1]);
    break;

  case VG_USERREQ__POST_COND_BROADCAST:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_SEM_INIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_semaphore_init(arg[1], arg[2], arg[3]);
    break;

  case VG_USERREQ__POST_SEM_INIT:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_SEM_DESTROY:
    thread_enter_synchr(drd_tid);
    break;

  case VG_USERREQ__POST_SEM_DESTROY:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_semaphore_destroy(arg[1]);
    break;

  case VG_USERREQ__PRE_SEM_WAIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_semaphore_pre_wait(drd_tid, arg[1]);
    break;

  case VG_USERREQ__POST_SEM_WAIT:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_semaphore_post_wait(drd_tid, arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_SEM_POST:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_semaphore_pre_post(drd_tid, arg[1]);
    break;

  case VG_USERREQ__POST_SEM_POST:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_semaphore_post_post(drd_tid, arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_BARRIER_INIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_barrier_init(arg[1], arg[2], arg[3], arg[4]);
    break;

  case VG_USERREQ__POST_BARRIER_INIT:
    thread_leave_synchr(drd_tid);
    break;

  case VG_USERREQ__PRE_BARRIER_DESTROY:
    thread_enter_synchr(drd_tid);
    break;

  case VG_USERREQ__POST_BARRIER_DESTROY:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_barrier_destroy(arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_BARRIER_WAIT:
    if (thread_enter_synchr(drd_tid) == 0)
      drd_barrier_pre_wait(drd_tid, arg[1], arg[2]);
    break;

  case VG_USERREQ__POST_BARRIER_WAIT:
    if (thread_leave_synchr(drd_tid) == 0)
      drd_barrier_post_wait(drd_tid, arg[1], arg[2], arg[3]);
    break;

  case VG_USERREQ__PRE_RWLOCK_INIT:
    rwlock_pre_init(arg[1]);
    break;

  case VG_USERREQ__POST_RWLOCK_DESTROY:
    rwlock_post_destroy(arg[1]);
    break;

  case VG_USERREQ__PRE_RWLOCK_RDLOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      rwlock_pre_rdlock(arg[1]);
    break;

  case VG_USERREQ__POST_RWLOCK_RDLOCK:
    if (thread_leave_synchr(drd_tid) == 0)
      rwlock_post_rdlock(arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_RWLOCK_WRLOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      rwlock_pre_wrlock(arg[1]);
    break;

  case VG_USERREQ__POST_RWLOCK_WRLOCK:
    if (thread_leave_synchr(drd_tid) == 0)
      rwlock_post_wrlock(arg[1], arg[2]);
    break;

  case VG_USERREQ__PRE_RWLOCK_UNLOCK:
    if (thread_enter_synchr(drd_tid) == 0)
      rwlock_pre_unlock(arg[1]);
    break;
      
  case VG_USERREQ__POST_RWLOCK_UNLOCK:
    thread_leave_synchr(drd_tid);
    break;

  default:
    VG_(message)(Vg_DebugMsg, "Unrecognized client request 0x%lx 0x%lx",
                 arg[0], arg[1]);
    tl_assert(0);
    return False;
  }

  *ret = result;
  return True;
}