[msan] Unpoison errno in common interceptors.

llvm-svn: 193343
This commit is contained in:
Evgeniy Stepanov 2013-10-24 13:20:34 +00:00
parent 225bcbbe71
commit 7edb87a92c
2 changed files with 26 additions and 6 deletions

View File

@ -0,0 +1,17 @@
// RUN: %clangxx_msan -m64 -O0 %s -o %t && %t
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
int x;
int *volatile p = &x;
errno = *p;
int res = read(-1, 0, 0);
assert(res == -1);
if (errno) printf("errno %d\n", errno);
return 0;
}

View File

@ -1172,6 +1172,8 @@ int OnExit() {
} // namespace __msan
extern "C" int *__errno_location(void);
// A version of CHECK_UNPOISED using a saved scope value. Used in common
// interceptors.
#define CHECK_UNPOISONED_CTX(ctx, x, n) \
@ -1188,12 +1190,13 @@ int OnExit() {
CHECK_UNPOISONED_CTX(ctx, ptr, size)
#define COMMON_INTERCEPTOR_INITIALIZE_RANGE(ctx, ptr, size) \
__msan_unpoison(ptr, size)
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \
MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \
ctx = (void *)&msan_ctx; \
(void)ctx; \
InterceptorScope interceptor_scope; \
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \
if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \
MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \
ctx = (void *)&msan_ctx; \
(void)ctx; \
InterceptorScope interceptor_scope; \
__msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */ \
ENSURE_MSAN_INITED();
#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
do { \