forked from OSchip/llvm-project
[dfsan] Add custom function for pthread_create.
Differential Revision: http://llvm-reviews.chandlerc.com/D1504 llvm-svn: 189502
This commit is contained in:
parent
8fb5a9113a
commit
3e5524d6c5
|
@ -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 flag, dfsan_label filename_label,
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue