Libsanitizer: merge from trunk

2019-11-07  Martin Liska  <mliska@suse.cz>

	* merge.sh: Update to use llvm-project git repository.
	* all source files: Merge from upstream
	82588e05cc32bb30807e480abd4e689b0dee132a.

From-SVN: r277909
This commit is contained in:
Martin Liska 2019-11-07 10:33:54 +01:00 committed by Martin Liska
parent 29f3def308
commit cb7dc4da4c
30 changed files with 292 additions and 134 deletions

View File

@ -1,3 +1,9 @@
2019-11-07 Martin Liska <mliska@suse.cz>
* merge.sh: Update to use llvm-project git repository.
* all source files: Merge from upstream
82588e05cc32bb30807e480abd4e689b0dee132a.
2019-11-05 Martin Liska <mliska@suse.cz>
* ubsan/ubsan_flags.cpp (InitializeFlags): Trunk decided to print

View File

@ -1,4 +1,4 @@
375507
82588e05cc32bb30807e480abd4e689b0dee132a
The first line of this file holds the svn revision number of the
The first line of this file holds the git revision number of the
last merge done from the master library sources.

View File

@ -246,6 +246,7 @@ struct Allocator {
AllocatorCache fallback_allocator_cache;
QuarantineCache fallback_quarantine_cache;
uptr max_user_defined_malloc_size;
atomic_uint8_t rss_limit_exceeded;
// ------------------- Options --------------------------
@ -280,6 +281,10 @@ struct Allocator {
SetAllocatorMayReturnNull(options.may_return_null);
allocator.InitLinkerInitialized(options.release_to_os_interval_ms);
SharedInitCode(options);
max_user_defined_malloc_size = common_flags()->max_allocation_size_mb
? common_flags()->max_allocation_size_mb
<< 20
: kMaxAllowedMallocSize;
}
bool RssLimitExceeded() {
@ -394,6 +399,16 @@ struct Allocator {
return right_chunk;
}
bool UpdateAllocationStack(uptr addr, BufferedStackTrace *stack) {
AsanChunk *m = GetAsanChunkByAddr(addr);
if (!m) return false;
if (m->chunk_state != CHUNK_ALLOCATED) return false;
if (m->Beg() != addr) return false;
atomic_store((atomic_uint32_t *)&m->alloc_context_id, StackDepotPut(*stack),
memory_order_relaxed);
return true;
}
// -------------------- Allocation/Deallocation routines ---------------
void *Allocate(uptr size, uptr alignment, BufferedStackTrace *stack,
AllocType alloc_type, bool can_fill) {
@ -435,14 +450,16 @@ struct Allocator {
using_primary_allocator = false;
}
CHECK(IsAligned(needed_size, min_alignment));
if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize) {
if (size > kMaxAllowedMallocSize || needed_size > kMaxAllowedMallocSize ||
size > max_user_defined_malloc_size) {
if (AllocatorMayReturnNull()) {
Report("WARNING: AddressSanitizer failed to allocate 0x%zx bytes\n",
(void*)size);
return nullptr;
}
ReportAllocationSizeTooBig(size, needed_size, kMaxAllowedMallocSize,
stack);
uptr malloc_limit =
Min(kMaxAllowedMallocSize, max_user_defined_malloc_size);
ReportAllocationSizeTooBig(size, needed_size, malloc_limit, stack);
}
AsanThread *t = GetCurrentThread();
@ -1105,6 +1122,11 @@ void __sanitizer_purge_allocator() {
instance.Purge(&stack);
}
int __asan_update_allocation_context(void* addr) {
GET_STACK_TRACE_MALLOC;
return instance.UpdateAllocationStack((uptr)addr, &stack);
}
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
// Provide default (no-op) implementation of malloc hooks.
SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_malloc_hook,

View File

@ -154,6 +154,23 @@ static void CheckODRViolationViaIndicator(const Global *g) {
}
}
// Check ODR violation for given global G by checking if it's already poisoned.
// We use this method in case compiler doesn't use private aliases for global
// variables.
static void CheckODRViolationViaPoisoning(const Global *g) {
if (__asan_region_is_poisoned(g->beg, g->size_with_redzone)) {
// This check may not be enough: if the first global is much larger
// the entire redzone of the second global may be within the first global.
for (ListOfGlobals *l = list_of_all_globals; l; l = l->next) {
if (g->beg == l->g->beg &&
(flags()->detect_odr_violation >= 2 || g->size != l->g->size) &&
!IsODRViolationSuppressed(g->name))
ReportODRViolation(g, FindRegistrationSite(g),
l->g, FindRegistrationSite(l->g));
}
}
}
// Clang provides two different ways for global variables protection:
// it can poison the global itself or its private alias. In former
// case we may poison same symbol multiple times, that can help us to
@ -199,6 +216,8 @@ static void RegisterGlobal(const Global *g) {
// where two globals with the same name are defined in different modules.
if (UseODRIndicator(g))
CheckODRViolationViaIndicator(g);
else
CheckODRViolationViaPoisoning(g);
}
if (CanPoisonMemory())
PoisonRedZones(*g);

View File

@ -80,12 +80,7 @@ void InitializePlatformInterceptors();
#if ASAN_HAS_EXCEPTIONS && !SANITIZER_WINDOWS && !SANITIZER_SOLARIS && \
!SANITIZER_NETBSD
# define ASAN_INTERCEPT___CXA_THROW 1
# if ! defined(ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION) \
|| ASAN_HAS_CXA_RETHROW_PRIMARY_EXCEPTION
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
# else
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 0
# endif
# define ASAN_INTERCEPT___CXA_RETHROW_PRIMARY_EXCEPTION 1
# if defined(_GLIBCXX_SJLJ_EXCEPTIONS) || (SANITIZER_IOS && defined(__arm__))
# define ASAN_INTERCEPT__UNWIND_SJLJ_RAISEEXCEPTION 1
# else

View File

@ -164,6 +164,7 @@ INTERFACE_FUNCTION(__sanitizer_unaligned_load64)
INTERFACE_FUNCTION(__sanitizer_unaligned_store16)
INTERFACE_FUNCTION(__sanitizer_unaligned_store32)
INTERFACE_FUNCTION(__sanitizer_unaligned_store64)
INTERFACE_FUNCTION(__asan_update_allocation_context)
INTERFACE_WEAK_FUNCTION(__asan_default_options)
INTERFACE_WEAK_FUNCTION(__asan_default_suppressions)
INTERFACE_WEAK_FUNCTION(__asan_on_error)

View File

@ -251,6 +251,9 @@ extern "C" {
const char* __asan_default_suppressions();
SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_vfork(void *sp);
SANITIZER_INTERFACE_ATTRIBUTE int __asan_update_allocation_context(
void *addr);
} // extern "C"
#endif // ASAN_INTERFACE_INTERNAL_H

View File

@ -35,11 +35,8 @@ constexpr unsigned long HEAP_REALLOC_IN_PLACE_ONLY = 0x00000010;
constexpr unsigned long HEAP_ALLOCATE_SUPPORTED_FLAGS = (HEAP_ZERO_MEMORY);
constexpr unsigned long HEAP_ALLOCATE_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS);
constexpr unsigned long HEAP_FREE_SUPPORTED_FLAGS = (0);
constexpr unsigned long HEAP_FREE_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS);
constexpr unsigned long HEAP_REALLOC_SUPPORTED_FLAGS =
(HEAP_REALLOC_IN_PLACE_ONLY | HEAP_ZERO_MEMORY);
constexpr unsigned long HEAP_REALLOC_UNSUPPORTED_FLAGS =
(~HEAP_ALLOCATE_SUPPORTED_FLAGS);

