sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 1 | /* |
bart | 86562bd | 2009-02-16 19:43:56 +0000 | [diff] [blame] | 2 | This file is part of drd, a thread error detector. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 3 | |
sewardj | 03f8d3f | 2012-08-05 15:46:46 +0000 | [diff] [blame] | 4 | Copyright (C) 2006-2012 Bart Van Assche <bvanassche@acm.org>. |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or |
| 7 | modify it under the terms of the GNU General Public License as |
| 8 | published by the Free Software Foundation; either version 2 of the |
| 9 | License, or (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, but |
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with this program; if not, write to the Free Software |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 19 | 02111-1307, USA. |
| 20 | |
| 21 | The GNU General Public License is contained in the file COPYING. |
| 22 | */ |
| 23 | |
| 24 | |
| 25 | #ifndef __THREAD_H |
| 26 | #define __THREAD_H |
| 27 | |
| 28 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 29 | /* Include directives. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 30 | |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 31 | #include "drd_basics.h" |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 32 | #include "drd_segment.h" |
bart | d59bb0f | 2008-06-08 08:08:31 +0000 | [diff] [blame] | 33 | #include "pub_drd_bitmap.h" |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 34 | #include "pub_tool_libcassert.h" /* tl_assert() */ |
| 35 | #include "pub_tool_stacktrace.h" /* typedef StackTrace */ |
| 36 | #include "pub_tool_threadstate.h" /* VG_N_THREADS */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 37 | |
| 38 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 39 | /* Defines. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 40 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 41 | /** Maximum number of threads DRD keeps information about. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 42 | #define DRD_N_THREADS VG_N_THREADS |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 43 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 44 | /** A number different from any valid DRD thread ID. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 45 | #define DRD_INVALID_THREADID 0 |
| 46 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 47 | /** |
| 48 | * A number different from any valid POSIX thread ID. |
| 49 | * |
| 50 | * @note The PThreadId typedef and the INVALID_POSIX_THREADID depend on the |
| 51 | * operating system and threading library in use. PThreadId must contain at |
| 52 | * least as many bits as pthread_t, and INVALID_POSIX_THREADID |
| 53 | * must be a value that will never be returned by pthread_self(). |
| 54 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 55 | #define INVALID_POSIX_THREADID ((PThreadId)0) |
| 56 | |
| 57 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 58 | /* Type definitions. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 59 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 60 | /** |
| 61 | * POSIX thread ID. The type PThreadId must be at least as wide as |
| 62 | * pthread_t. |
| 63 | */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 64 | typedef UWord PThreadId; |
| 65 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 66 | /** Per-thread information managed by DRD. */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 67 | typedef struct |
| 68 | { |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 69 | struct segment* sg_first;/**< Segment list. */ |
| 70 | struct segment* sg_last; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 71 | ThreadId vg_threadid; /**< Valgrind thread ID. */ |
| 72 | PThreadId pt_threadid; /**< POSIX thread ID. */ |
| 73 | Addr stack_min_min; /**< Lowest value stack pointer ever had. */ |
| 74 | Addr stack_min; /**< Current stack pointer. */ |
| 75 | Addr stack_startup; /**<Stack pointer after pthread_create() finished.*/ |
| 76 | Addr stack_max; /**< Top of stack. */ |
| 77 | SizeT stack_size; /**< Maximum size of stack. */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 78 | char name[64]; /**< User-assigned thread name. */ |
bart | 383d613 | 2010-09-02 14:43:18 +0000 | [diff] [blame] | 79 | Bool on_alt_stack; |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 80 | /** Whether this structure contains valid information. */ |
| 81 | Bool valid; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 82 | /** Indicates whether the Valgrind core knows about this thread. */ |
| 83 | Bool vg_thread_exists; |
| 84 | /** Indicates whether there is an associated POSIX thread ID. */ |
| 85 | Bool posix_thread_exists; |
| 86 | /** |
| 87 | * If true, indicates that there is a corresponding POSIX thread ID and |
| 88 | * a corresponding OS thread that is detached. |
| 89 | */ |
| 90 | Bool detached_posix_thread; |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 91 | /** Wether recording of memory load accesses is currently enabled. */ |
| 92 | Bool is_recording_loads; |
| 93 | /** Wether recording of memory load accesses is currently enabled. */ |
| 94 | Bool is_recording_stores; |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 95 | /** pthread_create() nesting level. */ |
| 96 | Int pthread_create_nesting_level; |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 97 | /** Nesting level of synchronization functions called by the client. */ |
| 98 | Int synchr_nesting; |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 99 | /** Delayed thread deletion sequence number. */ |
| 100 | unsigned deletion_seq; |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 101 | } ThreadInfo; |
| 102 | |
| 103 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 104 | /* |
| 105 | * Local variables of drd_thread.c that are declared here such that these |
| 106 | * can be accessed by inline functions. |
| 107 | */ |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 108 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 109 | /** |
| 110 | * DRD thread ID of the currently running thread. It is crucial for correct |
| 111 | * operation of DRD that this number is always in sync with |
| 112 | * VG_(get_running_tid)(). |
| 113 | */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 114 | extern DrdThreadId DRD_(g_drd_running_tid); |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 115 | /** Per-thread information managed by DRD. */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 116 | extern ThreadInfo DRD_(g_threadinfo)[DRD_N_THREADS]; |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 117 | /** Conflict set for the currently running thread. */ |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 118 | extern struct bitmap* DRD_(g_conflict_set); |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 119 | |
| 120 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 121 | /* Function declarations. */ |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 122 | |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 123 | void DRD_(thread_trace_context_switches)(const Bool t); |
| 124 | void DRD_(thread_trace_conflict_set)(const Bool t); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 125 | void DRD_(thread_trace_conflict_set_bm)(const Bool t); |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 126 | Bool DRD_(thread_get_trace_fork_join)(void); |
| 127 | void DRD_(thread_set_trace_fork_join)(const Bool t); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 128 | void DRD_(thread_set_segment_merging)(const Bool m); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 129 | int DRD_(thread_get_segment_merge_interval)(void); |
| 130 | void DRD_(thread_set_segment_merge_interval)(const int i); |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 131 | void DRD_(thread_set_join_list_vol)(const int jlv); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 132 | |
bart | e278ab5 | 2012-01-24 18:28:55 +0000 | [diff] [blame] | 133 | void DRD_(thread_init)(void); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 134 | DrdThreadId DRD_(VgThreadIdToDrdThreadId)(const ThreadId tid); |
| 135 | DrdThreadId DRD_(NewVgThreadIdToDrdThreadId)(const ThreadId tid); |
| 136 | DrdThreadId DRD_(PtThreadIdToDrdThreadId)(const PThreadId tid); |
| 137 | ThreadId DRD_(DrdThreadIdToVgThreadId)(const DrdThreadId tid); |
| 138 | DrdThreadId DRD_(thread_pre_create)(const DrdThreadId creator, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 139 | const ThreadId vg_created); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 140 | DrdThreadId DRD_(thread_post_create)(const ThreadId vg_created); |
bart | 09dc13f | 2009-02-14 15:13:31 +0000 | [diff] [blame] | 141 | void DRD_(thread_post_join)(DrdThreadId drd_joiner, DrdThreadId drd_joinee); |
bart | 9194e93 | 2011-02-09 11:55:12 +0000 | [diff] [blame] | 142 | void DRD_(thread_delete)(const DrdThreadId tid, Bool detached); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 143 | void DRD_(thread_finished)(const DrdThreadId tid); |
bart | 5c7e6b6 | 2011-02-03 17:47:50 +0000 | [diff] [blame] | 144 | void DRD_(drd_thread_atfork_child)(const DrdThreadId tid); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 145 | void DRD_(thread_pre_cancel)(const DrdThreadId tid); |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 146 | void DRD_(thread_set_stack_startup)(const DrdThreadId tid, |
| 147 | const Addr stack_startup); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 148 | Addr DRD_(thread_get_stack_min)(const DrdThreadId tid); |
| 149 | Addr DRD_(thread_get_stack_min_min)(const DrdThreadId tid); |
| 150 | Addr DRD_(thread_get_stack_max)(const DrdThreadId tid); |
| 151 | SizeT DRD_(thread_get_stack_size)(const DrdThreadId tid); |
bart | 383d613 | 2010-09-02 14:43:18 +0000 | [diff] [blame] | 152 | Bool DRD_(thread_get_on_alt_stack)(const DrdThreadId tid); |
| 153 | void DRD_(thread_set_on_alt_stack)(const DrdThreadId tid, |
| 154 | const Bool on_alt_stack); |
| 155 | Int DRD_(thread_get_threads_on_alt_stack)(void); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 156 | void DRD_(thread_set_pthreadid)(const DrdThreadId tid, const PThreadId ptid); |
| 157 | Bool DRD_(thread_get_joinable)(const DrdThreadId tid); |
| 158 | void DRD_(thread_set_joinable)(const DrdThreadId tid, const Bool joinable); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 159 | void DRD_(thread_entering_pthread_create)(const DrdThreadId tid); |
| 160 | void DRD_(thread_left_pthread_create)(const DrdThreadId tid); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 161 | const char* DRD_(thread_get_name)(const DrdThreadId tid); |
| 162 | void DRD_(thread_set_name)(const DrdThreadId tid, const char* const name); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 163 | void DRD_(thread_set_vg_running_tid)(const ThreadId vg_tid); |
| 164 | void DRD_(thread_set_running_tid)(const ThreadId vg_tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 165 | const DrdThreadId drd_tid); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 166 | int DRD_(thread_enter_synchr)(const DrdThreadId tid); |
| 167 | int DRD_(thread_leave_synchr)(const DrdThreadId tid); |
| 168 | int DRD_(thread_get_synchr_nesting_count)(const DrdThreadId tid); |
| 169 | void DRD_(thread_new_segment)(const DrdThreadId tid); |
| 170 | VectorClock* DRD_(thread_get_vc)(const DrdThreadId tid); |
| 171 | void DRD_(thread_get_latest_segment)(Segment** sg, const DrdThreadId tid); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 172 | void DRD_(thread_combine_vc_join)(const DrdThreadId joiner, |
| 173 | const DrdThreadId joinee); |
bart | f6ec1fe | 2009-06-21 18:07:35 +0000 | [diff] [blame] | 174 | void DRD_(thread_new_segment_and_combine_vc)(DrdThreadId tid, |
| 175 | const Segment* sg); |
bart | 8f822af | 2009-06-08 18:20:42 +0000 | [diff] [blame] | 176 | void DRD_(thread_update_conflict_set)(const DrdThreadId tid, |
| 177 | const VectorClock* const old_vc); |
bart | dfbae6e | 2008-06-05 08:29:53 +0000 | [diff] [blame] | 178 | |
bart | 23ef19d | 2011-03-12 12:34:44 +0000 | [diff] [blame] | 179 | void DRD_(thread_stop_using_mem)(const Addr a1, const Addr a2); |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 180 | void DRD_(thread_set_record_loads)(const DrdThreadId tid, const Bool enabled); |
| 181 | void DRD_(thread_set_record_stores)(const DrdThreadId tid, const Bool enabled); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 182 | void DRD_(thread_print_all)(void); |
| 183 | void DRD_(thread_report_races)(const DrdThreadId tid); |
| 184 | void DRD_(thread_report_races_segment)(const DrdThreadId tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 185 | const Segment* const p); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 186 | void DRD_(thread_report_all_races)(void); |
| 187 | void DRD_(thread_report_conflicting_segments)(const DrdThreadId tid, |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 188 | const Addr addr, |
| 189 | const SizeT size, |
| 190 | const BmAccessTypeT access_type); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 191 | ULong DRD_(thread_get_context_switch_count)(void); |
| 192 | ULong DRD_(thread_get_report_races_count)(void); |
| 193 | ULong DRD_(thread_get_discard_ordered_segments_count)(void); |
bart | 54803fe | 2009-06-21 09:26:27 +0000 | [diff] [blame] | 194 | ULong DRD_(thread_get_compute_conflict_set_count)(void); |
| 195 | ULong DRD_(thread_get_update_conflict_set_count)(void); |
bart | e521466 | 2009-06-21 11:51:23 +0000 | [diff] [blame] | 196 | ULong DRD_(thread_get_update_conflict_set_new_sg_count)(void); |
| 197 | ULong DRD_(thread_get_update_conflict_set_sync_count)(void); |
| 198 | ULong DRD_(thread_get_update_conflict_set_join_count)(void); |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 199 | ULong DRD_(thread_get_conflict_set_bitmap_creation_count)(void); |
| 200 | ULong DRD_(thread_get_conflict_set_bitmap2_creation_count)(void); |
sewardj | af44c82 | 2007-11-25 14:01:38 +0000 | [diff] [blame] | 201 | |
| 202 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 203 | /* Inline function definitions. */ |
| 204 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 205 | /** |
| 206 | * Whether or not the specified DRD thread ID is valid. |
| 207 | * |
| 208 | * A DRD thread ID is valid if and only if the following conditions are met: |
| 209 | * - The ID is a valid index of the DRD_(g_threadinfo)[] array. |
| 210 | * - The ID is not equal to DRD_INVALID_THREADID. |
| 211 | * - The ID refers either to a thread known by the Valgrind core, a joinable |
| 212 | * thread that has not yet been joined or a detached thread. |
| 213 | */ |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 214 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 215 | Bool DRD_(IsValidDrdThreadId)(const DrdThreadId tid) |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 216 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 217 | return (0 <= (int)tid && tid < DRD_N_THREADS && tid != DRD_INVALID_THREADID |
bart | 6d956dc | 2011-07-28 09:54:37 +0000 | [diff] [blame] | 218 | && (DRD_(g_threadinfo)[tid].valid)); |
bart | bf80e12 | 2008-06-06 10:18:24 +0000 | [diff] [blame] | 219 | } |
| 220 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 221 | /** Returns the DRD thread ID of the currently running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 222 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 223 | DrdThreadId DRD_(thread_get_running_tid)(void) |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 224 | { |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 225 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 226 | tl_assert(DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 227 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 228 | return DRD_(g_drd_running_tid); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 229 | } |
| 230 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 231 | /** Returns a pointer to the conflict set for the currently running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 232 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 233 | struct bitmap* DRD_(thread_get_conflict_set)(void) |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 234 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 235 | return DRD_(g_conflict_set); |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 236 | } |
| 237 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 238 | /** |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 239 | * Reports whether or not the currently running client thread is executing code |
| 240 | * inside the pthread_create() function. |
| 241 | */ |
| 242 | static __inline__ |
| 243 | Bool DRD_(running_thread_inside_pthread_create)(void) |
| 244 | { |
| 245 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)] |
| 246 | .pthread_create_nesting_level > 0); |
| 247 | } |
| 248 | |
| 249 | /** |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 250 | * Reports whether or not recording of memory loads is enabled for the |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 251 | * currently running client thread. |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 252 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 253 | static __inline__ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 254 | Bool DRD_(running_thread_is_recording_loads)(void) |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 255 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 256 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 257 | tl_assert(0 <= (int)DRD_(g_drd_running_tid) |
| 258 | && DRD_(g_drd_running_tid) < DRD_N_THREADS |
| 259 | && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
bart | 589f948 | 2008-06-09 15:08:22 +0000 | [diff] [blame] | 260 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 261 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0 |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 262 | && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording_loads); |
| 263 | } |
| 264 | |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 265 | /** |
bart | 31b983d | 2010-02-21 14:52:59 +0000 | [diff] [blame] | 266 | * Reports whether or not recording memory stores is enabled for the |
bart | dd75cdf | 2009-07-24 08:20:10 +0000 | [diff] [blame] | 267 | * currently running client thread. |
| 268 | */ |
bart | d45d995 | 2009-05-31 18:53:54 +0000 | [diff] [blame] | 269 | static __inline__ |
| 270 | Bool DRD_(running_thread_is_recording_stores)(void) |
| 271 | { |
| 272 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
| 273 | tl_assert(0 <= (int)DRD_(g_drd_running_tid) |
| 274 | && DRD_(g_drd_running_tid) < DRD_N_THREADS |
| 275 | && DRD_(g_drd_running_tid) != DRD_INVALID_THREADID); |
| 276 | #endif |
| 277 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].synchr_nesting == 0 |
| 278 | && DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].is_recording_stores); |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 279 | } |
| 280 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 281 | /** |
| 282 | * Update the information about the lowest stack address that has ever been |
| 283 | * accessed by a thread. |
| 284 | */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 285 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 286 | void DRD_(thread_set_stack_min)(const DrdThreadId tid, const Addr stack_min) |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 287 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 288 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 289 | tl_assert(0 <= (int)tid |
| 290 | && tid < DRD_N_THREADS |
| 291 | && tid != DRD_INVALID_THREADID); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 292 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 293 | DRD_(g_threadinfo)[tid].stack_min = stack_min; |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 294 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 295 | /* This function can be called after the thread has been created but */ |
| 296 | /* before drd_post_thread_create() has filled in stack_max. */ |
| 297 | tl_assert(DRD_(g_threadinfo)[tid].stack_min |
| 298 | < DRD_(g_threadinfo)[tid].stack_max |
| 299 | || DRD_(g_threadinfo)[tid].stack_max == 0); |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 300 | #endif |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 301 | if (UNLIKELY(stack_min < DRD_(g_threadinfo)[tid].stack_min_min)) |
| 302 | { |
| 303 | DRD_(g_threadinfo)[tid].stack_min_min = stack_min; |
| 304 | } |
bart | 1ea5fff | 2008-03-16 08:36:23 +0000 | [diff] [blame] | 305 | } |
| 306 | |
bart | 324a23b | 2009-02-15 12:14:52 +0000 | [diff] [blame] | 307 | /** |
| 308 | * Return true if and only if the specified address is on the stack of the |
| 309 | * currently scheduled thread. |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 310 | */ |
| 311 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 312 | Bool DRD_(thread_address_on_stack)(const Addr a) |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 313 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 314 | return (DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_min <= a |
| 315 | && a < DRD_(g_threadinfo)[DRD_(g_drd_running_tid)].stack_max); |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 316 | } |
| 317 | |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 318 | /** |
| 319 | * Return true if and only if the specified address is on the stack of any |
| 320 | * thread. |
| 321 | */ |
| 322 | static __inline__ |
| 323 | Bool DRD_(thread_address_on_any_stack)(const Addr a) |
| 324 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 325 | int i; |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 326 | |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 327 | for (i = 1; i < DRD_N_THREADS; i++) |
| 328 | { |
| 329 | if (DRD_(g_threadinfo)[i].vg_thread_exists |
| 330 | && DRD_(g_threadinfo)[i].stack_min <= a |
| 331 | && a < DRD_(g_threadinfo)[i].stack_max) |
| 332 | { |
| 333 | return True; |
| 334 | } |
| 335 | } |
| 336 | return False; |
bart | 0d6d5c5 | 2009-03-10 09:22:13 +0000 | [diff] [blame] | 337 | } |
| 338 | |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 339 | /** Return a pointer to the latest segment for the specified thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 340 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 341 | Segment* DRD_(thread_get_segment)(const DrdThreadId tid) |
bart | 1a473c7 | 2008-03-13 19:03:38 +0000 | [diff] [blame] | 342 | { |
bart | 8b4b2ee | 2008-06-11 13:17:56 +0000 | [diff] [blame] | 343 | #ifdef ENABLE_DRD_CONSISTENCY_CHECKS |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 344 | tl_assert(0 <= (int)tid && tid < DRD_N_THREADS |
| 345 | && tid != DRD_INVALID_THREADID); |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 346 | tl_assert(DRD_(g_threadinfo)[tid].sg_last); |
bart | 589f948 | 2008-06-09 15:08:22 +0000 | [diff] [blame] | 347 | #endif |
bart | 91b7ec3 | 2012-01-25 20:36:27 +0000 | [diff] [blame] | 348 | return DRD_(g_threadinfo)[tid].sg_last; |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 349 | } |
| 350 | |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 351 | /** Return a pointer to the latest segment for the running thread. */ |
bart | 0886562 | 2008-06-06 14:31:36 +0000 | [diff] [blame] | 352 | static __inline__ |
bart | 62a784c | 2009-02-15 13:11:14 +0000 | [diff] [blame] | 353 | Segment* DRD_(running_thread_get_segment)(void) |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 354 | { |
bart | bedfd23 | 2009-03-26 19:07:15 +0000 | [diff] [blame] | 355 | return DRD_(thread_get_segment)(DRD_(g_drd_running_tid)); |
bart | a79df6e | 2008-03-14 17:07:51 +0000 | [diff] [blame] | 356 | } |
bart | f00a85b | 2008-03-13 18:49:23 +0000 | [diff] [blame] | 357 | |
bart | 86a87df | 2009-03-04 19:26:47 +0000 | [diff] [blame] | 358 | #endif /* __THREAD_H */ |