Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_exceptions.cpp
35236 views
//===-- hwasan_exceptions.cpp ---------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of HWAddressSanitizer.9//10// HWAddressSanitizer runtime.11//===----------------------------------------------------------------------===//1213#include "hwasan_poisoning.h"14#include "sanitizer_common/sanitizer_common.h"1516#include <unwind.h>1718using namespace __hwasan;19using namespace __sanitizer;2021typedef _Unwind_Reason_Code PersonalityFn(int version, _Unwind_Action actions,22uint64_t exception_class,23_Unwind_Exception* unwind_exception,24_Unwind_Context* context);2526// Pointers to the _Unwind_GetGR and _Unwind_GetCFA functions are passed in27// instead of being called directly. This is to handle cases where the unwinder28// is statically linked and the sanitizer runtime and the program are linked29// against different unwinders. The _Unwind_Context data structure is opaque so30// it may be incompatible between unwinders.31typedef uintptr_t GetGRFn(_Unwind_Context* context, int index);32typedef uintptr_t GetCFAFn(_Unwind_Context* context);3334extern "C" SANITIZER_INTERFACE_ATTRIBUTE _Unwind_Reason_Code35__hwasan_personality_wrapper(int version, _Unwind_Action actions,36uint64_t exception_class,37_Unwind_Exception* unwind_exception,38_Unwind_Context* context,39PersonalityFn* real_personality, GetGRFn* get_gr,40GetCFAFn* get_cfa) {41_Unwind_Reason_Code rc;42if (real_personality)43rc = real_personality(version, actions, exception_class, unwind_exception,44context);45else46rc = _URC_CONTINUE_UNWIND;4748// We only untag frames without a landing pad because landing pads are49// responsible for untagging the stack themselves if they resume.50//51// Here we assume that the frame record appears after any locals. This is not52// required by AAPCS but is a requirement for HWASAN instrumented functions.53if ((actions & _UA_CLEANUP_PHASE) && rc == _URC_CONTINUE_UNWIND) {54#if defined(__x86_64__)55uptr fp = get_gr(context, 6); // rbp56#elif defined(__aarch64__)57uptr fp = get_gr(context, 29); // x2958#elif SANITIZER_RISCV6459uptr fp = get_gr(context, 8); // x860#else61#error Unsupported architecture62#endif63uptr sp = get_cfa(context);64TagMemory(UntagAddr(sp), UntagAddr(fp) - UntagAddr(sp),65GetTagFromPointer(sp));66}6768return rc;69}707172