View File

@ -163,7 +163,7 @@ static const u64 kDefaultShort64bitShadowOffset =
static const u64 kAArch64_ShadowOffset64 = 1ULL << 36;
static const u64 kMIPS32_ShadowOffset32 = 0x0aaa0000;
static const u64 kMIPS64_ShadowOffset64 = 1ULL << 37;
static const u64 kPPC64_ShadowOffset64 = 1ULL << 41;
static const u64 kPPC64_ShadowOffset64 = 1ULL << 44;
static const u64 kSystemZ_ShadowOffset64 = 1ULL << 52;
static const u64 kSPARC64_ShadowOffset64 = 1ULL << 43; // 0x80000000000
static const u64 kFreeBSD_ShadowOffset32 = 1ULL << 30; // 0x40000000

View File

@ -315,6 +315,10 @@ void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
/// functions like <c>_exit()</c> and <c>execl()</c>.
void __asan_handle_no_return(void);
/// Update allocation stack trace for the given allocation to the current stack
/// trace. Returns 1 if successfull, 0 if not.
int __asan_update_allocation_context(void* addr);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@ -20,8 +20,8 @@
// DO NOT EDIT! THIS FILE HAS BEEN GENERATED!
//
// Generated with: generate_netbsd_syscalls.awk
// Generated date: 2018-10-30
// Generated from: syscalls.master,v 1.293 2018/07/31 13:00:13 rjs Exp
// Generated date: 2019-11-01
// Generated from: syscalls.master,v 1.296 2019/09/22 22:59:39 christos Exp
//
//===----------------------------------------------------------------------===//
#ifndef SANITIZER_NETBSD_SYSCALL_HOOKS_H
@ -1839,23 +1839,24 @@
#define __sanitizer_syscall_post_uuidgen(res, store, count) \
__sanitizer_syscall_post_impl_uuidgen(res, (long long)(store), \
(long long)(count))
#define __sanitizer_syscall_pre_getvfsstat(buf, bufsize, flags) \
__sanitizer_syscall_pre_impl_getvfsstat( \
#define __sanitizer_syscall_pre_compat_90_getvfsstat(buf, bufsize, flags) \
__sanitizer_syscall_pre_impl_compat_90_getvfsstat( \
(long long)(buf), (long long)(bufsize), (long long)(flags))
#define __sanitizer_syscall_post_getvfsstat(res, buf, bufsize, flags) \
__sanitizer_syscall_post_impl_getvfsstat( \
#define __sanitizer_syscall_post_compat_90_getvfsstat(res, buf, bufsize, \
flags) \
__sanitizer_syscall_post_impl_compat_90_getvfsstat( \
res, (long long)(buf), (long long)(bufsize), (long long)(flags))
#define __sanitizer_syscall_pre_statvfs1(path, buf, flags) \
__sanitizer_syscall_pre_impl_statvfs1((long long)(path), (long long)(buf), \
(long long)(flags))
#define __sanitizer_syscall_post_statvfs1(res, path, buf, flags) \
__sanitizer_syscall_post_impl_statvfs1(res, (long long)(path), \
(long long)(buf), (long long)(flags))
#define __sanitizer_syscall_pre_fstatvfs1(fd, buf, flags) \
__sanitizer_syscall_pre_impl_fstatvfs1((long long)(fd), (long long)(buf), \
(long long)(flags))
#define __sanitizer_syscall_post_fstatvfs1(res, fd, buf, flags) \
__sanitizer_syscall_post_impl_fstatvfs1( \
#define __sanitizer_syscall_pre_compat_90_statvfs1(path, buf, flags) \
__sanitizer_syscall_pre_impl_compat_90_statvfs1( \
(long long)(path), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_post_compat_90_statvfs1(res, path, buf, flags) \
__sanitizer_syscall_post_impl_compat_90_statvfs1( \
res, (long long)(path), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_pre_compat_90_fstatvfs1(fd, buf, flags) \
__sanitizer_syscall_pre_impl_compat_90_fstatvfs1( \
(long long)(fd), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_post_compat_90_fstatvfs1(res, fd, buf, flags) \
__sanitizer_syscall_post_impl_compat_90_fstatvfs1( \
res, (long long)(fd), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_pre_compat_30_fhstatvfs1(fhp, buf, flags) \
__sanitizer_syscall_pre_impl_compat_30_fhstatvfs1( \
@ -2143,12 +2144,13 @@
#define __sanitizer_syscall_post___fhopen40(res, fhp, fh_size, flags) \
__sanitizer_syscall_post_impl___fhopen40( \
res, (long long)(fhp), (long long)(fh_size), (long long)(flags))
#define __sanitizer_syscall_pre___fhstatvfs140(fhp, fh_size, buf, flags) \
__sanitizer_syscall_pre_impl___fhstatvfs140( \
#define __sanitizer_syscall_pre_compat_90_fhstatvfs1(fhp, fh_size, buf, flags) \
__sanitizer_syscall_pre_impl_compat_90_fhstatvfs1( \
(long long)(fhp), (long long)(fh_size), (long long)(buf), \
(long long)(flags))
#define __sanitizer_syscall_post___fhstatvfs140(res, fhp, fh_size, buf, flags) \
__sanitizer_syscall_post_impl___fhstatvfs140( \
#define __sanitizer_syscall_post_compat_90_fhstatvfs1(res, fhp, fh_size, buf, \
flags) \
__sanitizer_syscall_post_impl_compat_90_fhstatvfs1( \
res, (long long)(fhp), (long long)(fh_size), (long long)(buf), \
(long long)(flags))
#define __sanitizer_syscall_pre_compat_50___fhstat40(fhp, fh_size, sb) \
@ -2703,6 +2705,53 @@
clock_id) \
__sanitizer_syscall_post_impl_clock_getcpuclockid2( \
res, (long long)(idtype), (long long)(id), (long long)(clock_id))
#define __sanitizer_syscall_pre___getvfsstat90(buf, bufsize, flags) \
__sanitizer_syscall_pre_impl___getvfsstat90( \
(long long)(buf), (long long)(bufsize), (long long)(flags))
#define __sanitizer_syscall_post___getvfsstat90(res, buf, bufsize, flags) \
__sanitizer_syscall_post_impl___getvfsstat90( \
res, (long long)(buf), (long long)(bufsize), (long long)(flags))
#define __sanitizer_syscall_pre___statvfs190(path, buf, flags) \
__sanitizer_syscall_pre_impl___statvfs190( \
(long long)(path), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_post___statvfs190(res, path, buf, flags) \
__sanitizer_syscall_post_impl___statvfs190( \
res, (long long)(path), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_pre___fstatvfs190(fd, buf, flags) \
__sanitizer_syscall_pre_impl___fstatvfs190( \
(long long)(fd), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_post___fstatvfs190(res, fd, buf, flags) \
__sanitizer_syscall_post_impl___fstatvfs190( \
res, (long long)(fd), (long long)(buf), (long long)(flags))
#define __sanitizer_syscall_pre___fhstatvfs190(fhp, fh_size, buf, flags) \
__sanitizer_syscall_pre_impl___fhstatvfs190( \
(long long)(fhp), (long long)(fh_size), (long long)(buf), \
(long long)(flags))
#define __sanitizer_syscall_post___fhstatvfs190(res, fhp, fh_size, buf, flags) \
__sanitizer_syscall_post_impl___fhstatvfs190( \
res, (long long)(fhp), (long long)(fh_size), (long long)(buf), \
(long long)(flags))
/* Compat with older releases */
#define __sanitizer_syscall_pre_getvfsstat \
__sanitizer_syscall_pre_compat_90_getvfsstat
#define __sanitizer_syscall_post_getvfsstat \
__sanitizer_syscall_post_compat_90_getvfsstat
#define __sanitizer_syscall_pre_statvfs1 \
__sanitizer_syscall_pre_compat_90_statvfs1
#define __sanitizer_syscall_post_statvfs1 \
__sanitizer_syscall_post_compat_90_statvfs1
#define __sanitizer_syscall_pre_fstatvfs1 \
__sanitizer_syscall_pre_compat_90_fstatvfs1
#define __sanitizer_syscall_post_fstatvfs1 \
__sanitizer_syscall_post_compat_90_fstatvfs1
#define __sanitizer_syscall_pre___fhstatvfs140 \
__sanitizer_syscall_pre_compat_90_fhstatvfs1
#define __sanitizer_syscall_post___fhstatvfs140 \
__sanitizer_syscall_post_compat_90_fhstatvfs1
#ifdef __cplusplus
extern "C" {
@ -4066,19 +4115,27 @@ void __sanitizer_syscall_post_impl_fsync_range(long long res, long long fd,
void __sanitizer_syscall_pre_impl_uuidgen(long long store, long long count);
void __sanitizer_syscall_post_impl_uuidgen(long long res, long long store,
long long count);
void __sanitizer_syscall_pre_impl_getvfsstat(long long buf, long long bufsize,
long long flags);
void __sanitizer_syscall_post_impl_getvfsstat(long long res, long long buf,
long long bufsize,
long long flags);
void __sanitizer_syscall_pre_impl_statvfs1(long long path, long long buf,
long long flags);
void __sanitizer_syscall_post_impl_statvfs1(long long res, long long path,
long long buf, long long flags);
void __sanitizer_syscall_pre_impl_fstatvfs1(long long fd, long long buf,
long long flags);
void __sanitizer_syscall_post_impl_fstatvfs1(long long res, long long fd,
long long buf, long long flags);
void __sanitizer_syscall_pre_impl_compat_90_getvfsstat(long long buf,
long long bufsize,
long long flags);
void __sanitizer_syscall_post_impl_compat_90_getvfsstat(long long res,
long long buf,
long long bufsize,
long long flags);
void __sanitizer_syscall_pre_impl_compat_90_statvfs1(long long path,
long long buf,
long long flags);
void __sanitizer_syscall_post_impl_compat_90_statvfs1(long long res,
long long path,
long long buf,
long long flags);
void __sanitizer_syscall_pre_impl_compat_90_fstatvfs1(long long fd,
long long buf,
long long flags);
void __sanitizer_syscall_post_impl_compat_90_fstatvfs1(long long res,
long long fd,
long long buf,
long long flags);
void __sanitizer_syscall_pre_impl_compat_30_fhstatvfs1(long long fhp,
long long buf,
long long flags);
@ -4304,14 +4361,15 @@ void __sanitizer_syscall_pre_impl___fhopen40(long long fhp, long long fh_size,
void __sanitizer_syscall_post_impl___fhopen40(long long res, long long fhp,
long long fh_size,
long long flags);
void __sanitizer_syscall_pre_impl___fhstatvfs140(long long fhp,
long long fh_size,
long long buf,
long long flags);
void __sanitizer_syscall_post_impl___fhstatvfs140(long long res, long long fhp,
long long fh_size,
long long buf,
long long flags);
void __sanitizer_syscall_pre_impl_compat_90_fhstatvfs1(long long fhp,
long long fh_size,
long long buf,
long long flags);
void __sanitizer_syscall_post_impl_compat_90_fhstatvfs1(long long res,
long long fhp,
long long fh_size,
long long buf,
long long flags);
void __sanitizer_syscall_pre_impl_compat_50___fhstat40(long long fhp,
long long fh_size,
long long sb);
@ -4721,6 +4779,29 @@ void __sanitizer_syscall_post_impl_clock_getcpuclockid2(long long res,
long long idtype,
long long id,
long long clock_id);
void __sanitizer_syscall_pre_impl___getvfsstat90(long long buf,
long long bufsize,
long long flags);
void __sanitizer_syscall_post_impl___getvfsstat90(long long res, long long buf,
long long bufsize,
long long flags);
void __sanitizer_syscall_pre_impl___statvfs190(long long path, long long buf,
long long flags);
void __sanitizer_syscall_post_impl___statvfs190(long long res, long long path,
long long buf, long long flags);
void __sanitizer_syscall_pre_impl___fstatvfs190(long long fd, long long buf,
long long flags);
void __sanitizer_syscall_post_impl___fstatvfs190(long long res, long long fd,
long long buf,
long long flags);
void __sanitizer_syscall_pre_impl___fhstatvfs190(long long fhp,
long long fh_size,
long long buf,
long long flags);
void __sanitizer_syscall_post_impl___fhstatvfs190(long long res, long long fhp,
long long fh_size,
long long buf,
long long flags);
#ifdef __cplusplus
} // extern "C"

View File

@ -36,10 +36,17 @@ static const uptr kMaxAllowedMallocSize = 8UL << 30;
static Allocator allocator;
static uptr max_malloc_size;
void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator.InitLinkerInitialized(
common_flags()->allocator_release_to_os_interval_ms);
if (common_flags()->max_allocation_size_mb)
max_malloc_size = Min(common_flags()->max_allocation_size_mb << 20,
kMaxAllowedMallocSize);
else
max_malloc_size = kMaxAllowedMallocSize;
}
void AllocatorThreadFinish() {
@ -72,14 +79,14 @@ static void *ReportAllocationSizeTooBig(uptr size, const StackTrace &stack) {
Report("WARNING: LeakSanitizer failed to allocate 0x%zx bytes\n", size);
return nullptr;
}
ReportAllocationSizeTooBig(size, kMaxAllowedMallocSize, &stack);
ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
}
void *Allocate(const StackTrace &stack, uptr size, uptr alignment,
bool cleared) {
if (size == 0)
size = 1;
if (size > kMaxAllowedMallocSize)
if (size > max_malloc_size)
return ReportAllocationSizeTooBig(size, stack);
void *p = allocator.Allocate(GetAllocatorCache(), size, alignment);
if (UNLIKELY(!p)) {
@ -117,7 +124,7 @@ void Deallocate(void *p) {
void *Reallocate(const StackTrace &stack, void *p, uptr new_size,
uptr alignment) {
RegisterDeallocation(p);
if (new_size > kMaxAllowedMallocSize) {
if (new_size > max_malloc_size) {
allocator.Deallocate(GetAllocatorCache(), p);
return ReportAllocationSizeTooBig(new_size, stack);
}

View File

@ -8,13 +8,12 @@ VCS=${1:-svn}
get_upstream() {
rm -rf upstream
#cp -rf orig upstream
svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk upstream
git clone https://github.com/llvm/llvm-project.git upstream
}
get_current_rev() {
cd upstream
svn info | grep Revision | grep -o '[0-9]*'
git rev-parse HEAD
}
list_files() {
@ -85,6 +84,6 @@ rm -rf upstream
cat << EOF > MERGE
$CUR_REV
The first line of this file holds the svn revision number of the
The first line of this file holds the git revision number of the
last merge done from the master library sources.
EOF

View File

@ -132,6 +132,9 @@ COMMON_FLAG(uptr, soft_rss_limit_mb, 0,
" until the RSS goes below the soft limit."
" This limit does not affect memory allocations other than"
" malloc/new.")
COMMON_FLAG(uptr, max_allocation_size_mb, 0,
"If non-zero, malloc/new calls larger than this size will return "
"nullptr (or crash if allocator_may_return_null=false).")
COMMON_FLAG(bool, heap_profile, false, "Experimental heap profiler, asan-only")
COMMON_FLAG(s32, allocator_release_to_os_interval_ms,
((bool)SANITIZER_FUCHSIA || (bool)SANITIZER_WINDOWS) ? -1 : 5000,

View File

@ -407,7 +407,10 @@ uptr internal_unlink(const char *path) {
}
uptr internal_rename(const char *oldpath, const char *newpath) {
#if SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD
#if defined(__riscv)
return internal_syscall(SYSCALL(renameat2), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
(uptr)newpath, 0);
#elif SANITIZER_USES_CANONICAL_LINUX_SYSCALLS || SANITIZER_OPENBSD
return internal_syscall(SYSCALL(renameat), AT_FDCWD, (uptr)oldpath, AT_FDCWD,
(uptr)newpath);
#else
@ -1972,6 +1975,11 @@ static void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
# endif
*bp = ucontext->uc_mcontext.gregs[11];
*sp = ucontext->uc_mcontext.gregs[15];
#elif defined(__riscv)
ucontext_t *ucontext = (ucontext_t*)context;
*pc = ucontext->uc_mcontext.__gregs[REG_PC];
*bp = ucontext->uc_mcontext.__gregs[REG_S0];
*sp = ucontext->uc_mcontext.__gregs[REG_SP];
#else
# error "Unsupported arch"
#endif

View File

@ -698,13 +698,9 @@ u32 GetNumberOfCPUs() {
#elif SANITIZER_SOLARIS
return sysconf(_SC_NPROCESSORS_ONLN);
#else
#if defined(CPU_COUNT)
cpu_set_t CPUs;
CHECK_EQ(sched_getaffinity(0, sizeof(cpu_set_t), &CPUs), 0);
return CPU_COUNT(&CPUs);
#else
return 1;
#endif
#endif
}

View File

@ -37,7 +37,7 @@
extern char **environ;
#endif
#if defined(__has_include) && __has_include(<os/trace.h>) && defined(__BLOCKS__)
#if defined(__has_include) && __has_include(<os/trace.h>)
#define SANITIZER_OS_TRACE 1
#include <os/trace.h>
#else

View File

@ -255,11 +255,11 @@
#define SANITIZER_SIGN_EXTENDED_ADDRESSES 0
#endif
// The AArch64 linux port uses the canonical syscall set as mandated by
// the upstream linux community for all new ports. Other ports may still
// use legacy syscalls.
// The AArch64 and RISC-V linux ports use the canonical syscall set as
// mandated by the upstream linux community for all new ports. Other ports
// may still use legacy syscalls.
#ifndef SANITIZER_USES_CANONICAL_LINUX_SYSCALLS
# if defined(__aarch64__) && SANITIZER_LINUX
# if (defined(__aarch64__) || defined(__riscv)) && SANITIZER_LINUX
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 1
# else
# define SANITIZER_USES_CANONICAL_LINUX_SYSCALLS 0

View File

@ -26,12 +26,9 @@
// With old kernels (and even new kernels on powerpc) asm/stat.h uses types that
// are not defined anywhere in userspace headers. Fake them. This seems to work
// fine with newer headers, too. Beware that with <sys/stat.h>, struct stat
// takes the form of struct stat64 on 32-bit platforms if _FILE_OFFSET_BITS=64.
// Also, for some platforms (e.g. mips) there are additional members in the
// <sys/stat.h> struct stat:s.
// fine with newer headers, too.
#include <linux/posix_types.h>
#if defined(__x86_64__)
#if defined(__x86_64__) || defined(__mips__)
#include <sys/stat.h>
#else
#define ino_t __kernel_ino_t
@ -68,7 +65,7 @@ namespace __sanitizer {
#if !defined(__powerpc64__) && !defined(__x86_64__) && !defined(__aarch64__)\
&& !defined(__mips__) && !defined(__s390__)\
&& !defined(__sparc__)
&& !defined(__sparc__) && !defined(__riscv)
COMPILER_CHECK(struct___old_kernel_stat_sz == sizeof(struct __old_kernel_stat));
#endif

View File

@ -354,7 +354,13 @@ struct __sanitizer_addrinfo {
int ai_family;
int ai_socktype;
int ai_protocol;
#if defined(__sparc__) && defined(_LP64)
int __ai_pad0;
#endif
unsigned ai_addrlen;
#if defined(__alpha__) || (defined(__i386__) && defined(_LP64))
int __ai_pad0;
#endif
char *ai_canonname;
void *ai_addr;
struct __sanitizer_addrinfo *ai_next;

View File

@ -230,7 +230,7 @@ namespace __sanitizer {
// has been removed from glibc 2.28.
#if defined(__aarch64__) || defined(__s390x__) || defined (__mips64) \
|| defined(__powerpc64__) || defined(__arch64__) || defined(__sparcv9) \
|| defined(__x86_64__)
|| defined(__x86_64__) || (defined(__riscv) && __riscv_xlen == 64)
#define SIZEOF_STRUCT_USTAT 32
#elif defined(__arm__) || defined(__i386__) || defined(__mips__) \
|| defined(__powerpc__) || defined(__s390__) || defined(__sparc__)

View File

@ -82,7 +82,7 @@ const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__mips__)
const unsigned struct_kernel_stat_sz = SANITIZER_ANDROID
? FIRST_32_SECOND_64(104, 128)
: FIRST_32_SECOND_64(144, 216);
: FIRST_32_SECOND_64(160, 216);
const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__s390__) && !defined(__s390x__)
const unsigned struct_kernel_stat_sz = 64;
@ -98,6 +98,9 @@ const unsigned struct_kernel_stat64_sz = 144;
const unsigned struct___old_kernel_stat_sz = 0;
const unsigned struct_kernel_stat_sz = 64;
const unsigned struct_kernel_stat64_sz = 104;
#elif defined(__riscv) && __riscv_xlen == 64
const unsigned struct_kernel_stat_sz = 128;
const unsigned struct_kernel_stat64_sz = 104;
#endif
struct __sanitizer_perf_event_attr {
unsigned type;

View File

@ -60,8 +60,8 @@ static inline uhwptr *GetCanonicFrame(uptr bp,
// Nope, this does not look right either. This means the frame after next does
// not have a valid frame pointer, but we can still extract the caller PC.
// Unfortunately, there is no way to decide between GCC and LLVM frame
// layouts. Assume GCC.
return bp_prev - 1;
// layouts. Assume LLVM.
return bp_prev;
#else
return (uhwptr*)bp;
#endif
@ -84,21 +84,14 @@ void BufferedStackTrace::UnwindFast(uptr pc, uptr bp, uptr stack_top,
IsAligned((uptr)frame, sizeof(*frame)) &&
size < max_depth) {
#ifdef __powerpc__
// PowerPC ABIs specify that the return address is saved on the
// *caller's* stack frame. Thus we must dereference the back chain
// to find the caller frame before extracting it.
// PowerPC ABIs specify that the return address is saved at offset
// 16 of the *caller's* stack frame. Thus we must dereference the
// back chain to find the caller frame before extracting it.
uhwptr *caller_frame = (uhwptr*)frame[0];
if (!IsValidFrame((uptr)caller_frame, stack_top, bottom) ||
!IsAligned((uptr)caller_frame, sizeof(uhwptr)))
break;
// For most ABIs the offset where the return address is saved is two
// register sizes. The exception is the SVR4 ABI, which uses an
// offset of only one register size.
#ifdef _CALL_SYSV
uhwptr pc1 = caller_frame[1];
#else
uhwptr pc1 = caller_frame[2];
#endif
#elif defined(__s390__)
uhwptr pc1 = frame[14];
#else

View File

@ -42,8 +42,8 @@
// DO NOT EDIT! THIS FILE HAS BEEN GENERATED!
//
// Generated with: generate_netbsd_syscalls.awk
// Generated date: 2018-10-30
// Generated from: syscalls.master,v 1.293 2018/07/31 13:00:13 rjs Exp
// Generated date: 2019-11-01
// Generated from: syscalls.master,v 1.296 2019/09/22 22:59:39 christos Exp
//
//===----------------------------------------------------------------------===//
@ -2433,30 +2433,31 @@ PRE_SYSCALL(uuidgen)(void *store_, long long count_) { /* Nothing to do */ }
POST_SYSCALL(uuidgen)(long long res, void *store_, long long count_) {
/* Nothing to do */
}
PRE_SYSCALL(getvfsstat)(void *buf_, long long bufsize_, long long flags_) {
PRE_SYSCALL(compat_90_getvfsstat)
(void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(getvfsstat)
POST_SYSCALL(compat_90_getvfsstat)
(long long res, void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
PRE_SYSCALL(statvfs1)(void *path_, void *buf_, long long flags_) {
PRE_SYSCALL(compat_90_statvfs1)(void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
PRE_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
POST_SYSCALL(statvfs1)
POST_SYSCALL(compat_90_statvfs1)
(long long res, void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
POST_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
PRE_SYSCALL(fstatvfs1)(long long fd_, void *buf_, long long flags_) {
PRE_SYSCALL(compat_90_fstatvfs1)(long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(fstatvfs1)
POST_SYSCALL(compat_90_fstatvfs1)
(long long res, long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
@ -2853,13 +2854,13 @@ PRE_SYSCALL(__fhopen40)(void *fhp_, long long fh_size_, long long flags_) {
}
POST_SYSCALL(__fhopen40)
(long long res, void *fhp_, long long fh_size_, long long flags_) {}
PRE_SYSCALL(__fhstatvfs140)
PRE_SYSCALL(compat_90_fhstatvfs1)
(void *fhp_, long long fh_size_, void *buf_, long long flags_) {
if (fhp_) {
PRE_READ(fhp_, fh_size_);
}
}
POST_SYSCALL(__fhstatvfs140)
POST_SYSCALL(compat_90_fhstatvfs1)
(long long res, void *fhp_, long long fh_size_, void *buf_, long long flags_) {}
PRE_SYSCALL(compat_50___fhstat40)(void *fhp_, long long fh_size_, void *sb_) {
if (fhp_) {
@ -3768,6 +3769,41 @@ POST_SYSCALL(clock_getcpuclockid2)
(long long res, long long idtype_, long long id_, void *clock_id_) {
/* Nothing to do */
}
PRE_SYSCALL(__getvfsstat90)(void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(__getvfsstat90)
(long long res, void *buf_, long long bufsize_, long long flags_) {
/* Nothing to do */
}
PRE_SYSCALL(__statvfs190)(void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
PRE_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
POST_SYSCALL(__statvfs190)
(long long res, void *path_, void *buf_, long long flags_) {
const char *path = (const char *)path_;
if (path) {
POST_READ(path, __sanitizer::internal_strlen(path) + 1);
}
}
PRE_SYSCALL(__fstatvfs190)(long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
POST_SYSCALL(__fstatvfs190)
(long long res, long long fd_, void *buf_, long long flags_) {
/* Nothing to do */
}
PRE_SYSCALL(__fhstatvfs190)
(void *fhp_, long long fh_size_, void *buf_, long long flags_) {
if (fhp_) {
PRE_READ(fhp_, fh_size_);
}
}
POST_SYSCALL(__fhstatvfs190)
(long long res, void *fhp_, long long fh_size_, void *buf_, long long flags_) {}
#undef SYS_MAXSYSARGS
} // extern "C"

View File

@ -113,9 +113,16 @@ ScopedGlobalProcessor::~ScopedGlobalProcessor() {
gp->mtx.Unlock();
}
static constexpr uptr kMaxAllowedMallocSize = 1ull << 40;
static uptr max_user_defined_malloc_size;
void InitializeAllocator() {
SetAllocatorMayReturnNull(common_flags()->allocator_may_return_null);
allocator()->Init(common_flags()->allocator_release_to_os_interval_ms);
max_user_defined_malloc_size = common_flags()->max_allocation_size_mb
? common_flags()->max_allocation_size_mb
<< 20
: kMaxAllowedMallocSize;
}
void InitializeAllocatorLate() {
@ -150,15 +157,17 @@ static void SignalUnsafeCall(ThreadState *thr, uptr pc) {
OutputReport(thr, rep);
}
static constexpr uptr kMaxAllowedMallocSize = 1ull << 40;
void *user_alloc_internal(ThreadState *thr, uptr pc, uptr sz, uptr align,
bool signal) {
if (sz >= kMaxAllowedMallocSize || align >= kMaxAllowedMallocSize) {
if (sz >= kMaxAllowedMallocSize || align >= kMaxAllowedMallocSize ||
sz > max_user_defined_malloc_size) {
if (AllocatorMayReturnNull())
return nullptr;
uptr malloc_limit =
Min(kMaxAllowedMallocSize, max_user_defined_malloc_size);
GET_STACK_TRACE_FATAL(thr, pc);
ReportAllocationSizeTooBig(sz, kMaxAllowedMallocSize, &stack);
ReportAllocationSizeTooBig(sz, malloc_limit, &stack);
}
void *p = allocator()->Allocate(&thr->proc()->alloc_cache, sz, align);
if (UNLIKELY(!p)) {

View File

@ -1,6 +1,5 @@
#include "tsan_ppc_regs.h"
.machine altivec
.section .text
.hidden __tsan_setjmp
.globl _setjmp

View File

@ -54,7 +54,6 @@ void InitializeFlags() {
{
CommonFlags cf;
cf.CopyFrom(*common_flags());
cf.print_summary = false;
cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
OverrideCommonFlags(cf);
}

View File

@ -819,21 +819,6 @@ void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
} // namespace __ubsan
void __ubsan::__ubsan_handle_cfi_bad_icall(CFIBadIcallData *CallData,
ValueHandle Function) {
GET_REPORT_OPTIONS(false);
CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
handleCFIBadIcall(&Data, Function, Opts);
}
void __ubsan::__ubsan_handle_cfi_bad_icall_abort(CFIBadIcallData *CallData,
ValueHandle Function) {
GET_REPORT_OPTIONS(true);
CFICheckFailData Data = {CFITCK_ICall, CallData->Loc, CallData->Type};
handleCFIBadIcall(&Data, Function, Opts);
Die();
}
void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
ValueHandle Value,
uptr ValidVtable) {

View File

@ -207,20 +207,12 @@ enum CFITypeCheckKind : unsigned char {
CFITCK_VMFCall,
};
struct CFIBadIcallData {
SourceLocation Loc;
const TypeDescriptor &Type;
};
struct CFICheckFailData {
CFITypeCheckKind CheckKind;
SourceLocation Loc;
const TypeDescriptor &Type;
};
/// \brief Handle control flow integrity failure for indirect function calls.
RECOVERABLE(cfi_bad_icall, CFIBadIcallData *Data, ValueHandle Function)
/// \brief Handle control flow integrity failures.
RECOVERABLE(cfi_check_fail, CFICheckFailData *Data, ValueHandle Function,
uptr VtableIsValid)

View File

@ -12,7 +12,6 @@
#ifndef UBSAN_PLATFORM_H
#define UBSAN_PLATFORM_H
#ifndef CAN_SANITIZE_UB
// Other platforms should be easy to add, and probably work as-is.
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || \
defined(__NetBSD__) || defined(__OpenBSD__) || \
@ -22,6 +21,5 @@
#else
# define CAN_SANITIZE_UB 0
#endif
#endif //CAN_SANITIZE_UB
#endif