• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*- mode: C; c-basic-offset: 3; -*- */
2 /*
3   This file is part of drd, a thread error detector.
4 
5   Copyright (C) 2006-2010 Bart Van Assche <bvanassche@acm.org>.
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 __DRD_ERROR_H
27 #define __DRD_ERROR_H
28 
29 
30 #include "pub_drd_bitmap.h"     // BmAccessTypeT
31 #include "drd_thread.h"         // DrdThreadId
32 #include "pub_tool_basics.h"    // SizeT
33 #include "pub_tool_debuginfo.h" // SegInfo
34 #include "pub_tool_errormgr.h"  // ExeContext
35 
36 
37 /* DRD error types. */
38 
39 typedef enum {
40 #define STR_DataRaceErr  "ConflictingAccess"
41    DataRaceErr    = 1,
42 #define STR_MutexErr     "MutexErr"
43    MutexErr       = 2,
44 #define STR_CondErr      "CondErr"
45    CondErr        = 3,
46 #define STR_CondDestrErr "CondDestrErr"
47    CondDestrErr   = 4,
48 #define STR_CondRaceErr  "CondRaceErr"
49    CondRaceErr    = 5,
50 #define STR_CondWaitErr  "CondWaitErr"
51    CondWaitErr    = 6,
52 #define STR_SemaphoreErr "SemaphoreErr"
53    SemaphoreErr   = 7,
54 #define STR_BarrierErr   "BarrierErr"
55    BarrierErr     = 8,
56 #define STR_RwlockErr    "RwlockErr"
57    RwlockErr      = 9,
58 #define STR_HoldtimeErr  "HoldtimeErr"
59    HoldtimeErr    = 10,
60 #define STR_GenericErr   "GenericErr"
61    GenericErr     = 11,
62 #define STR_InvalidThreadId "InvalidThreadId"
63    InvalidThreadId = 12,
64 #define STR_UnimpHgClReq  "UnimpHgClReq"
65    UnimpHgClReq   = 13,
66 #define STR_UnimpDrdClReq "UnimpDrdClReq"
67    UnimpDrdClReq  = 14,
68 } DrdErrorKind;
69 
70 /* The classification of a faulting address. */
71 typedef
72 enum {
73    //Undescribed,   // as-yet unclassified
74    eStack,
75    eUnknown,       // classification yielded nothing useful
76    //Freed,
77    eMallocd,
78    eSegment,       // in a segment (as defined in pub_tool_debuginfo.h)
79    //UserG,         // in a user-defined block
80    //Mempool,       // in a mempool
81    //Register,      // in a register;  for Param errors only
82 }
83    AddrKind;
84 
85 /* Records info about a faulting address. */
86 typedef
87 struct {                      // Used by:
88    AddrKind    akind;         //   ALL
89    SizeT       size;          //   ALL
90    PtrdiffT    rwoffset;      //   ALL
91    ExeContext* lastchange;    //   Mallocd
92    DrdThreadId stack_tid;     //   Stack
93    DebugInfo*  debuginfo;     //   Segment
94    Char        name[256];     //   Segment
95    Char        descr[256];    //   Segment
96 } AddrInfo;
97 
98 /*
99  * NOTE: the first member of each error info structure MUST be the thread ID
100  * in which the error has been observed.
101  */
102 typedef struct {
103    DrdThreadId   tid;         // Thread ID of the running thread.
104    Addr          addr;        // Conflicting address in current thread.
105    SizeT         size;        // Size in bytes of conflicting operation.
106    BmAccessTypeT access_type; // Access type: load or store.
107 } DataRaceErrInfo;
108 
109 typedef struct {
110    DrdThreadId tid;
111    Addr        mutex;
112    Int         recursion_count;
113    DrdThreadId owner;
114 } MutexErrInfo;
115 
116 typedef struct {
117    DrdThreadId tid;
118    Addr        cond;
119 } CondErrInfo;
120 
121 typedef struct {
122    DrdThreadId tid;
123    Addr        cond;
124    Addr        mutex;
125    DrdThreadId owner;
126 } CondDestrErrInfo;
127 
128 typedef struct {
129    DrdThreadId tid;
130    Addr        cond;
131    Addr        mutex;
132 } CondRaceErrInfo;
133 
134 typedef struct {
135    DrdThreadId tid;
136    Addr        cond;
137    Addr        mutex1;
138    Addr        mutex2;
139 } CondWaitErrInfo;
140 
141 typedef struct {
142    DrdThreadId tid;
143    Addr        semaphore;
144 } SemaphoreErrInfo;
145 
146 typedef struct {
147    DrdThreadId tid;
148    Addr        barrier;
149    DrdThreadId other_tid;
150    ExeContext* other_context;
151 } BarrierErrInfo;
152 
153 typedef struct {
154    DrdThreadId tid;
155    Addr        rwlock;
156 } RwlockErrInfo;
157 
158 typedef struct {
159    DrdThreadId tid;
160    Addr        synchronization_object;
161    ExeContext* acquired_at;
162    UInt        hold_time_ms;
163    UInt        threshold_ms;
164 } HoldtimeErrInfo;
165 
166 typedef struct {
167    DrdThreadId tid;
168    Addr        addr;
169 } GenericErrInfo;
170 
171 typedef struct {
172    DrdThreadId tid;
173    ULong       ptid;
174 } InvalidThreadIdInfo;
175 
176 typedef struct {
177    DrdThreadId tid;
178    Char*       descr;
179 } UnimpClReqInfo;
180 
181 void DRD_(set_show_conflicting_segments)(const Bool scs);
182 void DRD_(register_error_handlers)(void);
183 
184 
185 #endif /* __DRD_ERROR_H */
186