--- lib/msan/msan.h.orig 2016-12-08 17:30:58.000000000 +1100 +++ lib/msan/msan.h 2020-05-26 09:33:13.419813000 +1000 @@ -178,7 +178,7 @@ #define MEM_TO_SHADOW(mem) (LINEARIZE_MEM((mem)) + 0x080000000000ULL) #define SHADOW_TO_ORIGIN(shadow) (((uptr)(shadow)) + 0x140000000000ULL) -#elif SANITIZER_FREEBSD && SANITIZER_WORDSIZE == 64 +#elif (SANITIZER_FREEBSD || SANITIZER_BSDSUNIX) && SANITIZER_WORDSIZE == 64 // Low memory: main binary, MAP_32BIT mappings and modules // High memory: heap, modules and main thread stack --- lib/msan/msan_interceptors.cc.orig 2016-12-28 08:13:11.000000000 +1100 +++ lib/msan/msan_interceptors.cc 2020-05-26 09:37:19.428847000 +1000 @@ -48,7 +48,7 @@ DECLARE_REAL(void *, memcpy, void *dest, const void *src, uptr n) DECLARE_REAL(void *, memset, void *dest, int c, uptr n) -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX #define __errno_location __error #endif @@ -131,7 +131,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(SIZE_T, fread_unlocked, void *ptr, SIZE_T size, SIZE_T nmemb, void *file) { ENSURE_MSAN_INITED(); @@ -182,7 +182,7 @@ return 0; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(void *, memalign, SIZE_T boundary, SIZE_T size) { GET_MALLOC_STACK_TRACE; CHECK_EQ(boundary & (boundary - 1), 0); @@ -215,7 +215,7 @@ return ptr; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(void *, pvalloc, SIZE_T size) { GET_MALLOC_STACK_TRACE; uptr PageSize = GetPageSizeCached(); @@ -238,7 +238,7 @@ MsanDeallocate(&stack, ptr); } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(void, cfree, void *ptr) { GET_MALLOC_STACK_TRACE; if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return; @@ -253,7 +253,7 @@ return __sanitizer_get_allocated_size(ptr); } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX // This function actually returns a struct by value, but we can't unpoison a // temporary! The following is equivalent on all supported platforms but // aarch64 (which uses a different register for sret value). We have a test @@ -272,7 +272,7 @@ #define MSAN_MAYBE_INTERCEPT_MALLINFO #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, mallopt, int cmd, int value) { return -1; } @@ -281,7 +281,7 @@ #define MSAN_MAYBE_INTERCEPT_MALLOPT #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(void, malloc_stats, void) { // FIXME: implement, but don't call REAL(malloc_stats)! } @@ -325,7 +325,7 @@ INTERCEPTOR(char *, strdup, char *src) { ENSURE_MSAN_INITED(); GET_STORE_STACK_TRACE; - // On FreeBSD strdup() leverages strlen(). + // On FreeBSD and BSDSUniX strdup() leverages strlen(). InterceptorScope interceptor_scope; SIZE_T n = REAL(strlen)(src); CHECK_UNPOISONED_STRING(src + n, 0); @@ -334,7 +334,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(char *, __strdup, char *src) { ENSURE_MSAN_INITED(); GET_STORE_STACK_TRACE; @@ -352,7 +352,7 @@ INTERCEPTOR(char *, strndup, char *src, SIZE_T n) { ENSURE_MSAN_INITED(); GET_STORE_STACK_TRACE; - // On FreeBSD strndup() leverages strnlen(). + // On FreeBSD and BSDSUniX strndup() leverages strnlen(). InterceptorScope interceptor_scope; SIZE_T copy_size = REAL(strnlen)(src, n); char *res = REAL(strndup)(src, n); @@ -361,7 +361,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(char *, __strndup, char *src, SIZE_T n) { ENSURE_MSAN_INITED(); GET_STORE_STACK_TRACE; @@ -526,7 +526,7 @@ INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, strftime_l, s, max, format, tm, loc); } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(SIZE_T, __strftime_l, char *s, SIZE_T max, const char *format, __sanitizer_tm *tm, void *loc) { INTERCEPTOR_STRFTIME_BODY(char, SIZE_T, __strftime_l, s, max, format, tm, @@ -548,7 +548,7 @@ loc); } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(SIZE_T, __wcsftime_l, wchar_t *s, SIZE_T max, const wchar_t *format, __sanitizer_tm *tm, void *loc) { INTERCEPTOR_STRFTIME_BODY(wchar_t, SIZE_T, __wcsftime_l, s, max, format, tm, @@ -691,7 +691,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, __fxstat, int magic, int fd, void *buf) { ENSURE_MSAN_INITED(); int res = REAL(__fxstat)(magic, fd, buf); @@ -704,7 +704,7 @@ #define MSAN_MAYBE_INTERCEPT___FXSTAT #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, __fxstat64, int magic, int fd, void *buf) { ENSURE_MSAN_INITED(); int res = REAL(__fxstat64)(magic, fd, buf); @@ -717,7 +717,7 @@ #define MSAN_MAYBE_INTERCEPT___FXSTAT64 #endif -#if SANITIZER_FREEBSD +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX INTERCEPTOR(int, fstatat, int fd, char *pathname, void *buf, int flags) { ENSURE_MSAN_INITED(); int res = REAL(fstatat)(fd, pathname, buf, flags); @@ -736,7 +736,7 @@ # define MSAN_INTERCEPT_FSTATAT INTERCEPT_FUNCTION(__fxstatat) #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, __fxstatat64, int magic, int fd, char *pathname, void *buf, int flags) { ENSURE_MSAN_INITED(); @@ -783,7 +783,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(char *, fgets_unlocked, char *s, int size, void *stream) { ENSURE_MSAN_INITED(); char *res = REAL(fgets_unlocked)(s, size, stream); @@ -806,7 +806,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, getrlimit64, int resource, void *rlim) { if (msan_init_is_running) return REAL(getrlimit64)(resource, rlim); ENSURE_MSAN_INITED(); @@ -846,8 +846,8 @@ #define MSAN_MAYBE_INTERCEPT_PRLIMIT64 #endif -#if SANITIZER_FREEBSD -// FreeBSD's define uname() as +#if SANITIZER_FREEBSD || SANITIZER_BSDSUNIX +// FreeBSD's and BSDSUniX's define uname() as // static __inline int uname(struct utsname *name) { // return __xuname(SYS_NMLN, (void*)name); // } @@ -882,7 +882,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, epoll_wait, int epfd, void *events, int maxevents, int timeout) { ENSURE_MSAN_INITED(); @@ -897,7 +897,7 @@ #define MSAN_MAYBE_INTERCEPT_EPOLL_WAIT #endif -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(int, epoll_pwait, int epfd, void *events, int maxevents, int timeout, void *sigmask) { ENSURE_MSAN_INITED(); @@ -986,7 +986,7 @@ return res; } -#if !SANITIZER_FREEBSD +#if !SANITIZER_FREEBSD && !SANITIZER_BSDSUNIX INTERCEPTOR(void *, mmap64, void *addr, SIZE_T length, int prot, int flags, int fd, OFF64_T offset) { ENSURE_MSAN_INITED(); --- lib/msan/tests/msan_test.cc.orig 2016-08-20 10:38:55.000000000 +1000 +++ lib/msan/tests/msan_test.cc 2020-05-26 15:03:42.942500000 +1000 @@ -21,7 +21,7 @@ #include "sanitizer/allocator_interface.h" #include "sanitizer/msan_interface.h" -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__BSDSUniX__) # define _KERNEL // To declare 'shminfo' structure. # include # undef _KERNEL @@ -65,7 +65,7 @@ #include #include -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) # include # include # include @@ -79,7 +79,7 @@ # include # include # include -# define f_namelen f_namemax // FreeBSD names this statfs field so. +# define f_namelen f_namemax // FreeBSD/BSDSUniX names this statfs field so. # define cpu_set_t cpuset_t extern "C" { // FreeBSD's defines mempcpy() to be a macro expanding into @@ -100,8 +100,8 @@ # include #endif -// On FreeBSD procfs is not enabled by default. -#if defined(__FreeBSD__) +// On FreeBSD/BSDSUniX procfs is not enabled by default. +#if defined(__FreeBSD__) || defined(__BSDSUniX__) # define FILE_TO_READ "/bin/cat" # define DIR_TO_READ "/bin" # define SUBFILE_TO_READ "cat" @@ -813,8 +813,8 @@ close(pipefd[1]); } -// There is no ppoll() on FreeBSD. -#if !defined (__FreeBSD__) +// There is no ppoll() on FreeBSD/BSDSUniX. +#if !defined (__FreeBSD__) && !defined (__BSDSUniX__) TEST(MemorySanitizer, ppoll) { int* pipefd = new int[2]; int res = pipe(pipefd); @@ -904,7 +904,7 @@ res = fcntl(connect_socket, F_SETFL, O_NONBLOCK); ASSERT_EQ(0, res); res = connect(connect_socket, (struct sockaddr *)&sai, sizeof(sai)); - // On FreeBSD this connection completes immediately. + // On FreeBSD/BSDSUniX this connection completes immediately. if (res != 0) { ASSERT_EQ(-1, res); ASSERT_EQ(EINPROGRESS, errno); @@ -1180,8 +1180,8 @@ free(res); } -// There's no get_current_dir_name() on FreeBSD. -#if !defined(__FreeBSD__) +// There's no get_current_dir_name() on FreeBSD or BSDSUniX. +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, get_current_dir_name) { char* res = get_current_dir_name(); ASSERT_TRUE(res != NULL); @@ -1200,7 +1200,7 @@ EXPECT_NOT_POISONED(ds); // FreeBSD does not support shmctl(IPC_INFO) and shmctl(SHM_INFO). -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) struct shminfo si; res = shmctl(id, IPC_INFO, (struct shmid_ds *)&si); ASSERT_GT(res, -1); @@ -1249,7 +1249,7 @@ } // There's no random_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, random_r) { int32_t x; char z[64]; @@ -1330,7 +1330,7 @@ } // There's no canonicalize_file_name() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, canonicalize_file_name) { const char* relpath = "."; char* res = canonicalize_file_name(relpath); @@ -1737,7 +1737,7 @@ } // There's no sincos() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, sincos) { double s, c; sincos(0.2, &s, &c); @@ -1747,7 +1747,7 @@ #endif // There's no sincosf() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, sincosf) { float s, c; sincosf(0.2, &s, &c); @@ -1757,7 +1757,7 @@ #endif // There's no sincosl() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, sincosl) { long double s, c; sincosl(0.2, &s, &c); @@ -1820,7 +1820,7 @@ } // There's no lgammal_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, lgammal_r) { int sgn; long double res = lgammal_r(1.1, &sgn); @@ -1830,7 +1830,7 @@ #endif // There's no drand48_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, drand48_r) { struct drand48_data buf; srand48_r(0, &buf); @@ -1841,7 +1841,7 @@ #endif // There's no lrand48_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, lrand48_r) { struct drand48_data buf; srand48_r(0, &buf); @@ -2125,7 +2125,7 @@ } // There's no getmntent() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, getmntent) { FILE *fp = setmntent("/etc/fstab", "r"); struct mntent *mnt = getmntent(fp); @@ -2141,7 +2141,7 @@ #endif // There's no getmntent_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, getmntent_r) { FILE *fp = setmntent("/etc/fstab", "r"); struct mntent mntbuf; @@ -2197,7 +2197,7 @@ } // There's no fcvt() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) // FIXME: enable and add ecvt. // FIXME: check why msandr does nt handle fcvt. TEST(MemorySanitizer, fcvt) { @@ -2216,7 +2216,7 @@ #endif // There's no fcvt_long() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, fcvt_long) { int a, b; break_optimization(&a); @@ -2876,7 +2876,7 @@ EXPECT_NOT_POISONED(usage.ru_nivcsw); } -#if defined(__FreeBSD__) +#if defined(__FreeBSD__) || defined(__BSDSUniX__) static void GetProgramPath(char *buf, size_t sz) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; int res = sysctl(mib, 4, buf, &sz, NULL, 0); @@ -3001,7 +3001,7 @@ #endif // MSAN_TEST_DISABLE_DLOPEN // There's no sched_getaffinity() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, sched_getaffinity) { cpu_set_t mask; int res = sched_getaffinity(getpid(), sizeof(mask), &mask); @@ -3247,7 +3247,7 @@ } // There's no memalign() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, memalign) { void *p = memalign(4096, 13); EXPECT_EQ(0U, (uintptr_t)p % 4096); @@ -3263,7 +3263,7 @@ } // There's no pvalloc() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, pvalloc) { uintptr_t PageSize = GetPageSize(); void *p = pvalloc(PageSize + 100); @@ -3321,7 +3321,7 @@ } // There's no sysinfo() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, sysinfo) { struct sysinfo info; int res = sysinfo(&info); @@ -3419,7 +3419,7 @@ } // There's no fgetpwent() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, fgetpwent) { FILE *fp = fopen("/etc/passwd", "r"); struct passwd *p = fgetpwent(fp); @@ -3443,7 +3443,7 @@ } // There's no fgetgrent() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, fgetgrent) { FILE *fp = fopen("/etc/group", "r"); struct group *grp = fgetgrent(fp); @@ -3475,7 +3475,7 @@ } // There's no fgetgrent_r() on FreeBSD. -#if !defined(__FreeBSD__) +#if !defined(__FreeBSD__) && !defined(__BSDSUniX__) TEST(MemorySanitizer, fgetgrent_r) { FILE *fp = fopen("/etc/group", "r"); struct group grp;