forked from OSchip/llvm-project
tsan: add memory access functions that accept pc
This is required for Java support, as real PCs don't work for Java. llvm-svn: 236484
This commit is contained in:
parent
1d526a613d
commit
da6d5b919d
|
@ -38,6 +38,16 @@ void __tsan_write16(void *addr) {
|
|||
MemoryWrite(cur_thread(), CALLERPC, (uptr)addr + 8, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_read16_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_write16_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr + 8, kSizeLog8);
|
||||
}
|
||||
|
||||
// __tsan_unaligned_read/write calls are emitted by compiler.
|
||||
|
||||
void __tsan_unaligned_read2(const void *addr) {
|
||||
|
|
|
@ -51,6 +51,18 @@ SANITIZER_INTERFACE_ATTRIBUTE void __tsan_unaligned_write4(void *addr);
|
|||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_unaligned_write8(void *addr);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_unaligned_write16(void *addr);
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read1_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read2_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read4_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read8_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_read16_pc(void *addr, void *pc);
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write1_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write2_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write4_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write8_pc(void *addr, void *pc);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_write16_pc(void *addr, void *pc);
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE void __tsan_vptr_read(void **vptr_p);
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void __tsan_vptr_update(void **vptr_p, void *new_val);
|
||||
|
|
|
@ -50,6 +50,38 @@ void __tsan_write8(void *addr) {
|
|||
MemoryWrite(cur_thread(), CALLERPC, (uptr)addr, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_read1_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
|
||||
}
|
||||
|
||||
void __tsan_read2_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
|
||||
}
|
||||
|
||||
void __tsan_read4_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
|
||||
}
|
||||
|
||||
void __tsan_read8_pc(void *addr, void *pc) {
|
||||
MemoryRead(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_write1_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog1);
|
||||
}
|
||||
|
||||
void __tsan_write2_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog2);
|
||||
}
|
||||
|
||||
void __tsan_write4_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog4);
|
||||
}
|
||||
|
||||
void __tsan_write8_pc(void *addr, void *pc) {
|
||||
MemoryWrite(cur_thread(), (uptr)pc, (uptr)addr, kSizeLog8);
|
||||
}
|
||||
|
||||
void __tsan_vptr_update(void **vptr_p, void *new_val) {
|
||||
CHECK_EQ(sizeof(vptr_p), 8);
|
||||
if (*vptr_p != new_val) {
|
||||
|
|
|
@ -18,4 +18,7 @@ int __tsan_java_mutex_unlock_rec(jptr addr);
|
|||
int __tsan_java_acquire(jptr addr);
|
||||
int __tsan_java_release(jptr addr);
|
||||
int __tsan_java_release_store(jptr addr);
|
||||
|
||||
void __tsan_read1_pc(jptr addr, jptr pc);
|
||||
void __tsan_write1_pc(jptr addr, jptr pc);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
||||
#include "java.h"
|
||||
|
||||
void foobar() {
|
||||
}
|
||||
|
||||
void barbaz() {
|
||||
}
|
||||
|
||||
void *Thread(void *p) {
|
||||
barrier_wait(&barrier);
|
||||
__tsan_read1_pc((jptr)p, (jptr)foobar + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
barrier_init(&barrier, 2);
|
||||
int const kHeapSize = 1024 * 1024;
|
||||
jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
|
||||
__tsan_java_init(jheap, kHeapSize);
|
||||
const int kBlockSize = 16;
|
||||
__tsan_java_alloc(jheap, kBlockSize);
|
||||
pthread_t th;
|
||||
pthread_create(&th, 0, Thread, (void*)jheap);
|
||||
__tsan_write1_pc((jptr)jheap, (jptr)barbaz + 1);
|
||||
barrier_wait(&barrier);
|
||||
pthread_join(th, 0);
|
||||
__tsan_java_free(jheap, kBlockSize);
|
||||
fprintf(stderr, "DONE\n");
|
||||
return __tsan_java_fini();
|
||||
}
|
||||
|
||||
// CHECK: WARNING: ThreadSanitizer: data race
|
||||
// CHECK: #0 foobar
|
||||
// CHECK: #0 barbaz
|
||||
// CHECK: DONE
|
Loading…
Reference in New Issue