blob: 7d80066257af8904bfde490263016bcf8f86e565 [file] [log] [blame]
Alexey Samsonov3b2f9f42012-06-04 13:55:19 +00001//===-- tsan_rtl_thread.cc ------------------------------------------------===//
Kostya Serebryany4ad375f2012-05-10 13:48:04 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of ThreadSanitizer (TSan), a race detector.
11//
12//===----------------------------------------------------------------------===//
13
Alexey Samsonov8bd90982012-06-07 09:50:16 +000014#include "sanitizer_common/sanitizer_placement_new.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000015#include "tsan_rtl.h"
16#include "tsan_mman.h"
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000017#include "tsan_platform.h"
18#include "tsan_report.h"
19#include "tsan_sync.h"
20
21namespace __tsan {
22
Dmitry Vyukovdc36d692012-07-16 16:03:16 +000023#ifndef TSAN_GO
Dmitry Vyukovf6985e32012-05-22 14:34:43 +000024const int kThreadQuarantineSize = 16;
Dmitry Vyukovdc36d692012-07-16 16:03:16 +000025#else
26const int kThreadQuarantineSize = 64;
27#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000028
29static void MaybeReportThreadLeak(ThreadContext *tctx) {
30 if (tctx->detached)
31 return;
32 if (tctx->status != ThreadStatusCreated
33 && tctx->status != ThreadStatusRunning
34 && tctx->status != ThreadStatusFinished)
35 return;
36 ScopedReport rep(ReportTypeThreadLeak);
37 rep.AddThread(tctx);
Dmitry Vyukov90c9cbf2012-10-05 15:51:32 +000038 OutputReport(CTX(), rep);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000039}
40
41void ThreadFinalize(ThreadState *thr) {
42 CHECK_GT(thr->in_rtl, 0);
43 if (!flags()->report_thread_leaks)
44 return;
45 Context *ctx = CTX();
46 Lock l(&ctx->thread_mtx);
Kostya Serebryany07c48052012-05-11 14:42:24 +000047 for (unsigned i = 0; i < kMaxTid; i++) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000048 ThreadContext *tctx = ctx->threads[i];
49 if (tctx == 0)
50 continue;
51 MaybeReportThreadLeak(tctx);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000052 }
53}
54
Dmitry Vyukov67dc5702012-11-07 16:41:57 +000055int ThreadCount(ThreadState *thr) {
56 CHECK_GT(thr->in_rtl, 0);
57 Context *ctx = CTX();
58 Lock l(&ctx->thread_mtx);
59 int cnt = 0;
60 for (unsigned i = 0; i < kMaxTid; i++) {
61 ThreadContext *tctx = ctx->threads[i];
62 if (tctx == 0)
63 continue;
64 if (tctx->status != ThreadStatusCreated
65 && tctx->status != ThreadStatusRunning)
66 continue;
67 cnt++;
68 }
69 return cnt;
70}
71
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000072static void ThreadDead(ThreadState *thr, ThreadContext *tctx) {
73 Context *ctx = CTX();
74 CHECK_GT(thr->in_rtl, 0);
75 CHECK(tctx->status == ThreadStatusRunning
76 || tctx->status == ThreadStatusFinished);
Alexey Samsonov51ae9832012-06-06 13:11:29 +000077 DPrintf("#%d: ThreadDead uid=%zu\n", thr->tid, tctx->user_id);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +000078 tctx->status = ThreadStatusDead;
79 tctx->user_id = 0;
80 tctx->sync.Reset();
81
82 // Put to dead list.
83 tctx->dead_next = 0;
84 if (ctx->dead_list_size == 0)
85 ctx->dead_list_head = tctx;
86 else
87 ctx->dead_list_tail->dead_next = tctx;
88 ctx->dead_list_tail = tctx;
89 ctx->dead_list_size++;
90}
91
92int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) {
93 CHECK_GT(thr->in_rtl, 0);
94 Context *ctx = CTX();
95 Lock l(&ctx->thread_mtx);
96 StatInc(thr, StatThreadCreate);
97 int tid = -1;
98 ThreadContext *tctx = 0;
99 if (ctx->dead_list_size > kThreadQuarantineSize
100 || ctx->thread_seq >= kMaxTid) {
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000101 // Reusing old thread descriptor and tid.
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000102 if (ctx->dead_list_size == 0) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000103 Printf("ThreadSanitizer: %d thread limit exceeded. Dying.\n",
Alexey Samsonovac4c2902012-06-06 10:13:27 +0000104 kMaxTid);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000105 Die();
106 }
107 StatInc(thr, StatThreadReuse);
108 tctx = ctx->dead_list_head;
109 ctx->dead_list_head = tctx->dead_next;
110 ctx->dead_list_size--;
111 if (ctx->dead_list_size == 0) {
112 CHECK_EQ(tctx->dead_next, 0);
113 ctx->dead_list_head = 0;
114 }
115 CHECK_EQ(tctx->status, ThreadStatusDead);
116 tctx->status = ThreadStatusInvalid;
117 tctx->reuse_count++;
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000118 tctx->sync.Reset();
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000119 tid = tctx->tid;
Dmitry Vyukovf6985e32012-05-22 14:34:43 +0000120 DestroyAndFree(tctx->dead_info);
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000121 if (tctx->name) {
122 internal_free(tctx->name);
123 tctx->name = 0;
124 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000125 } else {
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000126 // Allocating new thread descriptor and tid.
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000127 StatInc(thr, StatThreadMaxTid);
128 tid = ctx->thread_seq++;
129 void *mem = internal_alloc(MBlockThreadContex, sizeof(ThreadContext));
130 tctx = new(mem) ThreadContext(tid);
131 ctx->threads[tid] = tctx;
Dmitry Vyukove1a7f332012-11-28 12:19:50 +0000132 MapThreadTrace(GetThreadTrace(tid), TraceSize() * sizeof(Event));
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000133 }
134 CHECK_NE(tctx, 0);
135 CHECK_GE(tid, 0);
136 CHECK_LT(tid, kMaxTid);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000137 DPrintf("#%d: ThreadCreate tid=%d uid=%zu\n", thr->tid, tid, uid);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000138 CHECK_EQ(tctx->status, ThreadStatusInvalid);
139 ctx->alive_threads++;
140 if (ctx->max_alive_threads < ctx->alive_threads) {
141 ctx->max_alive_threads++;
142 CHECK_EQ(ctx->max_alive_threads, ctx->alive_threads);
143 StatInc(thr, StatThreadMaxAlive);
144 }
145 tctx->status = ThreadStatusCreated;
146 tctx->thr = 0;
147 tctx->user_id = uid;
148 tctx->unique_id = ctx->unique_thread_seq++;
149 tctx->detached = detached;
150 if (tid) {
151 thr->fast_state.IncrementEpoch();
152 // Can't increment epoch w/o writing to the trace as well.
Dmitry Vyukov2429b022012-11-28 10:35:31 +0000153 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000154 thr->clock.set(thr->tid, thr->fast_state.epoch());
155 thr->fast_synch_epoch = thr->fast_state.epoch();
156 thr->clock.release(&tctx->sync);
157 StatInc(thr, StatSyncRelease);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000158 tctx->creation_stack.ObtainCurrent(thr, pc);
159 }
160 return tid;
161}
162
Dmitry Vyukov56faa552012-10-02 12:58:14 +0000163void ThreadStart(ThreadState *thr, int tid, uptr os_id) {
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000164 CHECK_GT(thr->in_rtl, 0);
165 uptr stk_addr = 0;
166 uptr stk_size = 0;
167 uptr tls_addr = 0;
168 uptr tls_size = 0;
Dmitry Vyukov7339eb12012-05-25 11:15:04 +0000169 GetThreadStackAndTls(tid == 0, &stk_addr, &stk_size, &tls_addr, &tls_size);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000170
Dmitry Vyukov2d4e3c12012-05-28 07:44:34 +0000171 if (tid) {
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000172 if (stk_addr && stk_size) {
173 MemoryResetRange(thr, /*pc=*/ 1, stk_addr, stk_size);
174 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000175
Dmitry Vyukov03d32ec2012-07-05 16:18:28 +0000176 if (tls_addr && tls_size) {
177 // Check that the thr object is in tls;
178 const uptr thr_beg = (uptr)thr;
179 const uptr thr_end = (uptr)thr + sizeof(*thr);
180 CHECK_GE(thr_beg, tls_addr);
181 CHECK_LE(thr_beg, tls_addr + tls_size);
182 CHECK_GE(thr_end, tls_addr);
183 CHECK_LE(thr_end, tls_addr + tls_size);
184 // Since the thr object is huge, skip it.
185 MemoryResetRange(thr, /*pc=*/ 2, tls_addr, thr_beg - tls_addr);
186 MemoryResetRange(thr, /*pc=*/ 2, thr_end, tls_addr + tls_size - thr_end);
187 }
Dmitry Vyukov2d4e3c12012-05-28 07:44:34 +0000188 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000189
190 Lock l(&CTX()->thread_mtx);
191 ThreadContext *tctx = CTX()->threads[tid];
192 CHECK_NE(tctx, 0);
193 CHECK_EQ(tctx->status, ThreadStatusCreated);
194 tctx->status = ThreadStatusRunning;
Dmitry Vyukov27d5b372012-10-02 11:52:05 +0000195 tctx->os_id = os_id;
Dmitry Vyukov55b47ca2012-12-04 12:19:53 +0000196 // RoundUp so that one trace part does not contain events
197 // from different threads.
198 tctx->epoch0 = RoundUp(tctx->epoch1 + 1, kTracePartSize);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000199 tctx->epoch1 = (u64)-1;
Dmitry Vyukov191f2f72012-08-30 13:02:30 +0000200 new(thr) ThreadState(CTX(), tid, tctx->unique_id,
201 tctx->epoch0, stk_addr, stk_size,
202 tls_addr, tls_size);
Dmitry Vyukov5bfac972012-07-16 16:44:47 +0000203#ifdef TSAN_GO
204 // Setup dynamic shadow stack.
205 const int kInitStackSize = 8;
206 thr->shadow_stack = (uptr*)internal_alloc(MBlockShadowStack,
207 kInitStackSize * sizeof(uptr));
208 thr->shadow_stack_pos = thr->shadow_stack;
209 thr->shadow_stack_end = thr->shadow_stack + kInitStackSize;
210#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000211 tctx->thr = thr;
212 thr->fast_synch_epoch = tctx->epoch0;
213 thr->clock.set(tid, tctx->epoch0);
214 thr->clock.acquire(&tctx->sync);
Dmitry Vyukove1a7f332012-11-28 12:19:50 +0000215 thr->fast_state.SetHistorySize(flags()->history_size);
Dmitry Vyukov55b47ca2012-12-04 12:19:53 +0000216 const uptr trace = (tctx->epoch0 / kTracePartSize) % TraceParts();
217 thr->trace.headers[trace].epoch0 = tctx->epoch0;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000218 StatInc(thr, StatSyncAcquire);
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000219 DPrintf("#%d: ThreadStart epoch=%zu stk_addr=%zx stk_size=%zx "
220 "tls_addr=%zx tls_size=%zx\n",
221 tid, (uptr)tctx->epoch0, stk_addr, stk_size, tls_addr, tls_size);
Dmitry Vyukovfa985a02012-06-28 18:07:46 +0000222 thr->is_alive = true;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000223}
224
225void ThreadFinish(ThreadState *thr) {
226 CHECK_GT(thr->in_rtl, 0);
227 StatInc(thr, StatThreadFinish);
228 // FIXME: Treat it as write.
229 if (thr->stk_addr && thr->stk_size)
230 MemoryResetRange(thr, /*pc=*/ 3, thr->stk_addr, thr->stk_size);
231 if (thr->tls_addr && thr->tls_size) {
232 const uptr thr_beg = (uptr)thr;
233 const uptr thr_end = (uptr)thr + sizeof(*thr);
234 // Since the thr object is huge, skip it.
235 MemoryResetRange(thr, /*pc=*/ 4, thr->tls_addr, thr_beg - thr->tls_addr);
236 MemoryResetRange(thr, /*pc=*/ 5,
237 thr_end, thr->tls_addr + thr->tls_size - thr_end);
238 }
Dmitry Vyukovfa985a02012-06-28 18:07:46 +0000239 thr->is_alive = false;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000240 Context *ctx = CTX();
241 Lock l(&ctx->thread_mtx);
242 ThreadContext *tctx = ctx->threads[thr->tid];
243 CHECK_NE(tctx, 0);
244 CHECK_EQ(tctx->status, ThreadStatusRunning);
245 CHECK_GT(ctx->alive_threads, 0);
246 ctx->alive_threads--;
247 if (tctx->detached) {
248 ThreadDead(thr, tctx);
249 } else {
250 thr->fast_state.IncrementEpoch();
251 // Can't increment epoch w/o writing to the trace as well.
Dmitry Vyukov2429b022012-11-28 10:35:31 +0000252 TraceAddEvent(thr, thr->fast_state, EventTypeMop, 0);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000253 thr->clock.set(thr->tid, thr->fast_state.epoch());
254 thr->fast_synch_epoch = thr->fast_state.epoch();
255 thr->clock.release(&tctx->sync);
256 StatInc(thr, StatSyncRelease);
257 tctx->status = ThreadStatusFinished;
258 }
259
260 // Save from info about the thread.
Dmitry Vyukovf6985e32012-05-22 14:34:43 +0000261 tctx->dead_info = new(internal_alloc(MBlockDeadInfo, sizeof(ThreadDeadInfo)))
262 ThreadDeadInfo();
Dmitry Vyukov55b47ca2012-12-04 12:19:53 +0000263 for (uptr i = 0; i < TraceParts(); i++) {
Dmitry Vyukov2429b022012-11-28 10:35:31 +0000264 tctx->dead_info->trace.headers[i].epoch0 = thr->trace.headers[i].epoch0;
Dmitry Vyukovf6985e32012-05-22 14:34:43 +0000265 tctx->dead_info->trace.headers[i].stack0.CopyFrom(
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000266 thr->trace.headers[i].stack0);
267 }
Dmitry Vyukov302cebb2012-05-22 18:07:45 +0000268 tctx->epoch1 = thr->fast_state.epoch();
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000269
Dmitry Vyukov9f143c52012-08-16 19:36:45 +0000270#ifndef TSAN_GO
Dmitry Vyukov954fc8c2012-08-15 15:35:15 +0000271 AlloctorThreadFinish(thr);
Dmitry Vyukov9f143c52012-08-16 19:36:45 +0000272#endif
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000273 thr->~ThreadState();
274 StatAggregate(ctx->stat, thr->stat);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000275 tctx->thr = 0;
276}
277
278int ThreadTid(ThreadState *thr, uptr pc, uptr uid) {
279 CHECK_GT(thr->in_rtl, 0);
Dmitry Vyukov880bb662012-05-28 17:32:50 +0000280 Context *ctx = CTX();
281 Lock l(&ctx->thread_mtx);
282 int res = -1;
Kostya Serebryany07c48052012-05-11 14:42:24 +0000283 for (unsigned tid = 0; tid < kMaxTid; tid++) {
Dmitry Vyukov880bb662012-05-28 17:32:50 +0000284 ThreadContext *tctx = ctx->threads[tid];
285 if (tctx != 0 && tctx->user_id == uid
286 && tctx->status != ThreadStatusInvalid) {
287 tctx->user_id = 0;
288 res = tid;
289 break;
290 }
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000291 }
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000292 DPrintf("#%d: ThreadTid uid=%zu tid=%d\n", thr->tid, uid, res);
Dmitry Vyukov880bb662012-05-28 17:32:50 +0000293 return res;
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000294}
295
296void ThreadJoin(ThreadState *thr, uptr pc, int tid) {
297 CHECK_GT(thr->in_rtl, 0);
298 CHECK_GT(tid, 0);
299 CHECK_LT(tid, kMaxTid);
300 DPrintf("#%d: ThreadJoin tid=%d\n", thr->tid, tid);
301 Context *ctx = CTX();
302 Lock l(&ctx->thread_mtx);
303 ThreadContext *tctx = ctx->threads[tid];
304 if (tctx->status == ThreadStatusInvalid) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000305 Printf("ThreadSanitizer: join of non-existent thread\n");
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000306 return;
307 }
308 CHECK_EQ(tctx->detached, false);
309 CHECK_EQ(tctx->status, ThreadStatusFinished);
310 thr->clock.acquire(&tctx->sync);
311 StatInc(thr, StatSyncAcquire);
312 ThreadDead(thr, tctx);
313}
314
315void ThreadDetach(ThreadState *thr, uptr pc, int tid) {
316 CHECK_GT(thr->in_rtl, 0);
317 CHECK_GT(tid, 0);
318 CHECK_LT(tid, kMaxTid);
319 Context *ctx = CTX();
320 Lock l(&ctx->thread_mtx);
321 ThreadContext *tctx = ctx->threads[tid];
322 if (tctx->status == ThreadStatusInvalid) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000323 Printf("ThreadSanitizer: detach of non-existent thread\n");
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000324 return;
325 }
326 if (tctx->status == ThreadStatusFinished) {
327 ThreadDead(thr, tctx);
328 } else {
329 tctx->detached = true;
330 }
331}
332
Dmitry Vyukov1b469932012-12-04 15:46:05 +0000333void ThreadSetName(ThreadState *thr, const char *name) {
334 Context *ctx = CTX();
335 Lock l(&ctx->thread_mtx);
336 ThreadContext *tctx = ctx->threads[thr->tid];
337 CHECK_NE(tctx, 0);
338 CHECK_EQ(tctx->status, ThreadStatusRunning);
339 if (tctx->name) {
340 internal_free(tctx->name);
341 tctx->name = 0;
342 }
343 if (name)
344 tctx->name = internal_strdup(name);
345}
346
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000347void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr,
348 uptr size, bool is_write) {
349 if (size == 0)
350 return;
351
352 u64 *shadow_mem = (u64*)MemToShadow(addr);
353 DPrintf2("#%d: MemoryAccessRange: @%p %p size=%d is_write=%d\n",
354 thr->tid, (void*)pc, (void*)addr,
355 (int)size, is_write);
356
357#if TSAN_DEBUG
358 if (!IsAppMem(addr)) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000359 Printf("Access to non app mem %zx\n", addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000360 DCHECK(IsAppMem(addr));
361 }
362 if (!IsAppMem(addr + size - 1)) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000363 Printf("Access to non app mem %zx\n", addr + size - 1);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000364 DCHECK(IsAppMem(addr + size - 1));
365 }
366 if (!IsShadowMem((uptr)shadow_mem)) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000367 Printf("Bad shadow addr %p (%zx)\n", shadow_mem, addr);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000368 DCHECK(IsShadowMem((uptr)shadow_mem));
369 }
370 if (!IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1))) {
Alexey Samsonovad9d65f2012-11-02 12:17:51 +0000371 Printf("Bad shadow addr %p (%zx)\n",
Alexey Samsonov51ae9832012-06-06 13:11:29 +0000372 shadow_mem + size * kShadowCnt / 8 - 1, addr + size - 1);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000373 DCHECK(IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1)));
374 }
375#endif
376
377 StatInc(thr, StatMopRange);
378
379 FastState fast_state = thr->fast_state;
380 if (fast_state.GetIgnoreBit())
381 return;
382
383 fast_state.IncrementEpoch();
384 thr->fast_state = fast_state;
Dmitry Vyukov2429b022012-11-28 10:35:31 +0000385 TraceAddEvent(thr, fast_state, EventTypeMop, pc);
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000386
387 bool unaligned = (addr % kShadowCell) != 0;
388
389 // Handle unaligned beginning, if any.
390 for (; addr % kShadowCell && size; addr++, size--) {
391 int const kAccessSizeLog = 0;
392 Shadow cur(fast_state);
393 cur.SetWrite(is_write);
394 cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
Dmitry Vyukov933c9882012-11-15 18:49:08 +0000395 MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000396 shadow_mem, cur);
397 }
398 if (unaligned)
399 shadow_mem += kShadowCnt;
400 // Handle middle part, if any.
401 for (; size >= kShadowCell; addr += kShadowCell, size -= kShadowCell) {
402 int const kAccessSizeLog = 3;
403 Shadow cur(fast_state);
404 cur.SetWrite(is_write);
405 cur.SetAddr0AndSizeLog(0, kAccessSizeLog);
Dmitry Vyukov933c9882012-11-15 18:49:08 +0000406 MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000407 shadow_mem, cur);
408 shadow_mem += kShadowCnt;
409 }
410 // Handle ending, if any.
411 for (; size; addr++, size--) {
412 int const kAccessSizeLog = 0;
413 Shadow cur(fast_state);
414 cur.SetWrite(is_write);
415 cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
Dmitry Vyukov933c9882012-11-15 18:49:08 +0000416 MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
Kostya Serebryany4ad375f2012-05-10 13:48:04 +0000417 shadow_mem, cur);
418 }
419}
420
421void MemoryRead1Byte(ThreadState *thr, uptr pc, uptr addr) {
422 MemoryAccess(thr, pc, addr, 0, 0);
423}
424
425void MemoryWrite1Byte(ThreadState *thr, uptr pc, uptr addr) {
426 MemoryAccess(thr, pc, addr, 0, 1);
427}
428
429void MemoryRead8Byte(ThreadState *thr, uptr pc, uptr addr) {
430 MemoryAccess(thr, pc, addr, 3, 0);
431}
432
433void MemoryWrite8Byte(ThreadState *thr, uptr pc, uptr addr) {
434 MemoryAccess(thr, pc, addr, 3, 1);
435}
436} // namespace __tsan