Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/Driver/ToolChains/OpenBSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ SanitizerMask OpenBSD::getSupportedSanitizers() const {
SanitizerMask Res = ToolChain::getSupportedSanitizers();

if (IsX86 || IsX86_64) {
Res |= SanitizerKind::Address;
Res |= SanitizerKind::Leak;
Res |= SanitizerKind::Vptr;
Res |= SanitizerKind::Fuzzer;
Res |= SanitizerKind::FuzzerNoLink;
Expand Down
3 changes: 1 addition & 2 deletions compiler-rt/cmake/config-ix.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,7 @@ else()
set(COMPILER_RT_HAS_INTERCEPTION FALSE)
endif()

if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH AND
NOT OS_NAME MATCHES "OpenBSD")
if (COMPILER_RT_HAS_SANITIZER_COMMON AND ASAN_SUPPORTED_ARCH)
set(COMPILER_RT_HAS_ASAN TRUE)
else()
set(COMPILER_RT_HAS_ASAN FALSE)
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void OnStackUnwind(const SignalContext &sig,
const void *callback_context,
BufferedStackTrace *stack) {
bool fast = common_flags()->fast_unwind_on_fatal;
#if SANITIZER_FREEBSD || SANITIZER_NETBSD
#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD
// On FreeBSD the slow unwinding that leverages _Unwind_Backtrace()
// yields the call stack of the signal's handler and not of the code
// that raised the signal (as it does on Linux).
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/asan_interceptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void InitializePlatformInterceptors();
#endif

#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
SANITIZER_SOLARIS
SANITIZER_OPENBSD || SANITIZER_SOLARIS
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1
#else
# define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0
Expand Down
12 changes: 7 additions & 5 deletions compiler-rt/lib/asan/asan_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
SANITIZER_SOLARIS
SANITIZER_OPENBSD || SANITIZER_SOLARIS

#include "asan_interceptors.h"
#include "asan_internal.h"
Expand Down Expand Up @@ -52,6 +52,8 @@ extern "C" void* _DYNAMIC;
#include <link_elf.h>
#include <ucontext.h>
extern Elf_Dyn _DYNAMIC;
#elif SANITIZER_OPENBSD
#include <link_elf.h>
#else
#include <sys/ucontext.h>
#include <link.h>
Expand Down Expand Up @@ -156,7 +158,7 @@ static int FindFirstDSOCallback(struct dl_phdr_info *info, size_t size,
if (internal_strncmp(info->dlpi_name, "linux-", sizeof("linux-") - 1) == 0)
return 0;

#if SANITIZER_FREEBSD || SANITIZER_NETBSD
#if SANITIZER_FREEBSD || SANITIZER_NETBSD || SANITIZER_OPENBSD
// Ignore first entry (the main program)
char **p = (char **)data;
if (!(*p)) {
Expand Down Expand Up @@ -231,7 +233,7 @@ void AsanCheckIncompatibleRT() {
}
#endif // SANITIZER_ANDROID

#if !SANITIZER_ANDROID
#if !SANITIZER_ANDROID && !SANITIZER_OPENBSD
void ReadContextStack(void *context, uptr *stack, uptr *ssize) {
ucontext_t *ucp = (ucontext_t*)context;
*stack = (uptr)ucp->uc_stack.ss_sp;
Expand All @@ -256,5 +258,5 @@ bool HandleDlopenInit() {

} // namespace __asan

#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
// SANITIZER_SOLARIS
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
// SANITIZER_OPENBSD || SANITIZER_SOLARIS
3 changes: 2 additions & 1 deletion compiler-rt/lib/asan/asan_malloc_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

#include "sanitizer_common/sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_FUCHSIA || SANITIZER_LINUX || \
SANITIZER_NETBSD || SANITIZER_RTEMS || SANITIZER_SOLARIS
SANITIZER_NETBSD || SANITIZER_OPENBSD || SANITIZER_RTEMS || \
SANITIZER_SOLARIS

#include "sanitizer_common/sanitizer_allocator_checks.h"
#include "sanitizer_common/sanitizer_errno.h"
Expand Down
3 changes: 3 additions & 0 deletions compiler-rt/lib/asan/asan_mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000
static const u64 kFreeBSD_ShadowOffset64 = 1ULL << 46; // 0x400000000000
static const u64 kNetBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000
static const u64 kNetBSD_ShadowOffset64 = 1ULL << 46; // 0x400000000000
static const u64 kOpenBSD_ShadowOffset64 = 0x100000000000ull;
static const u64 kWindowsShadowOffset32 = 3ULL << 28; // 0x30000000

static const u64 kMyriadMemoryOffset32 = 0x80000000ULL;
Expand Down Expand Up @@ -216,6 +217,8 @@ static const u64 kMyriadCacheBitMask32 = 0x40000000ULL;
# define SHADOW_OFFSET kFreeBSD_ShadowOffset64
# elif SANITIZER_NETBSD
# define SHADOW_OFFSET kNetBSD_ShadowOffset64
# elif SANITIZER_OPENBSD
# define SHADOW_OFFSET kOpenBSD_ShadowOffset64
# elif SANITIZER_MAC
# define SHADOW_OFFSET kDefaultShadowOffset64
# elif defined(__mips64)
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/asan/tests/asan_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
#include <unistd.h>
#endif

#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
#include <malloc.h>
#endif

Expand Down
12 changes: 9 additions & 3 deletions compiler-rt/lib/sanitizer_common/sanitizer_openbsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,21 @@ extern char **environ;

namespace __sanitizer {

extern "C" void *_thread_sys_mmap(void *addr, size_t len, int prot, int flags,
int fd, off_t offset);
uptr internal_mmap(void *addr, size_t length, int prot, int flags, int fd,
u64 offset) {
return (uptr)mmap(addr, length, prot, flags, fd, offset);
return (uptr)_thread_sys_mmap(addr, length, prot, flags, fd, offset);
}

uptr internal_munmap(void *addr, uptr length) { return munmap(addr, length); }
extern "C" int _thread_sys_munmap(void *addr, size_t len);
uptr internal_munmap(void *addr, uptr length) {
return _thread_sys_munmap(addr, length);
}

extern "C" int _thread_sys_mprotect(void *addr, uptr length, int prot);
int internal_mprotect(void *addr, uptr length, int prot) {
return mprotect(addr, length, prot);
return _thread_sys_mprotect(addr, length, prot);
}

int internal_sysctlbyname(const char *sname, void *oldp, uptr *oldlenp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,8 @@
#define SANITIZER_INTERCEPT_SENDMMSG SI_LINUX
#define SANITIZER_INTERCEPT_SYSMSG SI_LINUX_NOT_ANDROID
#define SANITIZER_INTERCEPT_GETPEERNAME SI_POSIX
#define SANITIZER_INTERCEPT_IOCTL SI_POSIX
// TODO(gnezdo): IOCTLs need to be intercepted, just too many details for now.
#define SANITIZER_INTERCEPT_IOCTL (SI_POSIX && !SI_OPENBSD)
#define SANITIZER_INTERCEPT_INET_ATON SI_POSIX
#define SANITIZER_INTERCEPT_SYSINFO SI_LINUX
#define SANITIZER_INTERCEPT_READDIR SI_POSIX
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#if SANITIZER_OPENBSD

#include <stddef.h>
#include "sanitizer_internal_defs.h"
#include "sanitizer_platform.h"

Expand Down Expand Up @@ -273,11 +274,7 @@ struct __sanitizer_dl_phdr_info {
#endif
const char *dlpi_name;
const void *dlpi_phdr;
#if SANITIZER_WORDSIZE == 64
u32 dlpi_phnum;
#else
u16 dlpi_phnum;
#endif
};

extern unsigned struct_ElfW_Phdr_sz;
Expand Down Expand Up @@ -310,9 +307,9 @@ struct __sanitizer_pollfd {
typedef unsigned __sanitizer_nfds_t;

struct __sanitizer_glob_t {
int gl_pathc;
int gl_matchc;
int gl_offs;
size_t gl_pathc;
size_t gl_matchc;
size_t gl_offs;
int gl_flags;
char **gl_pathv;
void **gl_statv;
Expand Down
5 changes: 4 additions & 1 deletion compiler-rt/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,10 @@ bool MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) {
}

bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name) {
#if SANITIZER_FREEBSD
#if SANITIZER_OPENBSD
// Shadow memory doesn't need to be dumped into core.
return MmapFixed(fixed_addr, size, MAP_CONCEAL, name);
#elif SANITIZER_FREEBSD
if (common_flags()->no_huge_pages_for_shadow)
return MmapFixedNoReserve(fixed_addr, size, name);
// MAP_NORESERVE is implicit with FreeBSD
Expand Down
2 changes: 0 additions & 2 deletions compiler-rt/lib/sanitizer_common/sanitizer_stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ static const u32 kStackTraceMax = 256;
# define SANITIZER_CAN_FAST_UNWIND 0
#elif SANITIZER_WINDOWS
# define SANITIZER_CAN_FAST_UNWIND 0
#elif SANITIZER_OPENBSD
# define SANITIZER_CAN_FAST_UNWIND 0
#else
# define SANITIZER_CAN_FAST_UNWIND 1
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include "sanitizer_platform.h"
#if SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD || \
SANITIZER_SOLARIS
SANITIZER_OPENBSD || SANITIZER_SOLARIS
#include "sanitizer_common.h"
#include "sanitizer_stacktrace.h"

Expand Down Expand Up @@ -177,4 +177,4 @@ void BufferedStackTrace::UnwindSlow(uptr pc, void *context, u32 max_depth) {
} // namespace __sanitizer

#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD ||
// SANITIZER_SOLARIS
// SANITIZER_OPENBSD || SANITIZER_SOLARIS
4 changes: 2 additions & 2 deletions compiler-rt/lib/sanitizer_common/tests/sanitizer_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ static inline uint32_t my_rand() {
#endif

#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__ANDROID__) && \
!defined(__NetBSD__) && !defined(_WIN32)
!defined(__NetBSD__) && !defined(_WIN32) && !defined(__OpenBSD__)
# define SANITIZER_TEST_HAS_MEMALIGN 1
#else
# define SANITIZER_TEST_HAS_MEMALIGN 0
#endif

#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__ANDROID__) && \
!defined(__NetBSD__) && !defined(_WIN32) && \
!defined(__NetBSD__) && !defined(__OpenBSD__) && !defined(_WIN32) && \
!(defined(__sun__) && defined(__svr4__))
# define SANITIZER_TEST_HAS_PVALLOC 1
# define SANITIZER_TEST_HAS_MALLOC_USABLE_SIZE 1
Expand Down