sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | This file is part of drd, a data race detector. |
| 3 | |
| 4 | Copyright (C) 2006-2008 Bart Van Assche |
| 5 | bart.vanassche@gmail.com |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or |
| 8 | modify it under the terms of the GNU General Public License as |
| 9 | published by the Free Software Foundation; either version 2 of the |
| 10 | License, or (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, but |
| 13 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307, USA. |
| 21 | |
| 22 | The GNU General Public License is contained in the file COPYING. |
| 23 | */ |
| 24 | |
| 25 | |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 26 | #include "drd_clientreq.h" |
| 27 | #include "drd_cond.h" |
| 28 | #include "drd_mutex.h" |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 29 | #include "drd_semaphore.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 30 | #include "drd_suppression.h" // drd_start_suppression() |
| 31 | #include "drd_thread.h" |
| 32 | #include "drd_track.h" |
bart | 777f7fe | 2008-03-02 17:43:18 +0000 | [diff] [blame] | 33 | #include "drd_rwlock.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 34 | #include "pub_tool_basics.h" // Bool |
bart | b93846e | 2008-04-16 18:17:12 +0000 | [diff] [blame] | 35 | #include "pub_tool_debuginfo.h" // VG_(describe_IP)() |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 36 | #include "pub_tool_libcassert.h" |
| 37 | #include "pub_tool_libcassert.h" // tl_assert() |
| 38 | #include "pub_tool_libcprint.h" // VG_(message)() |
| 39 | #include "pub_tool_machine.h" // VG_(get_SP)() |
| 40 | #include "pub_tool_threadstate.h" |
| 41 | #include "pub_tool_tooliface.h" // VG_(needs_...)() |
| 42 | |
| 43 | |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 44 | static void drd_spin_init_or_unlock(const Addr spinlock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 46 | struct mutex_info* mutex_p = mutex_get(spinlock); |
| 47 | if (mutex_p) |
| 48 | { |
| 49 | mutex_unlock(spinlock, mutex_type_spinlock); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | mutex_init(spinlock, mutex_type_spinlock); |
| 54 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 55 | } |
| 56 | |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 57 | static void drd_pre_cond_wait(const Addr cond, |
bart | 5357fcb | 2008-02-27 15:46:00 +0000 | [diff] [blame] | 58 | const Addr mutex, const MutexT mutex_type) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 59 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 60 | mutex_unlock(mutex, mutex_type); |
| 61 | cond_pre_wait(cond, mutex); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 62 | } |
| 63 | |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 64 | static void drd_post_cond_wait(const Addr cond, |
| 65 | const Addr mutex, |
bart | 3b1ee45 | 2008-02-29 19:28:15 +0000 | [diff] [blame] | 66 | const Bool took_lock) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 67 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 68 | cond_post_wait(cond); |
bart | 4a975e1 | 2008-03-30 13:28:33 +0000 | [diff] [blame] | 69 | mutex_post_lock(mutex, took_lock, True); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | static void drd_pre_cond_signal(const Addr cond) |
| 73 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 74 | cond_pre_signal(cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | static void drd_pre_cond_broadcast(const Addr cond) |
| 78 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 79 | cond_pre_broadcast(cond); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 80 | } |
| 81 | |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 82 | /** Walk the stack up to the highest stack frame, and return the stack pointer |
| 83 | * of the highest stack frame. It is assumed that there are no more than |
| 84 | * ten stack frames above the current frame. This should be no problem |
| 85 | * since this function is either called indirectly from the _init() function |
| 86 | * in vgpreload_exp-drd-*.so or from the thread wrapper for a newly created |
| 87 | * thread. See also drd_pthread_intercepts.c. |
| 88 | */ |
| 89 | static Addr highest_used_stack_address(const ThreadId vg_tid) |
| 90 | { |
| 91 | UInt nframes; |
| 92 | const UInt n_ips = 10; |
bart | d2765d8 | 2008-05-04 11:59:01 +0000 | [diff] [blame] | 93 | UInt i; |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 94 | Addr ips[n_ips], sps[n_ips]; |
bart | 6ad00b7 | 2008-05-02 17:27:08 +0000 | [diff] [blame] | 95 | Addr husa; |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 96 | |
| 97 | nframes = VG_(get_StackTrace)(vg_tid, ips, n_ips, sps, 0, 0); |
bart | d2765d8 | 2008-05-04 11:59:01 +0000 | [diff] [blame] | 98 | tl_assert(1 <= nframes && nframes <= n_ips); |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 99 | |
bart | d2765d8 | 2008-05-04 11:59:01 +0000 | [diff] [blame] | 100 | /* A hack to work around VG_(get_StackTrace)()'s behavior that sometimes */ |
| 101 | /* the topmost stackframes it returns are bogus (this occurs sometimes */ |
| 102 | /* at least on amd64, ppc32 and ppc64). */ |
bart | ab96eca | 2008-05-02 19:12:43 +0000 | [diff] [blame] | 103 | |
bart | d2765d8 | 2008-05-04 11:59:01 +0000 | [diff] [blame] | 104 | husa = sps[0]; |
| 105 | |
bart | 6ad00b7 | 2008-05-02 17:27:08 +0000 | [diff] [blame] | 106 | tl_assert(VG_(thread_get_stack_max)(vg_tid) |
| 107 | - VG_(thread_get_stack_size)(vg_tid) <= husa |
bart | 32fcd8d | 2008-05-02 19:21:02 +0000 | [diff] [blame] | 108 | && husa < VG_(thread_get_stack_max)(vg_tid)); |
bart | d2765d8 | 2008-05-04 11:59:01 +0000 | [diff] [blame] | 109 | |
| 110 | for (i = 1; i < nframes; i++) |
| 111 | { |
| 112 | if (sps[i] == 0) |
| 113 | break; |
| 114 | if (husa < sps[i] && sps[i] < VG_(thread_get_stack_max)(vg_tid)) |
| 115 | husa = sps[i]; |
| 116 | } |
| 117 | |
| 118 | tl_assert(VG_(thread_get_stack_max)(vg_tid) |
| 119 | - VG_(thread_get_stack_size)(vg_tid) <= husa |
| 120 | && husa < VG_(thread_get_stack_max)(vg_tid)); |
| 121 | |
bart | 6ad00b7 | 2008-05-02 17:27:08 +0000 | [diff] [blame] | 122 | return husa; |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 123 | } |
| 124 | |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 125 | static Bool drd_handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 126 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 127 | UWord result = 0; |
| 128 | const DrdThreadId drd_tid = thread_get_running_tid(); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 129 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 130 | tl_assert(vg_tid == VG_(get_running_tid())); |
| 131 | tl_assert(VgThreadIdToDrdThreadId(vg_tid) == drd_tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 132 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 133 | switch (arg[0]) |
| 134 | { |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 135 | case VG_USERREQ__DRD_GET_VALGRIND_THREAD_ID: |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 136 | result = vg_tid; |
| 137 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 138 | |
bart | 5f57be9 | 2008-07-01 08:48:56 +0000 | [diff] [blame] | 139 | case VG_USERREQ__DRD_GET_DRD_THREAD_ID: |
| 140 | result = drd_tid; |
| 141 | break; |
| 142 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 143 | case VG_USERREQ__DRD_START_SUPPRESSION: |
bart | f5bb46a | 2008-03-29 13:18:02 +0000 | [diff] [blame] | 144 | drd_start_suppression(arg[1], arg[1] + arg[2], "client"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 145 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 146 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 147 | case VG_USERREQ__DRD_FINISH_SUPPRESSION: |
bart | f5bb46a | 2008-03-29 13:18:02 +0000 | [diff] [blame] | 148 | drd_finish_suppression(arg[1], arg[1] + arg[2]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 149 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 150 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 151 | case VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK: |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 152 | { |
| 153 | const Addr topmost_sp = highest_used_stack_address(vg_tid); |
bart | 0ff483d | 2008-04-06 13:08:32 +0000 | [diff] [blame] | 154 | #if 0 |
| 155 | UInt nframes; |
| 156 | const UInt n_ips = 20; |
| 157 | Addr ips[n_ips], sps[n_ips], fps[n_ips]; |
bart | b93846e | 2008-04-16 18:17:12 +0000 | [diff] [blame] | 158 | Char desc[128]; |
bart | 0ff483d | 2008-04-06 13:08:32 +0000 | [diff] [blame] | 159 | unsigned i; |
| 160 | |
| 161 | nframes = VG_(get_StackTrace)(vg_tid, ips, n_ips, sps, fps, 0); |
| 162 | |
| 163 | VG_(message)(Vg_DebugMsg, "thread %d/%d", vg_tid, drd_tid); |
| 164 | for (i = 0; i < nframes; i++) |
| 165 | { |
bart | b93846e | 2008-04-16 18:17:12 +0000 | [diff] [blame] | 166 | VG_(describe_IP)(ips[i], desc, sizeof(desc)); |
| 167 | VG_(message)(Vg_DebugMsg, "[%2d] sp 0x%09lx fp 0x%09lx ip %s", |
| 168 | i, sps[i], fps[i], desc); |
bart | 0ff483d | 2008-04-06 13:08:32 +0000 | [diff] [blame] | 169 | } |
| 170 | #endif |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 171 | thread_set_stack_startup(drd_tid, VG_(get_SP)(vg_tid)); |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 172 | drd_start_suppression(topmost_sp, VG_(thread_get_stack_max)(vg_tid), |
| 173 | "stack top"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 174 | break; |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 175 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 176 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 177 | case VG_USERREQ__DRD_START_NEW_SEGMENT: |
| 178 | thread_new_segment(PtThreadIdToDrdThreadId(arg[1])); |
| 179 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 180 | |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 181 | case VG_USERREQ__DRD_START_TRACE_ADDR: |
| 182 | drd_start_tracing_address_range(arg[1], arg[1] + arg[2]); |
| 183 | break; |
| 184 | |
| 185 | case VG_USERREQ__DRD_STOP_TRACE_ADDR: |
| 186 | drd_stop_tracing_address_range(arg[1], arg[1] + arg[2]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 187 | break; |
bart | 5bd9f2d | 2008-03-03 20:31:58 +0000 | [diff] [blame] | 188 | |
bart | bf3a60c | 2008-04-04 19:10:21 +0000 | [diff] [blame] | 189 | case VG_USERREQ__DRD_STOP_RECORDING: |
| 190 | thread_stop_recording(drd_tid); |
| 191 | break; |
| 192 | |
| 193 | case VG_USERREQ__DRD_START_RECORDING: |
| 194 | thread_start_recording(drd_tid); |
| 195 | break; |
| 196 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 197 | case VG_USERREQ__SET_PTHREADID: |
bart | 145fe1c | 2008-04-21 17:12:45 +0000 | [diff] [blame] | 198 | // pthread_self() returns 0 for programs not linked with libpthread.so. |
| 199 | if (arg[1] != INVALID_POSIX_THREADID) |
| 200 | thread_set_pthreadid(drd_tid, arg[1]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 201 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 202 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 203 | case VG_USERREQ__SET_JOINABLE: |
| 204 | thread_set_joinable(PtThreadIdToDrdThreadId(arg[1]), (Bool)arg[2]); |
| 205 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 206 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 207 | case VG_USERREQ__POST_THREAD_JOIN: |
| 208 | tl_assert(arg[1]); |
| 209 | drd_post_thread_join(drd_tid, |
| 210 | PtThreadIdToDrdThreadId(arg[1])); |
| 211 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 212 | |
bart | 0f099cd | 2008-09-27 12:36:48 +0000 | [diff] [blame] | 213 | case VG_USERREQ__PRE_THREAD_CANCEL: |
| 214 | tl_assert(arg[1]); |
| 215 | drd_pre_thread_cancel(drd_tid, PtThreadIdToDrdThreadId(arg[1])); |
| 216 | break; |
| 217 | |
| 218 | case VG_USERREQ__POST_THREAD_CANCEL: |
| 219 | tl_assert(arg[1]); |
| 220 | drd_post_thread_cancel(drd_tid, PtThreadIdToDrdThreadId(arg[1]), arg[2]); |
| 221 | break; |
| 222 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 223 | case VG_USERREQ__PRE_MUTEX_INIT: |
| 224 | if (thread_enter_synchr(drd_tid) == 0) |
| 225 | drd_pre_mutex_init(arg[1], arg[2]); |
| 226 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 227 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 228 | case VG_USERREQ__POST_MUTEX_INIT: |
| 229 | thread_leave_synchr(drd_tid); |
| 230 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 231 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 232 | case VG_USERREQ__PRE_MUTEX_DESTROY: |
| 233 | thread_enter_synchr(drd_tid); |
| 234 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 235 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 236 | case VG_USERREQ__POST_MUTEX_DESTROY: |
| 237 | if (thread_leave_synchr(drd_tid) == 0) |
| 238 | drd_post_mutex_destroy(arg[1], arg[2]); |
| 239 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 240 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 241 | case VG_USERREQ__PRE_MUTEX_LOCK: |
| 242 | if (thread_enter_synchr(drd_tid) == 0) |
bart | 2e3a3c1 | 2008-03-24 08:33:47 +0000 | [diff] [blame] | 243 | drd_pre_mutex_lock(arg[1], arg[2], arg[3]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 244 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 245 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 246 | case VG_USERREQ__POST_MUTEX_LOCK: |
| 247 | if (thread_leave_synchr(drd_tid) == 0) |
| 248 | drd_post_mutex_lock(arg[1], arg[2]); |
| 249 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 250 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 251 | case VG_USERREQ__PRE_MUTEX_UNLOCK: |
| 252 | if (thread_enter_synchr(drd_tid) == 0) |
| 253 | drd_pre_mutex_unlock(arg[1], arg[2]); |
| 254 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 255 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 256 | case VG_USERREQ__POST_MUTEX_UNLOCK: |
| 257 | thread_leave_synchr(drd_tid); |
| 258 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 259 | |
bart | f4f0581 | 2008-07-07 08:10:56 +0000 | [diff] [blame] | 260 | case VG_USERREQ__PRE_SPIN_INIT_OR_UNLOCK: |
| 261 | if (thread_enter_synchr(drd_tid) == 0) |
| 262 | drd_spin_init_or_unlock(arg[1]); |
| 263 | break; |
| 264 | |
| 265 | case VG_USERREQ__POST_SPIN_INIT_OR_UNLOCK: |
| 266 | thread_leave_synchr(drd_tid); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 267 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 268 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 269 | case VG_USERREQ__PRE_COND_INIT: |
bart | 3f4623e | 2008-07-07 16:53:07 +0000 | [diff] [blame] | 270 | if (thread_enter_synchr(drd_tid) == 0) |
| 271 | drd_pre_cond_init(arg[1]); |
| 272 | break; |
| 273 | |
| 274 | case VG_USERREQ__POST_COND_INIT: |
| 275 | thread_leave_synchr(drd_tid); |
| 276 | break; |
| 277 | |
| 278 | case VG_USERREQ__PRE_COND_DESTROY: |
| 279 | thread_enter_synchr(drd_tid); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 280 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 281 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 282 | case VG_USERREQ__POST_COND_DESTROY: |
bart | 3f4623e | 2008-07-07 16:53:07 +0000 | [diff] [blame] | 283 | if (thread_leave_synchr(drd_tid) == 0) |
| 284 | drd_post_cond_destroy(arg[1]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 285 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 286 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 287 | case VG_USERREQ__PRE_COND_WAIT: |
| 288 | if (thread_enter_synchr(drd_tid) == 0) |
| 289 | drd_pre_cond_wait(arg[1], arg[2], arg[3]); |
| 290 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 291 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 292 | case VG_USERREQ__POST_COND_WAIT: |
| 293 | if (thread_leave_synchr(drd_tid) == 0) |
| 294 | drd_post_cond_wait(arg[1], arg[2], arg[3]); |
| 295 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 296 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 297 | case VG_USERREQ__PRE_COND_SIGNAL: |
bart | 3f4623e | 2008-07-07 16:53:07 +0000 | [diff] [blame] | 298 | if (thread_enter_synchr(drd_tid) == 0) |
| 299 | drd_pre_cond_signal(arg[1]); |
| 300 | break; |
| 301 | |
| 302 | case VG_USERREQ__POST_COND_SIGNAL: |
| 303 | thread_leave_synchr(drd_tid); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 304 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 305 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 306 | case VG_USERREQ__PRE_COND_BROADCAST: |
bart | 3f4623e | 2008-07-07 16:53:07 +0000 | [diff] [blame] | 307 | if (thread_enter_synchr(drd_tid) == 0) |
| 308 | drd_pre_cond_broadcast(arg[1]); |
| 309 | break; |
| 310 | |
| 311 | case VG_USERREQ__POST_COND_BROADCAST: |
| 312 | thread_leave_synchr(drd_tid); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 313 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 314 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 315 | case VG_USERREQ__PRE_SEM_INIT: |
| 316 | if (thread_enter_synchr(drd_tid) == 0) |
| 317 | drd_semaphore_init(arg[1], arg[2], arg[3]); |
| 318 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 319 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 320 | case VG_USERREQ__POST_SEM_INIT: |
| 321 | thread_leave_synchr(drd_tid); |
| 322 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 323 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 324 | case VG_USERREQ__PRE_SEM_DESTROY: |
| 325 | thread_enter_synchr(drd_tid); |
| 326 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 327 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 328 | case VG_USERREQ__POST_SEM_DESTROY: |
| 329 | if (thread_leave_synchr(drd_tid) == 0) |
| 330 | drd_semaphore_destroy(arg[1]); |
| 331 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 332 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 333 | case VG_USERREQ__PRE_SEM_WAIT: |
| 334 | if (thread_enter_synchr(drd_tid) == 0) |
| 335 | drd_semaphore_pre_wait(drd_tid, arg[1]); |
| 336 | break; |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 337 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 338 | case VG_USERREQ__POST_SEM_WAIT: |
| 339 | if (thread_leave_synchr(drd_tid) == 0) |
| 340 | drd_semaphore_post_wait(drd_tid, arg[1], arg[2]); |
| 341 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 342 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 343 | case VG_USERREQ__PRE_SEM_POST: |
| 344 | if (thread_enter_synchr(drd_tid) == 0) |
| 345 | drd_semaphore_pre_post(drd_tid, arg[1]); |
| 346 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 347 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 348 | case VG_USERREQ__POST_SEM_POST: |
| 349 | if (thread_leave_synchr(drd_tid) == 0) |
| 350 | drd_semaphore_post_post(drd_tid, arg[1], arg[2]); |
| 351 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 352 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 353 | case VG_USERREQ__PRE_BARRIER_INIT: |
| 354 | if (thread_enter_synchr(drd_tid) == 0) |
| 355 | drd_barrier_init(arg[1], arg[2], arg[3], arg[4]); |
| 356 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 357 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 358 | case VG_USERREQ__POST_BARRIER_INIT: |
| 359 | thread_leave_synchr(drd_tid); |
| 360 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 361 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 362 | case VG_USERREQ__PRE_BARRIER_DESTROY: |
| 363 | thread_enter_synchr(drd_tid); |
| 364 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 365 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 366 | case VG_USERREQ__POST_BARRIER_DESTROY: |
| 367 | if (thread_leave_synchr(drd_tid) == 0) |
| 368 | drd_barrier_destroy(arg[1], arg[2]); |
| 369 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 370 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 371 | case VG_USERREQ__PRE_BARRIER_WAIT: |
| 372 | if (thread_enter_synchr(drd_tid) == 0) |
| 373 | drd_barrier_pre_wait(drd_tid, arg[1], arg[2]); |
| 374 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 375 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 376 | case VG_USERREQ__POST_BARRIER_WAIT: |
| 377 | if (thread_leave_synchr(drd_tid) == 0) |
| 378 | drd_barrier_post_wait(drd_tid, arg[1], arg[2], arg[3]); |
| 379 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 380 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 381 | case VG_USERREQ__PRE_RWLOCK_INIT: |
| 382 | rwlock_pre_init(arg[1]); |
| 383 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 384 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 385 | case VG_USERREQ__POST_RWLOCK_DESTROY: |
| 386 | rwlock_post_destroy(arg[1]); |
| 387 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 388 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 389 | case VG_USERREQ__PRE_RWLOCK_RDLOCK: |
| 390 | if (thread_enter_synchr(drd_tid) == 0) |
| 391 | rwlock_pre_rdlock(arg[1]); |
| 392 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 393 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 394 | case VG_USERREQ__POST_RWLOCK_RDLOCK: |
| 395 | if (thread_leave_synchr(drd_tid) == 0) |
| 396 | rwlock_post_rdlock(arg[1], arg[2]); |
| 397 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 398 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 399 | case VG_USERREQ__PRE_RWLOCK_WRLOCK: |
| 400 | if (thread_enter_synchr(drd_tid) == 0) |
| 401 | rwlock_pre_wrlock(arg[1]); |
| 402 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 403 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 404 | case VG_USERREQ__POST_RWLOCK_WRLOCK: |
| 405 | if (thread_leave_synchr(drd_tid) == 0) |
| 406 | rwlock_post_wrlock(arg[1], arg[2]); |
| 407 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 408 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 409 | case VG_USERREQ__PRE_RWLOCK_UNLOCK: |
| 410 | if (thread_enter_synchr(drd_tid) == 0) |
| 411 | rwlock_pre_unlock(arg[1]); |
| 412 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 413 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 414 | case VG_USERREQ__POST_RWLOCK_UNLOCK: |
| 415 | thread_leave_synchr(drd_tid); |
| 416 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 417 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 418 | default: |
| 419 | VG_(message)(Vg_DebugMsg, "Unrecognized client request 0x%lx 0x%lx", |
| 420 | arg[0], arg[1]); |
| 421 | tl_assert(0); |
| 422 | return False; |
| 423 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 424 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 425 | *ret = result; |
| 426 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | void drd_clientreq_init(void) |
| 430 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 431 | VG_(needs_client_requests)(drd_handle_client_request); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 432 | } |