Index: lib/sanitizer_common/CMakeLists.txt =================================================================== --- lib/sanitizer_common/CMakeLists.txt +++ lib/sanitizer_common/CMakeLists.txt @@ -16,9 +16,11 @@ sanitizer_linux.cc sanitizer_linux_s390.cc sanitizer_mac.cc + sanitizer_openbsd.cc sanitizer_persistent_allocator.cc sanitizer_platform_limits_linux.cc sanitizer_platform_limits_netbsd.cc + sanitizer_platform_limits_openbsd.cc sanitizer_platform_limits_posix.cc sanitizer_platform_limits_solaris.cc sanitizer_posix.cc Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -3590,7 +3590,7 @@ // * GNU version returns message pointer, which points to either buf or some // static storage. #if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE) || \ - SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD + SANITIZER_MAC || SANITIZER_ANDROID || SANITIZER_NETBSD || SANITIZER_OPENBSD // POSIX version. Spec is not clear on whether buf is NULL-terminated. // At least on OSX, buf contents are valid even when the call fails. INTERCEPTOR(int, strerror_r, int errnum, char *buf, SIZE_T buflen) { @@ -4405,25 +4405,36 @@ #endif #if SANITIZER_INTERCEPT_PTHREAD_ATTR_GET -INTERCEPTOR_PTHREAD_ATTR_GET(detachstate, sizeof(int)) -INTERCEPTOR_PTHREAD_ATTR_GET(guardsize, sizeof(SIZE_T)) -INTERCEPTOR_PTHREAD_ATTR_GET(schedparam, struct_sched_param_sz) -INTERCEPTOR_PTHREAD_ATTR_GET(schedpolicy, sizeof(int)) -INTERCEPTOR_PTHREAD_ATTR_GET(scope, sizeof(int)) -INTERCEPTOR_PTHREAD_ATTR_GET(stacksize, sizeof(SIZE_T)) -INTERCEPTOR(int, pthread_attr_getstack, void *attr, void **addr, SIZE_T *size) { - void *ctx; - COMMON_INTERCEPTOR_ENTER(ctx, pthread_attr_getstack, attr, addr, size); - // FIXME: under ASan the call below may write to freed memory and corrupt - // its metadata. See - // https://github.com/google/sanitizers/issues/321. - int res = REAL(pthread_attr_getstack)(attr, addr, size); - if (!res) { - if (addr) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, addr, sizeof(*addr)); - if (size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, size, sizeof(*size)); - } - return res; -} +#define COMMON_INTERCEPTOR_PTHREAD_ATTR_GET \ +INTERCEPTOR_PTHREAD_ATTR_GET(detachstate, sizeof(int)) \ +INTERCEPTOR_PTHREAD_ATTR_GET(guardsize, sizeof(SIZE_T)) \ +INTERCEPTOR_PTHREAD_ATTR_GET(scope, sizeof(int)) \ +INTERCEPTOR_PTHREAD_ATTR_GET(stacksize, sizeof(SIZE_T)) \ +INTERCEPTOR(int, pthread_attr_getstack, void *attr, void **addr, SIZE_T *size) { \ + void *ctx; \ + COMMON_INTERCEPTOR_ENTER(ctx, pthread_attr_getstack, attr, addr, size); \ + // FIXME: under ASan the call below may write to freed memory and corrupt \ + // its metadata. See \ + // https://github.com/google/sanitizers/issues/321. \ + int res = REAL(pthread_attr_getstack)(attr, addr, size); \ + if (!res) { \ + if (addr) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, addr, sizeof(*addr)); \ + if (size) COMMON_INTERCEPTOR_WRITE_RANGE(ctx, size, sizeof(*size)); \ + } \ + return res; \ +} + +#if !SANITIZER_OPENBSD +#define SANITIZER_INTERCEPTOR_PTHREAD_ATTR_GET \ +COMMON_INTERCEPTOR_PTHREAD_ATTR_GET \ +INTERCEPTOR_PTHREAD_ATTR_GET(schedparam, struct_sched_param_sz) \ +INTERCEPTOR_PTHREAD_ATTR_GET(schedpolicy, sizeof(int)) +#else +#define SANITIZER_INTERCEPTOR_PTHREAD_ATTR_GET \ +COMMON_INTERCEPTOR_PTHREAD_ATTR_GET +#endif + +SANITIZER_INTERCEPTOR_PTHREAD_ATTR_GET // We may need to call the real pthread_attr_getstack from the run-time // in sanitizer_common, but we don't want to include the interception headers @@ -4436,14 +4447,21 @@ } // extern "C" } // namespace __sanitizer -#define INIT_PTHREAD_ATTR_GET \ +#define COMMON_INIT_PTHREAD_ATTR_GET \ COMMON_INTERCEPT_FUNCTION(pthread_attr_getdetachstate); \ COMMON_INTERCEPT_FUNCTION(pthread_attr_getguardsize); \ - COMMON_INTERCEPT_FUNCTION(pthread_attr_getschedparam); \ - COMMON_INTERCEPT_FUNCTION(pthread_attr_getschedpolicy); \ COMMON_INTERCEPT_FUNCTION(pthread_attr_getscope); \ COMMON_INTERCEPT_FUNCTION(pthread_attr_getstacksize); \ COMMON_INTERCEPT_FUNCTION(pthread_attr_getstack); + +#if !SANITIZER_OPENBSD +#define INIT_PTHREAD_ATTR_GET \ + COMMON_INIT_PTHREAD_ATTR_GET \ + COMMON_INTERCEPT_FUNCTION(pthread_attr_getschedparam); \ + COMMON_INTERCEPT_FUNCTION(pthread_attr_getschedpolicy); \ +#else +#define INIT_PTHREAD_ATTR_GET COMMON_INIT_PTHREAD_ATTR_GET +#endif #else #define INIT_PTHREAD_ATTR_GET #endif