[compiler-rt] r189502 - [dfsan] Add custom function for pthread_create.
Peter Collingbourne
peter at pcc.me.uk
Wed Aug 28 13:18:22 PDT 2013
Author: pcc
Date: Wed Aug 28 15:18:22 2013
New Revision: 189502
URL: http://llvm.org/viewvc/llvm-project?rev=189502&view=rev
Log:
[dfsan] Add custom function for pthread_create.
Differential Revision: http://llvm-reviews.chandlerc.com/D1504
Modified:
compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
compiler-rt/trunk/lib/dfsan/done_abilist.txt
compiler-rt/trunk/lib/dfsan/lit_tests/custom.c
Modified: compiler-rt/trunk/lib/dfsan/dfsan_custom.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_custom.cc?rev=189502&r1=189501&r2=189502&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_custom.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_custom.cc Wed Aug 28 15:18:22 2013
@@ -19,6 +19,7 @@
#include <ctype.h>
#include <dlfcn.h>
+#include <pthread.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -272,4 +273,37 @@ __dfsw_dlopen(const char *filename, int
return (void *)map;
}
+struct pthread_create_info {
+ void *(*start_routine_trampoline)(void *, void *, dfsan_label, dfsan_label *);
+ void *start_routine;
+ void *arg;
+};
+
+static void *pthread_create_cb(void *p) {
+ pthread_create_info pci(*(pthread_create_info *)p);
+ free(p);
+ dfsan_label ret_label;
+ return pci.start_routine_trampoline(pci.start_routine, pci.arg, 0,
+ &ret_label);
+}
+
+SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_create(
+ pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start_routine_trampoline)(void *, void *, dfsan_label,
+ dfsan_label *),
+ void *start_routine, void *arg, dfsan_label thread_label,
+ dfsan_label attr_label, dfsan_label start_routine_label,
+ dfsan_label arg_label, dfsan_label *ret_label) {
+ pthread_create_info *pci =
+ (pthread_create_info *)malloc(sizeof(pthread_create_info));
+ pci->start_routine_trampoline = start_routine_trampoline;
+ pci->start_routine = start_routine;
+ pci->arg = arg;
+ int rv = pthread_create(thread, attr, pthread_create_cb, (void *)pci);
+ if (rv != 0)
+ free(pci);
+ *ret_label = 0;
+ return rv;
+}
+
}
Modified: compiler-rt/trunk/lib/dfsan/done_abilist.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/done_abilist.txt?rev=189502&r1=189501&r2=189502&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/done_abilist.txt (original)
+++ compiler-rt/trunk/lib/dfsan/done_abilist.txt Wed Aug 28 15:18:22 2013
@@ -102,6 +102,7 @@ fun:dlopen=custom
fun:read=custom
fun:pread=custom
fun:clock_gettime=custom
+fun:pthread_create=custom
# TODO: custom
fun:snprintf=discard
Modified: compiler-rt/trunk/lib/dfsan/lit_tests/custom.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/lit_tests/custom.c?rev=189502&r1=189501&r2=189502&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/lit_tests/custom.c (original)
+++ compiler-rt/trunk/lib/dfsan/lit_tests/custom.c Wed Aug 28 15:18:22 2013
@@ -5,6 +5,7 @@
#include <sanitizer/dfsan_interface.h>
#include <assert.h>
+#include <pthread.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
@@ -12,6 +13,12 @@
#include <fcntl.h>
#include <unistd.h>
+void *ptcb(void *p) {
+ assert(p == (void *)1);
+ assert(dfsan_get_label((uintptr_t)p) == 0);
+ return (void *)2;
+}
+
int main(void) {
int i = 1;
dfsan_label i_label = dfsan_create_label("i", 0);
@@ -125,5 +132,11 @@ int main(void) {
assert(dfsan_get_label(buf[0]) == 0);
assert(dfsan_get_label(buf[15]) == 0);
+ pthread_t pt;
+ pthread_create(&pt, 0, ptcb, (void *)1);
+ void *cbrv;
+ pthread_join(pt, &cbrv);
+ assert(cbrv == (void *)2);
+
return 0;
}
More information about the llvm-commits
mailing list