bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 1 | /* -*- mode: C; c-basic-offset: 3; -*- */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 2 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 3 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 4 | |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 5 | Copyright (C) 2006-2009 Bart Van Assche <bart.vanassche@gmail.com>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 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 | |
| 26 | #ifndef __THREAD_H |
| 27 | #define __THREAD_H |
| 28 | |
| 29 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 30 | /* Include directives. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 31 | |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 32 | #include "drd_basics.h" |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 33 | #include "drd_segment.h" |
bart | d59bb0f | 2008-06-08 08:08:31 +0000 | [diff] [blame] | 34 | #include "pub_drd_bitmap.h" |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 35 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 36 | #include "pub_tool_stacktrace.h" /* typedef StackTrace */ |
| 37 | #include "pub_tool_threadstate.h" /* VG_N_THREADS */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 38 | |
| 39 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 40 | /* Defines. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 41 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 42 | /** Maximum number of threads DRD keeps information about. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 43 | #define DRD_N_THREADS VG_N_THREADS |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 44 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 45 | /** A number different from any valid DRD thread ID. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 46 | #define DRD_INVALID_THREADID 0 |
| 47 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 48 | /** |
| 49 | * A number different from any valid POSIX thread ID. |
| 50 | * |
| 51 | * @note The PThreadId typedef and the INVALID_POSIX_THREADID depend on the |
| 52 | * operating system and threading library in use. PThreadId must contain at |
| 53 | * least as many bits as pthread_t, and INVALID_POSIX_THREADID |
| 54 | * must be a value that will never be returned by pthread_self(). |
| 55 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 56 | #define INVALID_POSIX_THREADID ((PThreadId)0) |
| 57 | |
| 58 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 59 | /* Type definitions. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 60 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 61 | /** |
| 62 | * POSIX thread ID. The type PThreadId must be at least as wide as |
| 63 | * pthread_t. |
| 64 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 65 | typedef UWord PThreadId; |
| 66 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 67 | /** Per-thread information managed by DRD. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 68 | typedef struct |
| 69 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 70 | Segment* first; /**< Pointer to first segment. */ |
| 71 | Segment* last; /**< Pointer to last segment. */ |
| 72 | ThreadId vg_threadid; /**< Valgrind thread ID. */ |
| 73 | PThreadId pt_threadid; /**< POSIX thread ID. */ |
| 74 | Addr stack_min_min; /**< Lowest value stack pointer ever had. */ |
| 75 | Addr stack_min; /**< Current stack pointer. */ |
| 76 | Addr stack_startup; /**<Stack pointer after pthread_create() finished.*/ |
| 77 | Addr stack_max; /**< Top of stack. */ |
| 78 | SizeT stack_size; /**< Maximum size of stack. */ |
| 79 | /** Indicates whether the Valgrind core knows about this thread. */ |
| 80 | Bool vg_thread_exists; |
| 81 | /** Indicates whether there is an associated POSIX thread ID. */ |
| 82 | Bool posix_thread_exists; |
| 83 | /** |
| 84 | * If true, indicates that there is a corresponding POSIX thread ID and |
| 85 | * a corresponding OS thread that is detached. |
| 86 | */ |
| 87 | Bool detached_posix_thread; |
| 88 | /** Wether recording of memory accesses is active. */ |
| 89 | Bool is_recording; |
| 90 | /** Nesting level of synchronization functions called by the client. */ |
| 91 | Int synchr_nesting; |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 92 | } ThreadInfo; |
| 93 | |
| 94 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 95 | /* |
| 96 | * Local variables of drd_thread.c that are declared here such that these |
| 97 | * can be accessed by inline functions. |
| 98 | */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 99 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 100 | /** |
| 101 | * DRD thread ID of the currently running thread. It is crucial for correct |
| 102 | * operation of DRD that this number is always in sync with |
| 103 | * VG_(get_running_tid)(). |
| 104 | */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 105 | extern DrdThreadId DRD_(g_drd_running_tid); |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 106 | /** Per-thread information managed by DRD. */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 107 | extern ThreadInfo DRD_(g_threadinfo)[DRD_N_THREADS]; |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 108 | /** Conflict set for the currently running thread. */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 109 | extern struct bitmap* DRD_(g_conflict_set); |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 110 | |
| 111 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 112 | /* Function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 113 | |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 114 | void DRD_(thread_trace_context_switches)(const Bool t); |
| 115 | void DRD_(thread_trace_conflict_set)(const Bool t); |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 116 | Bool DRD_(thread_get_trace_fork_join)(void); |
| 117 | void DRD_(thread_set_trace_fork_join)(const Bool t); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 118 | void DRD_(thread_set_segment_merging)(const Bool m); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 119 | |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 120 | DrdThreadId DRD_(VgThreadIdToDrdThreadId)(const ThreadId tid); |
| 121 | DrdThreadId DRD_(NewVgThreadIdToDrdThreadId)(const ThreadId tid); |
| 122 | DrdThreadId DRD_(PtThreadIdToDrdThreadId)(const PThreadId tid); |
| 123 | ThreadId DRD_(DrdThreadIdToVgThreadId)(const DrdThreadId tid); |
| 124 | DrdThreadId DRD_(thread_pre_create)(const DrdThreadId creator, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 125 | const ThreadId vg_created); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 126 | DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created); |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 127 | void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 128 | void DRD_(thread_delete)(const DrdThreadId tid); |
| 129 | void DRD_(thread_finished)(const DrdThreadId tid); |
| 130 | void DRD_(thread_pre_cancel)(const DrdThreadId tid); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 131 | void DRD_(thread_set_stack_startup)(const DrdThreadId tid, |
| 132 | const Addr stack_startup); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 133 | Addr DRD_(thread_get_stack_min)(const DrdThreadId tid); |
| 134 | Addr DRD_(thread_get_stack_min_min)(const DrdThreadId tid); |
| 135 | Addr DRD_(thread_get_stack_max)(const DrdThreadId tid); |
| 136 | SizeT DRD_(thread_get_stack_size)(const DrdThreadId tid); |
| 137 | void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid); |
| 138 | Bool DRD_(thread_get_joinable)(const DrdThreadId tid); |
| 139 | void DRD_(thread_set_joinable)(const DrdThreadId tid, const Bool joinable); |
| 140 | void DRD_(thread_set_vg_running_tid)(const ThreadId vg_tid); |
| 141 | void DRD_(thread_set_running_tid)(const ThreadId vg_tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 142 | const DrdThreadId drd_tid); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 143 | int DRD_(thread_enter_synchr)(const DrdThreadId tid); |
| 144 | int DRD_(thread_leave_synchr)(const DrdThreadId tid); |
| 145 | int DRD_(thread_get_synchr_nesting_count)(const DrdThreadId tid); |
| 146 | void DRD_(thread_new_segment)(const DrdThreadId tid); |
| 147 | VectorClock* DRD_(thread_get_vc)(const DrdThreadId tid); |
| 148 | void DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 149 | void DRD_(thread_combine_vc)(const DrdThreadId joiner, |
| 150 | const DrdThreadId joinee); |
| 151 | void DRD_(thread_combine_vc2)(const DrdThreadId tid, |
| 152 | const VectorClock* const vc); |
bart | dfbae6e | 2008-06-05 08:29:53 +0000 | [diff] [blame] | 153 | |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 154 | void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2); |
| 155 | void DRD_(thread_start_recording)(const DrdThreadId tid); |
| 156 | void DRD_(thread_stop_recording)(const DrdThreadId tid); |
| 157 | void DRD_(thread_print_all)(void); |
| 158 | void DRD_(thread_report_races)(const DrdThreadId tid); |
| 159 | void DRD_(thread_report_races_segment)(const DrdThreadId tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 160 | const Segment* const p); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 161 | void DRD_(thread_report_all_races)(void); |
| 162 | void DRD_(thread_report_conflicting_segments)(const DrdThreadId tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 163 | const Addr addr, |
| 164 | const SizeT size, |
| 165 | const BmAccessTypeT access_type); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 166 | ULong DRD_(thread_get_context_switch_count)(void); |
| 167 | ULong DRD_(thread_get_report_races_count)(void); |
| 168 | ULong DRD_(thread_get_discard_ordered_segments_count)(void); |
| 169 | ULong DRD_(thread_get_update_conflict_set_count)(ULong* dsnsc, ULong* dscvc); |
| 170 | ULong DRD_(thread_get_conflict_set_bitmap_creation_count)(void); |
| 171 | ULong DRD_(thread_get_conflict_set_bitmap2_creation_count)(void); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 172 | |
| 173 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 174 | /* Inline function definitions. */ |
| 175 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 176 | /** |
| 177 | * Whether or not the specified DRD thread ID is valid. |
| 178 | * |
| 179 | * A DRD thread ID is valid if and only if the following conditions are met: |
| 180 | * - The ID is a valid index of the DRD_(g_threadinfo)[] array. |
| 181 | * - The ID is not equal to DRD_INVALID_THREADID. |
| 182 | * - The ID refers either to a thread known by the Valgrind core, a joinable |
| 183 | * thread that has not yet been joined or a detached thread. |
| 184 | */ |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 185 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 186 | Bool DRD_(IsValidDrdThreadId)(const DrdThreadId tid) |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 187 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 188 | return (0 <= (int)tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID |
| 189 | && ! (DRD_(g_threadinfo)[tid].vg_thread_exists == False |
| 190 | && DRD_(g_threadinfo)[tid].posix_thread_exists == False |
| 191 | && DRD_(g_threadinfo)[tid].detached_posix_thread == False)); |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 192 | } |
| 193 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 194 | /** Returns the DRD thread ID of the currently running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 195 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 196 | DrdThreadId DRD_(thread_get_running_tid)(void) |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 197 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 198 | tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
| 199 | return DRD_(g_drd_running_tid); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 200 | } |
| 201 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 202 | /** Returns a pointer to the conflict set for the currently running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 203 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 204 | struct bitmap* DRD_(thread_get_conflict_set)(void) |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 205 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 206 | return DRD_(g_conflict_set); |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 207 | } |
| 208 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 209 | /** |
| 210 | * Reports whether or not memory access recording is enabled for the |
| 211 | * currently running thread. |
| 212 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 213 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 214 | Bool DRD_(running_thread_is_recording)(void) |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 215 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 216 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 217 | tl_assert(0 <= (int)DRD_(g_drd_running_tid) |
| 218 | && DRD_(g_drd_running_tid) < DRD_N_THREADS |
| 219 | && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
bart | 589f948 | 2008-06-09 15:08:22 +0000 | [diff] [blame] | 220 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 221 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0 |
| 222 | && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording); |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 223 | } |
| 224 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 225 | /** |
| 226 | * Update the information about the lowest stack address that has ever been |
| 227 | * accessed by a thread. |
| 228 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 229 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 230 | void DRD_(thread_set_stack_min)(const DrdThreadId tid, const Addr stack_min) |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 231 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 232 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 233 | tl_assert(0 <= (int)tid |
| 234 | && tid < DRD_N_THREADS |
| 235 | && tid != DRD_INVALID_THREADID); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 236 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 237 | DRD_(g_threadinfo)[tid].stack_min = stack_min; |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 238 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 239 | /* This function can be called after the thread has been created but */ |
| 240 | /* before drd_post_thread_create() has filled in stack_max. */ |
| 241 | tl_assert(DRD_(g_threadinfo)[tid].stack_min |
| 242 | < DRD_(g_threadinfo)[tid].stack_max |
| 243 | || DRD_(g_threadinfo)[tid].stack_max == 0); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 244 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 245 | if (UNLIKELY(stack_min < DRD_(g_threadinfo)[tid].stack_min_min)) |
| 246 | { |
| 247 | DRD_(g_threadinfo)[tid].stack_min_min = stack_min; |
| 248 | } |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 249 | } |
| 250 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 251 | /** |
| 252 | * Return true if and only if the specified address is on the stack of the |
| 253 | * currently scheduled thread. |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 254 | */ |
| 255 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 256 | Bool DRD_(thread_address_on_stack)(const Addr a) |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 257 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 258 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_min <= a |
| 259 | && a < DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_max); |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 260 | } |
| 261 | |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 262 | /** |
| 263 | * Return true if and only if the specified address is on the stack of any |
| 264 | * thread. |
| 265 | */ |
| 266 | static __inline__ |
| 267 | Bool DRD_(thread_address_on_any_stack)(const Addr a) |
| 268 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 269 | int i; |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 270 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 271 | for (i = 1; i < DRD_N_THREADS; i++) |
| 272 | { |
| 273 | if (DRD_(g_threadinfo)[i].vg_thread_exists |
| 274 | && DRD_(g_threadinfo)[i].stack_min <= a |
| 275 | && a < DRD_(g_threadinfo)[i].stack_max) |
| 276 | { |
| 277 | return True; |
| 278 | } |
| 279 | } |
| 280 | return False; |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 281 | } |
| 282 | |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 283 | /** Return a pointer to the latest segment for the specified thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 284 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 285 | Segment* DRD_(thread_get_segment)(const DrdThreadId tid) |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 286 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 287 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 288 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 289 | && tid != DRD_INVALID_THREADID); |
| 290 | tl_assert(DRD_(g_threadinfo)[tid].last); |
bart | 589f948 | 2008-06-09 15:08:22 +0000 | [diff] [blame] | 291 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 292 | return DRD_(g_threadinfo)[tid].last; |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 293 | } |
| 294 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 295 | /** Return a pointer to the latest segment for the running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 296 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 297 | Segment* DRD_(running_thread_get_segment)(void) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 298 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame^] | 299 | return DRD_(thread_get_segment)(DRD_(g_drd_running_tid)); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 300 | } |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 301 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 302 | #endif /* __THREAD_H */ |