[dfsan] Add custom function for dl_iterate_phdr.

Differential Revision: http://llvm-reviews.chandlerc.com/D1505

llvm-svn: 189503
This commit is contained in:
Peter Collingbourne 2013-08-28 20:18:25 +00:00
parent 3e5524d6c5
commit 187a169603
3 changed files with 46 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <ctype.h>
#include <dlfcn.h>
#include <link.h>
#include <pthread.h>
#include <stdlib.h>
#include <string.h>
@ -306,4 +307,36 @@ SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_pthread_create(
return rv;
}
struct dl_iterate_phdr_info {
int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
size_t size, void *data, dfsan_label info_label,
dfsan_label size_label, dfsan_label data_label,
dfsan_label *ret_label);
void *callback;
void *data;
};
int dl_iterate_phdr_cb(struct dl_phdr_info *info, size_t size, void *data) {
dl_iterate_phdr_info *dipi = (dl_iterate_phdr_info *)data;
dfsan_set_label(0, *info);
dfsan_set_label(0, (void *)info->dlpi_name, strlen(info->dlpi_name) + 1);
dfsan_set_label(0, (void *)info->dlpi_phdr,
sizeof(*info->dlpi_phdr) * info->dlpi_phnum);
dfsan_label ret_label;
return dipi->callback_trampoline(dipi->callback, info, size, dipi->data, 0, 0,
0, &ret_label);
}
SANITIZER_INTERFACE_ATTRIBUTE int __dfsw_dl_iterate_phdr(
int (*callback_trampoline)(void *callback, struct dl_phdr_info *info,
size_t size, void *data, dfsan_label info_label,
dfsan_label size_label, dfsan_label data_label,
dfsan_label *ret_label),
void *callback, void *data, dfsan_label callback_label,
dfsan_label data_label, dfsan_label *ret_label) {
dl_iterate_phdr_info dipi = { callback_trampoline, callback, data };
*ret_label = 0;
return dl_iterate_phdr(dl_iterate_phdr_cb, &dipi);
}
}

View File

@ -103,6 +103,7 @@ fun:read=custom
fun:pread=custom
fun:clock_gettime=custom
fun:pthread_create=custom
fun:dl_iterate_phdr=custom
# TODO: custom
fun:snprintf=discard

View File

@ -3,8 +3,10 @@
// Tests custom implementations of various libc functions.
#define _GNU_SOURCE
#include <sanitizer/dfsan_interface.h>
#include <assert.h>
#include <link.h>
#include <pthread.h>
#include <string.h>
#include <stdlib.h>
@ -19,6 +21,14 @@ void *ptcb(void *p) {
return (void *)2;
}
int dlcb(struct dl_phdr_info *info, size_t size, void *data) {
assert(data == (void *)3);
assert(dfsan_get_label((uintptr_t)info) == 0);
assert(dfsan_get_label(size) == 0);
assert(dfsan_get_label((uintptr_t)data) == 0);
return 0;
}
int main(void) {
int i = 1;
dfsan_label i_label = dfsan_create_label("i", 0);
@ -138,5 +148,7 @@ int main(void) {
pthread_join(pt, &cbrv);
assert(cbrv == (void *)2);
dl_iterate_phdr(dlcb, (void *)3);
return 0;
}