2012-06-04 21:55:19 +08:00
|
|
|
//===-- tsan_rtl_thread.cc ------------------------------------------------===//
|
2012-05-10 21:48:04 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of ThreadSanitizer (TSan), a race detector.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-06-07 17:50:16 +08:00
|
|
|
#include "sanitizer_common/sanitizer_placement_new.h"
|
2012-05-10 21:48:04 +08:00
|
|
|
#include "tsan_rtl.h"
|
|
|
|
#include "tsan_mman.h"
|
|
|
|
#include "tsan_platform.h"
|
|
|
|
#include "tsan_report.h"
|
|
|
|
#include "tsan_sync.h"
|
|
|
|
|
|
|
|
namespace __tsan {
|
|
|
|
|
2012-07-17 00:03:16 +08:00
|
|
|
#ifndef TSAN_GO
|
2012-05-22 22:34:43 +08:00
|
|
|
const int kThreadQuarantineSize = 16;
|
2012-07-17 00:03:16 +08:00
|
|
|
#else
|
|
|
|
const int kThreadQuarantineSize = 64;
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
static void MaybeReportThreadLeak(ThreadContext *tctx) {
|
|
|
|
if (tctx->detached)
|
|
|
|
return;
|
|
|
|
if (tctx->status != ThreadStatusCreated
|
|
|
|
&& tctx->status != ThreadStatusRunning
|
|
|
|
&& tctx->status != ThreadStatusFinished)
|
|
|
|
return;
|
|
|
|
ScopedReport rep(ReportTypeThreadLeak);
|
|
|
|
rep.AddThread(tctx);
|
2012-10-05 23:51:32 +08:00
|
|
|
OutputReport(CTX(), rep);
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadFinalize(ThreadState *thr) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
if (!flags()->report_thread_leaks)
|
|
|
|
return;
|
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
2012-05-11 22:42:24 +08:00
|
|
|
for (unsigned i = 0; i < kMaxTid; i++) {
|
2012-05-10 21:48:04 +08:00
|
|
|
ThreadContext *tctx = ctx->threads[i];
|
|
|
|
if (tctx == 0)
|
|
|
|
continue;
|
|
|
|
MaybeReportThreadLeak(tctx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-08 00:41:57 +08:00
|
|
|
int ThreadCount(ThreadState *thr) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
int cnt = 0;
|
|
|
|
for (unsigned i = 0; i < kMaxTid; i++) {
|
|
|
|
ThreadContext *tctx = ctx->threads[i];
|
|
|
|
if (tctx == 0)
|
|
|
|
continue;
|
|
|
|
if (tctx->status != ThreadStatusCreated
|
|
|
|
&& tctx->status != ThreadStatusRunning)
|
|
|
|
continue;
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2012-05-10 21:48:04 +08:00
|
|
|
static void ThreadDead(ThreadState *thr, ThreadContext *tctx) {
|
|
|
|
Context *ctx = CTX();
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
CHECK(tctx->status == ThreadStatusRunning
|
|
|
|
|| tctx->status == ThreadStatusFinished);
|
2012-06-06 21:11:29 +08:00
|
|
|
DPrintf("#%d: ThreadDead uid=%zu\n", thr->tid, tctx->user_id);
|
2012-05-10 21:48:04 +08:00
|
|
|
tctx->status = ThreadStatusDead;
|
|
|
|
tctx->user_id = 0;
|
|
|
|
tctx->sync.Reset();
|
|
|
|
|
|
|
|
// Put to dead list.
|
|
|
|
tctx->dead_next = 0;
|
|
|
|
if (ctx->dead_list_size == 0)
|
|
|
|
ctx->dead_list_head = tctx;
|
|
|
|
else
|
|
|
|
ctx->dead_list_tail->dead_next = tctx;
|
|
|
|
ctx->dead_list_tail = tctx;
|
|
|
|
ctx->dead_list_size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ThreadCreate(ThreadState *thr, uptr pc, uptr uid, bool detached) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
StatInc(thr, StatThreadCreate);
|
|
|
|
int tid = -1;
|
|
|
|
ThreadContext *tctx = 0;
|
|
|
|
if (ctx->dead_list_size > kThreadQuarantineSize
|
|
|
|
|| ctx->thread_seq >= kMaxTid) {
|
|
|
|
if (ctx->dead_list_size == 0) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer: %d thread limit exceeded. Dying.\n",
|
2012-06-06 18:13:27 +08:00
|
|
|
kMaxTid);
|
2012-05-10 21:48:04 +08:00
|
|
|
Die();
|
|
|
|
}
|
|
|
|
StatInc(thr, StatThreadReuse);
|
|
|
|
tctx = ctx->dead_list_head;
|
|
|
|
ctx->dead_list_head = tctx->dead_next;
|
|
|
|
ctx->dead_list_size--;
|
|
|
|
if (ctx->dead_list_size == 0) {
|
|
|
|
CHECK_EQ(tctx->dead_next, 0);
|
|
|
|
ctx->dead_list_head = 0;
|
|
|
|
}
|
|
|
|
CHECK_EQ(tctx->status, ThreadStatusDead);
|
|
|
|
tctx->status = ThreadStatusInvalid;
|
|
|
|
tctx->reuse_count++;
|
2012-05-23 02:07:45 +08:00
|
|
|
tctx->sync.Reset();
|
2012-05-10 21:48:04 +08:00
|
|
|
tid = tctx->tid;
|
2012-05-22 22:34:43 +08:00
|
|
|
DestroyAndFree(tctx->dead_info);
|
2012-05-10 21:48:04 +08:00
|
|
|
} else {
|
|
|
|
StatInc(thr, StatThreadMaxTid);
|
|
|
|
tid = ctx->thread_seq++;
|
|
|
|
void *mem = internal_alloc(MBlockThreadContex, sizeof(ThreadContext));
|
|
|
|
tctx = new(mem) ThreadContext(tid);
|
|
|
|
ctx->threads[tid] = tctx;
|
|
|
|
}
|
|
|
|
CHECK_NE(tctx, 0);
|
|
|
|
CHECK_GE(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
2012-06-06 21:11:29 +08:00
|
|
|
DPrintf("#%d: ThreadCreate tid=%d uid=%zu\n", thr->tid, tid, uid);
|
2012-05-10 21:48:04 +08:00
|
|
|
CHECK_EQ(tctx->status, ThreadStatusInvalid);
|
|
|
|
ctx->alive_threads++;
|
|
|
|
if (ctx->max_alive_threads < ctx->alive_threads) {
|
|
|
|
ctx->max_alive_threads++;
|
|
|
|
CHECK_EQ(ctx->max_alive_threads, ctx->alive_threads);
|
|
|
|
StatInc(thr, StatThreadMaxAlive);
|
|
|
|
}
|
|
|
|
tctx->status = ThreadStatusCreated;
|
|
|
|
tctx->thr = 0;
|
|
|
|
tctx->user_id = uid;
|
|
|
|
tctx->unique_id = ctx->unique_thread_seq++;
|
|
|
|
tctx->detached = detached;
|
|
|
|
if (tid) {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
// Can't increment epoch w/o writing to the trace as well.
|
|
|
|
TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeMop, 0);
|
|
|
|
thr->clock.set(thr->tid, thr->fast_state.epoch());
|
|
|
|
thr->fast_synch_epoch = thr->fast_state.epoch();
|
|
|
|
thr->clock.release(&tctx->sync);
|
|
|
|
StatInc(thr, StatSyncRelease);
|
|
|
|
|
|
|
|
tctx->creation_stack.ObtainCurrent(thr, pc);
|
|
|
|
}
|
|
|
|
return tid;
|
|
|
|
}
|
|
|
|
|
2012-10-02 20:58:14 +08:00
|
|
|
void ThreadStart(ThreadState *thr, int tid, uptr os_id) {
|
2012-05-10 21:48:04 +08:00
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
uptr stk_addr = 0;
|
|
|
|
uptr stk_size = 0;
|
|
|
|
uptr tls_addr = 0;
|
|
|
|
uptr tls_size = 0;
|
2012-05-25 19:15:04 +08:00
|
|
|
GetThreadStackAndTls(tid == 0, &stk_addr, &stk_size, &tls_addr, &tls_size);
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-05-28 15:44:34 +08:00
|
|
|
if (tid) {
|
2012-07-06 00:18:28 +08:00
|
|
|
if (stk_addr && stk_size) {
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 1, stk_addr, stk_size);
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-07-06 00:18:28 +08:00
|
|
|
if (tls_addr && tls_size) {
|
|
|
|
// Check that the thr object is in tls;
|
|
|
|
const uptr thr_beg = (uptr)thr;
|
|
|
|
const uptr thr_end = (uptr)thr + sizeof(*thr);
|
|
|
|
CHECK_GE(thr_beg, tls_addr);
|
|
|
|
CHECK_LE(thr_beg, tls_addr + tls_size);
|
|
|
|
CHECK_GE(thr_end, tls_addr);
|
|
|
|
CHECK_LE(thr_end, tls_addr + tls_size);
|
|
|
|
// Since the thr object is huge, skip it.
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 2, tls_addr, thr_beg - tls_addr);
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 2, thr_end, tls_addr + tls_size - thr_end);
|
|
|
|
}
|
2012-05-28 15:44:34 +08:00
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
|
|
|
|
Lock l(&CTX()->thread_mtx);
|
|
|
|
ThreadContext *tctx = CTX()->threads[tid];
|
|
|
|
CHECK_NE(tctx, 0);
|
|
|
|
CHECK_EQ(tctx->status, ThreadStatusCreated);
|
|
|
|
tctx->status = ThreadStatusRunning;
|
2012-10-02 19:52:05 +08:00
|
|
|
tctx->os_id = os_id;
|
2012-05-10 21:48:04 +08:00
|
|
|
tctx->epoch0 = tctx->epoch1 + 1;
|
|
|
|
tctx->epoch1 = (u64)-1;
|
2012-08-30 21:02:30 +08:00
|
|
|
new(thr) ThreadState(CTX(), tid, tctx->unique_id,
|
|
|
|
tctx->epoch0, stk_addr, stk_size,
|
|
|
|
tls_addr, tls_size);
|
2012-07-17 00:44:47 +08:00
|
|
|
#ifdef TSAN_GO
|
|
|
|
// Setup dynamic shadow stack.
|
|
|
|
const int kInitStackSize = 8;
|
|
|
|
thr->shadow_stack = (uptr*)internal_alloc(MBlockShadowStack,
|
|
|
|
kInitStackSize * sizeof(uptr));
|
|
|
|
thr->shadow_stack_pos = thr->shadow_stack;
|
|
|
|
thr->shadow_stack_end = thr->shadow_stack + kInitStackSize;
|
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
tctx->thr = thr;
|
|
|
|
thr->fast_synch_epoch = tctx->epoch0;
|
|
|
|
thr->clock.set(tid, tctx->epoch0);
|
|
|
|
thr->clock.acquire(&tctx->sync);
|
|
|
|
StatInc(thr, StatSyncAcquire);
|
2012-06-06 21:11:29 +08:00
|
|
|
DPrintf("#%d: ThreadStart epoch=%zu stk_addr=%zx stk_size=%zx "
|
|
|
|
"tls_addr=%zx tls_size=%zx\n",
|
|
|
|
tid, (uptr)tctx->epoch0, stk_addr, stk_size, tls_addr, tls_size);
|
2012-06-29 02:07:46 +08:00
|
|
|
thr->is_alive = true;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadFinish(ThreadState *thr) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
StatInc(thr, StatThreadFinish);
|
|
|
|
// FIXME: Treat it as write.
|
|
|
|
if (thr->stk_addr && thr->stk_size)
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 3, thr->stk_addr, thr->stk_size);
|
|
|
|
if (thr->tls_addr && thr->tls_size) {
|
|
|
|
const uptr thr_beg = (uptr)thr;
|
|
|
|
const uptr thr_end = (uptr)thr + sizeof(*thr);
|
|
|
|
// Since the thr object is huge, skip it.
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 4, thr->tls_addr, thr_beg - thr->tls_addr);
|
|
|
|
MemoryResetRange(thr, /*pc=*/ 5,
|
|
|
|
thr_end, thr->tls_addr + thr->tls_size - thr_end);
|
|
|
|
}
|
2012-06-29 02:07:46 +08:00
|
|
|
thr->is_alive = false;
|
2012-05-10 21:48:04 +08:00
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
ThreadContext *tctx = ctx->threads[thr->tid];
|
|
|
|
CHECK_NE(tctx, 0);
|
|
|
|
CHECK_EQ(tctx->status, ThreadStatusRunning);
|
|
|
|
CHECK_GT(ctx->alive_threads, 0);
|
|
|
|
ctx->alive_threads--;
|
|
|
|
if (tctx->detached) {
|
|
|
|
ThreadDead(thr, tctx);
|
|
|
|
} else {
|
|
|
|
thr->fast_state.IncrementEpoch();
|
|
|
|
// Can't increment epoch w/o writing to the trace as well.
|
|
|
|
TraceAddEvent(thr, thr->fast_state.epoch(), EventTypeMop, 0);
|
|
|
|
thr->clock.set(thr->tid, thr->fast_state.epoch());
|
|
|
|
thr->fast_synch_epoch = thr->fast_state.epoch();
|
|
|
|
thr->clock.release(&tctx->sync);
|
|
|
|
StatInc(thr, StatSyncRelease);
|
|
|
|
tctx->status = ThreadStatusFinished;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save from info about the thread.
|
2012-05-22 22:34:43 +08:00
|
|
|
tctx->dead_info = new(internal_alloc(MBlockDeadInfo, sizeof(ThreadDeadInfo)))
|
|
|
|
ThreadDeadInfo();
|
2012-06-28 05:00:23 +08:00
|
|
|
internal_memcpy(&tctx->dead_info->trace.events[0],
|
2012-05-10 21:48:04 +08:00
|
|
|
&thr->trace.events[0], sizeof(thr->trace.events));
|
|
|
|
for (int i = 0; i < kTraceParts; i++) {
|
2012-05-22 22:34:43 +08:00
|
|
|
tctx->dead_info->trace.headers[i].stack0.CopyFrom(
|
2012-05-10 21:48:04 +08:00
|
|
|
thr->trace.headers[i].stack0);
|
|
|
|
}
|
2012-05-23 02:07:45 +08:00
|
|
|
tctx->epoch1 = thr->fast_state.epoch();
|
2012-05-10 21:48:04 +08:00
|
|
|
|
2012-08-17 03:36:45 +08:00
|
|
|
#ifndef TSAN_GO
|
2012-08-15 23:35:15 +08:00
|
|
|
AlloctorThreadFinish(thr);
|
2012-08-17 03:36:45 +08:00
|
|
|
#endif
|
2012-05-10 21:48:04 +08:00
|
|
|
thr->~ThreadState();
|
|
|
|
StatAggregate(ctx->stat, thr->stat);
|
|
|
|
tctx->thr = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ThreadTid(ThreadState *thr, uptr pc, uptr uid) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
2012-05-29 01:32:50 +08:00
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
int res = -1;
|
2012-05-11 22:42:24 +08:00
|
|
|
for (unsigned tid = 0; tid < kMaxTid; tid++) {
|
2012-05-29 01:32:50 +08:00
|
|
|
ThreadContext *tctx = ctx->threads[tid];
|
|
|
|
if (tctx != 0 && tctx->user_id == uid
|
|
|
|
&& tctx->status != ThreadStatusInvalid) {
|
|
|
|
tctx->user_id = 0;
|
|
|
|
res = tid;
|
|
|
|
break;
|
|
|
|
}
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
2012-06-06 21:11:29 +08:00
|
|
|
DPrintf("#%d: ThreadTid uid=%zu tid=%d\n", thr->tid, uid, res);
|
2012-05-29 01:32:50 +08:00
|
|
|
return res;
|
2012-05-10 21:48:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadJoin(ThreadState *thr, uptr pc, int tid) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
CHECK_GT(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
|
|
|
DPrintf("#%d: ThreadJoin tid=%d\n", thr->tid, tid);
|
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
ThreadContext *tctx = ctx->threads[tid];
|
|
|
|
if (tctx->status == ThreadStatusInvalid) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer: join of non-existent thread\n");
|
2012-05-10 21:48:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
CHECK_EQ(tctx->detached, false);
|
|
|
|
CHECK_EQ(tctx->status, ThreadStatusFinished);
|
|
|
|
thr->clock.acquire(&tctx->sync);
|
|
|
|
StatInc(thr, StatSyncAcquire);
|
|
|
|
ThreadDead(thr, tctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThreadDetach(ThreadState *thr, uptr pc, int tid) {
|
|
|
|
CHECK_GT(thr->in_rtl, 0);
|
|
|
|
CHECK_GT(tid, 0);
|
|
|
|
CHECK_LT(tid, kMaxTid);
|
|
|
|
Context *ctx = CTX();
|
|
|
|
Lock l(&ctx->thread_mtx);
|
|
|
|
ThreadContext *tctx = ctx->threads[tid];
|
|
|
|
if (tctx->status == ThreadStatusInvalid) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("ThreadSanitizer: detach of non-existent thread\n");
|
2012-05-10 21:48:04 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (tctx->status == ThreadStatusFinished) {
|
|
|
|
ThreadDead(thr, tctx);
|
|
|
|
} else {
|
|
|
|
tctx->detached = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryAccessRange(ThreadState *thr, uptr pc, uptr addr,
|
|
|
|
uptr size, bool is_write) {
|
|
|
|
if (size == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
u64 *shadow_mem = (u64*)MemToShadow(addr);
|
|
|
|
DPrintf2("#%d: MemoryAccessRange: @%p %p size=%d is_write=%d\n",
|
|
|
|
thr->tid, (void*)pc, (void*)addr,
|
|
|
|
(int)size, is_write);
|
|
|
|
|
|
|
|
#if TSAN_DEBUG
|
|
|
|
if (!IsAppMem(addr)) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Access to non app mem %zx\n", addr);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsAppMem(addr));
|
|
|
|
}
|
|
|
|
if (!IsAppMem(addr + size - 1)) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Access to non app mem %zx\n", addr + size - 1);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsAppMem(addr + size - 1));
|
|
|
|
}
|
|
|
|
if (!IsShadowMem((uptr)shadow_mem)) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Bad shadow addr %p (%zx)\n", shadow_mem, addr);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsShadowMem((uptr)shadow_mem));
|
|
|
|
}
|
|
|
|
if (!IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1))) {
|
2012-11-02 20:17:51 +08:00
|
|
|
Printf("Bad shadow addr %p (%zx)\n",
|
2012-06-06 21:11:29 +08:00
|
|
|
shadow_mem + size * kShadowCnt / 8 - 1, addr + size - 1);
|
2012-05-10 21:48:04 +08:00
|
|
|
DCHECK(IsShadowMem((uptr)(shadow_mem + size * kShadowCnt / 8 - 1)));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
StatInc(thr, StatMopRange);
|
|
|
|
|
|
|
|
FastState fast_state = thr->fast_state;
|
|
|
|
if (fast_state.GetIgnoreBit())
|
|
|
|
return;
|
|
|
|
|
|
|
|
fast_state.IncrementEpoch();
|
|
|
|
thr->fast_state = fast_state;
|
|
|
|
TraceAddEvent(thr, fast_state.epoch(), EventTypeMop, pc);
|
|
|
|
|
|
|
|
bool unaligned = (addr % kShadowCell) != 0;
|
|
|
|
|
|
|
|
// Handle unaligned beginning, if any.
|
|
|
|
for (; addr % kShadowCell && size; addr++, size--) {
|
|
|
|
int const kAccessSizeLog = 0;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
|
2012-11-16 02:49:08 +08:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
|
2012-05-10 21:48:04 +08:00
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
if (unaligned)
|
|
|
|
shadow_mem += kShadowCnt;
|
|
|
|
// Handle middle part, if any.
|
|
|
|
for (; size >= kShadowCell; addr += kShadowCell, size -= kShadowCell) {
|
|
|
|
int const kAccessSizeLog = 3;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(0, kAccessSizeLog);
|
2012-11-16 02:49:08 +08:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
|
2012-05-10 21:48:04 +08:00
|
|
|
shadow_mem, cur);
|
|
|
|
shadow_mem += kShadowCnt;
|
|
|
|
}
|
|
|
|
// Handle ending, if any.
|
|
|
|
for (; size; addr++, size--) {
|
|
|
|
int const kAccessSizeLog = 0;
|
|
|
|
Shadow cur(fast_state);
|
|
|
|
cur.SetWrite(is_write);
|
|
|
|
cur.SetAddr0AndSizeLog(addr & (kShadowCell - 1), kAccessSizeLog);
|
2012-11-16 02:49:08 +08:00
|
|
|
MemoryAccessImpl(thr, addr, kAccessSizeLog, is_write,
|
2012-05-10 21:48:04 +08:00
|
|
|
shadow_mem, cur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryRead1Byte(ThreadState *thr, uptr pc, uptr addr) {
|
|
|
|
MemoryAccess(thr, pc, addr, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite1Byte(ThreadState *thr, uptr pc, uptr addr) {
|
|
|
|
MemoryAccess(thr, pc, addr, 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryRead8Byte(ThreadState *thr, uptr pc, uptr addr) {
|
|
|
|
MemoryAccess(thr, pc, addr, 3, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MemoryWrite8Byte(ThreadState *thr, uptr pc, uptr addr) {
|
|
|
|
MemoryAccess(thr, pc, addr, 3, 1);
|
|
|
|
}
|
|
|
|
} // namespace __tsan
|