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 | 721ad7b | 2007-11-30 08:30:29 +0000 | [diff] [blame] | 34 | #include "priv_drd_clientreq.h" |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 35 | #include "pub_tool_basics.h" // Bool |
| 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; |
| 93 | Addr ips[n_ips], sps[n_ips]; |
| 94 | |
| 95 | nframes = VG_(get_StackTrace)(vg_tid, ips, n_ips, sps, 0, 0); |
| 96 | |
| 97 | return (nframes >= 1 ? sps[nframes - 1] : VG_(get_SP)(vg_tid)); |
| 98 | } |
| 99 | |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 100 | static Bool drd_handle_client_request(ThreadId vg_tid, UWord* arg, UWord* ret) |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 101 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 102 | UWord result = 0; |
| 103 | const DrdThreadId drd_tid = thread_get_running_tid(); |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 104 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 105 | tl_assert(vg_tid == VG_(get_running_tid())); |
| 106 | tl_assert(VgThreadIdToDrdThreadId(vg_tid) == drd_tid); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 107 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 108 | switch (arg[0]) |
| 109 | { |
| 110 | case VG_USERREQ__GET_THREAD_SELF: |
| 111 | result = vg_tid; |
| 112 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 113 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 114 | case VG_USERREQ__DRD_START_SUPPRESSION: |
bart | f5bb46a | 2008-03-29 13:18:02 +0000 | [diff] [blame] | 115 | drd_start_suppression(arg[1], arg[1] + arg[2], "client"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 116 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 117 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 118 | case VG_USERREQ__DRD_FINISH_SUPPRESSION: |
bart | f5bb46a | 2008-03-29 13:18:02 +0000 | [diff] [blame] | 119 | drd_finish_suppression(arg[1], arg[1] + arg[2]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 120 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 121 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 122 | case VG_USERREQ__DRD_SUPPRESS_CURRENT_STACK: |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 123 | { |
| 124 | const Addr topmost_sp = highest_used_stack_address(vg_tid); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 125 | thread_set_stack_startup(drd_tid, VG_(get_SP)(vg_tid)); |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 126 | drd_start_suppression(topmost_sp, VG_(thread_get_stack_max)(vg_tid), |
| 127 | "stack top"); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 128 | break; |
bart | f1ac71a | 2008-04-04 16:54:37 +0000 | [diff] [blame] | 129 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 130 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 131 | case VG_USERREQ__DRD_START_NEW_SEGMENT: |
| 132 | thread_new_segment(PtThreadIdToDrdThreadId(arg[1])); |
| 133 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 134 | |
bart | 005dc97 | 2008-03-29 14:42:59 +0000 | [diff] [blame] | 135 | case VG_USERREQ__DRD_START_TRACE_ADDR: |
| 136 | drd_start_tracing_address_range(arg[1], arg[1] + arg[2]); |
| 137 | break; |
| 138 | |
| 139 | case VG_USERREQ__DRD_STOP_TRACE_ADDR: |
| 140 | drd_stop_tracing_address_range(arg[1], arg[1] + arg[2]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 141 | break; |
bart | 5bd9f2d | 2008-03-03 20:31:58 +0000 | [diff] [blame] | 142 | |
bart | bf3a60c | 2008-04-04 19:10:21 +0000 | [diff] [blame] | 143 | case VG_USERREQ__DRD_STOP_RECORDING: |
| 144 | thread_stop_recording(drd_tid); |
| 145 | break; |
| 146 | |
| 147 | case VG_USERREQ__DRD_START_RECORDING: |
| 148 | thread_start_recording(drd_tid); |
| 149 | break; |
| 150 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 151 | case VG_USERREQ__SET_PTHREADID: |
| 152 | thread_set_pthreadid(drd_tid, arg[1]); |
| 153 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 154 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 155 | case VG_USERREQ__SET_JOINABLE: |
| 156 | thread_set_joinable(PtThreadIdToDrdThreadId(arg[1]), (Bool)arg[2]); |
| 157 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 158 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 159 | case VG_USERREQ__POST_THREAD_JOIN: |
| 160 | tl_assert(arg[1]); |
| 161 | drd_post_thread_join(drd_tid, |
| 162 | PtThreadIdToDrdThreadId(arg[1])); |
| 163 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 164 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 165 | case VG_USERREQ__PRE_MUTEX_INIT: |
| 166 | if (thread_enter_synchr(drd_tid) == 0) |
| 167 | drd_pre_mutex_init(arg[1], arg[2]); |
| 168 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 169 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 170 | case VG_USERREQ__POST_MUTEX_INIT: |
| 171 | thread_leave_synchr(drd_tid); |
| 172 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 173 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 174 | case VG_USERREQ__PRE_MUTEX_DESTROY: |
| 175 | thread_enter_synchr(drd_tid); |
| 176 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 177 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 178 | case VG_USERREQ__POST_MUTEX_DESTROY: |
| 179 | if (thread_leave_synchr(drd_tid) == 0) |
| 180 | drd_post_mutex_destroy(arg[1], arg[2]); |
| 181 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 182 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 183 | case VG_USERREQ__PRE_MUTEX_LOCK: |
| 184 | if (thread_enter_synchr(drd_tid) == 0) |
bart | 2e3a3c1 | 2008-03-24 08:33:47 +0000 | [diff] [blame] | 185 | drd_pre_mutex_lock(arg[1], arg[2], arg[3]); |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 186 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 187 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 188 | case VG_USERREQ__POST_MUTEX_LOCK: |
| 189 | if (thread_leave_synchr(drd_tid) == 0) |
| 190 | drd_post_mutex_lock(arg[1], arg[2]); |
| 191 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 192 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 193 | case VG_USERREQ__PRE_MUTEX_UNLOCK: |
| 194 | if (thread_enter_synchr(drd_tid) == 0) |
| 195 | drd_pre_mutex_unlock(arg[1], arg[2]); |
| 196 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 197 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 198 | case VG_USERREQ__POST_MUTEX_UNLOCK: |
| 199 | thread_leave_synchr(drd_tid); |
| 200 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 201 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 202 | case VG_USERREQ__SPIN_INIT_OR_UNLOCK: |
| 203 | tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); |
| 204 | drd_spin_init_or_unlock(arg[1]); |
| 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__PRE_COND_INIT: |
| 208 | tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); |
| 209 | drd_pre_cond_init(arg[1]); |
| 210 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 211 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 212 | case VG_USERREQ__POST_COND_DESTROY: |
| 213 | tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); |
| 214 | drd_post_cond_destroy(arg[1]); |
| 215 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 216 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 217 | case VG_USERREQ__PRE_COND_WAIT: |
| 218 | if (thread_enter_synchr(drd_tid) == 0) |
| 219 | drd_pre_cond_wait(arg[1], arg[2], arg[3]); |
| 220 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 221 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 222 | case VG_USERREQ__POST_COND_WAIT: |
| 223 | if (thread_leave_synchr(drd_tid) == 0) |
| 224 | drd_post_cond_wait(arg[1], arg[2], arg[3]); |
| 225 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 226 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 227 | case VG_USERREQ__PRE_COND_SIGNAL: |
| 228 | tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); |
| 229 | drd_pre_cond_signal(arg[1]); |
| 230 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 231 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 232 | case VG_USERREQ__PRE_COND_BROADCAST: |
| 233 | tl_assert(thread_get_synchr_nesting_count(drd_tid) == 0); |
| 234 | drd_pre_cond_broadcast(arg[1]); |
| 235 | break; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 236 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 237 | case VG_USERREQ__PRE_SEM_INIT: |
| 238 | if (thread_enter_synchr(drd_tid) == 0) |
| 239 | drd_semaphore_init(arg[1], arg[2], arg[3]); |
| 240 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 241 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 242 | case VG_USERREQ__POST_SEM_INIT: |
| 243 | thread_leave_synchr(drd_tid); |
| 244 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 245 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 246 | case VG_USERREQ__PRE_SEM_DESTROY: |
| 247 | thread_enter_synchr(drd_tid); |
| 248 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 249 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 250 | case VG_USERREQ__POST_SEM_DESTROY: |
| 251 | if (thread_leave_synchr(drd_tid) == 0) |
| 252 | drd_semaphore_destroy(arg[1]); |
| 253 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 254 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 255 | case VG_USERREQ__PRE_SEM_WAIT: |
| 256 | if (thread_enter_synchr(drd_tid) == 0) |
| 257 | drd_semaphore_pre_wait(drd_tid, arg[1]); |
| 258 | break; |
bart | 28230a3 | 2008-02-29 17:27:03 +0000 | [diff] [blame] | 259 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 260 | case VG_USERREQ__POST_SEM_WAIT: |
| 261 | if (thread_leave_synchr(drd_tid) == 0) |
| 262 | drd_semaphore_post_wait(drd_tid, arg[1], arg[2]); |
| 263 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 264 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 265 | case VG_USERREQ__PRE_SEM_POST: |
| 266 | if (thread_enter_synchr(drd_tid) == 0) |
| 267 | drd_semaphore_pre_post(drd_tid, arg[1]); |
| 268 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 269 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 270 | case VG_USERREQ__POST_SEM_POST: |
| 271 | if (thread_leave_synchr(drd_tid) == 0) |
| 272 | drd_semaphore_post_post(drd_tid, arg[1], arg[2]); |
| 273 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 274 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 275 | case VG_USERREQ__PRE_BARRIER_INIT: |
| 276 | if (thread_enter_synchr(drd_tid) == 0) |
| 277 | drd_barrier_init(arg[1], arg[2], arg[3], arg[4]); |
| 278 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 279 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 280 | case VG_USERREQ__POST_BARRIER_INIT: |
| 281 | thread_leave_synchr(drd_tid); |
| 282 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 283 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 284 | case VG_USERREQ__PRE_BARRIER_DESTROY: |
| 285 | thread_enter_synchr(drd_tid); |
| 286 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 287 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 288 | case VG_USERREQ__POST_BARRIER_DESTROY: |
| 289 | if (thread_leave_synchr(drd_tid) == 0) |
| 290 | drd_barrier_destroy(arg[1], arg[2]); |
| 291 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 292 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 293 | case VG_USERREQ__PRE_BARRIER_WAIT: |
| 294 | if (thread_enter_synchr(drd_tid) == 0) |
| 295 | drd_barrier_pre_wait(drd_tid, arg[1], arg[2]); |
| 296 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 297 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 298 | case VG_USERREQ__POST_BARRIER_WAIT: |
| 299 | if (thread_leave_synchr(drd_tid) == 0) |
| 300 | drd_barrier_post_wait(drd_tid, arg[1], arg[2], arg[3]); |
| 301 | break; |
sewardj | 8564292 | 2008-01-14 11:54:56 +0000 | [diff] [blame] | 302 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 303 | case VG_USERREQ__PRE_RWLOCK_INIT: |
| 304 | rwlock_pre_init(arg[1]); |
| 305 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 306 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 307 | case VG_USERREQ__POST_RWLOCK_DESTROY: |
| 308 | rwlock_post_destroy(arg[1]); |
| 309 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 310 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 311 | case VG_USERREQ__PRE_RWLOCK_RDLOCK: |
| 312 | if (thread_enter_synchr(drd_tid) == 0) |
| 313 | rwlock_pre_rdlock(arg[1]); |
| 314 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 315 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 316 | case VG_USERREQ__POST_RWLOCK_RDLOCK: |
| 317 | if (thread_leave_synchr(drd_tid) == 0) |
| 318 | rwlock_post_rdlock(arg[1], arg[2]); |
| 319 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 320 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 321 | case VG_USERREQ__PRE_RWLOCK_WRLOCK: |
| 322 | if (thread_enter_synchr(drd_tid) == 0) |
| 323 | rwlock_pre_wrlock(arg[1]); |
| 324 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 325 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 326 | case VG_USERREQ__POST_RWLOCK_WRLOCK: |
| 327 | if (thread_leave_synchr(drd_tid) == 0) |
| 328 | rwlock_post_wrlock(arg[1], arg[2]); |
| 329 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 330 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 331 | case VG_USERREQ__PRE_RWLOCK_UNLOCK: |
| 332 | if (thread_enter_synchr(drd_tid) == 0) |
| 333 | rwlock_pre_unlock(arg[1]); |
| 334 | break; |
bart | 0268dfa | 2008-03-11 20:10:21 +0000 | [diff] [blame] | 335 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 336 | case VG_USERREQ__POST_RWLOCK_UNLOCK: |
| 337 | thread_leave_synchr(drd_tid); |
| 338 | break; |
bart | 0034464 | 2008-03-01 15:27:41 +0000 | [diff] [blame] | 339 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 340 | default: |
| 341 | VG_(message)(Vg_DebugMsg, "Unrecognized client request 0x%lx 0x%lx", |
| 342 | arg[0], arg[1]); |
| 343 | tl_assert(0); |
| 344 | return False; |
| 345 | } |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 346 | |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 347 | *ret = result; |
| 348 | return True; |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | void drd_clientreq_init(void) |
| 352 | { |
bart | 3772a98 | 2008-03-15 08:11:03 +0000 | [diff] [blame] | 353 | VG_(needs_client_requests)(drd_handle_client_request); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 354 | } |