Path: blob/main/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_memintrinsics.cpp
35236 views
//===-- hwasan_memintrinsics.cpp --------------------------------*- C++ -*-===//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/// \file9/// This file is a part of HWAddressSanitizer and contains HWASAN versions of10/// memset, memcpy and memmove11///12//===----------------------------------------------------------------------===//1314#include <string.h>15#include "hwasan.h"16#include "hwasan_checks.h"17#include "hwasan_flags.h"18#include "hwasan_interface_internal.h"19#include "sanitizer_common/sanitizer_libc.h"2021using namespace __hwasan;2223void *__hwasan_memset(void *block, int c, uptr size) {24CheckAddressSized<ErrorAction::Recover, AccessType::Store>(25reinterpret_cast<uptr>(block), size);26return memset(block, c, size);27}2829void *__hwasan_memcpy(void *to, const void *from, uptr size) {30CheckAddressSized<ErrorAction::Recover, AccessType::Store>(31reinterpret_cast<uptr>(to), size);32CheckAddressSized<ErrorAction::Recover, AccessType::Load>(33reinterpret_cast<uptr>(from), size);34return memcpy(to, from, size);35}3637void *__hwasan_memmove(void *to, const void *from, uptr size) {38CheckAddressSized<ErrorAction::Recover, AccessType::Store>(39reinterpret_cast<uptr>(to), size);40CheckAddressSized<ErrorAction::Recover, AccessType::Load>(41reinterpret_cast<uptr>(from), size);42return memmove(to, from, size);43}4445void *__hwasan_memset_match_all(void *block, int c, uptr size,46u8 match_all_tag) {47if (GetTagFromPointer(reinterpret_cast<uptr>(block)) != match_all_tag)48CheckAddressSized<ErrorAction::Recover, AccessType::Store>(49reinterpret_cast<uptr>(block), size);50return memset(block, c, size);51}5253void *__hwasan_memcpy_match_all(void *to, const void *from, uptr size,54u8 match_all_tag) {55if (GetTagFromPointer(reinterpret_cast<uptr>(to)) != match_all_tag)56CheckAddressSized<ErrorAction::Recover, AccessType::Store>(57reinterpret_cast<uptr>(to), size);58if (GetTagFromPointer(reinterpret_cast<uptr>(from)) != match_all_tag)59CheckAddressSized<ErrorAction::Recover, AccessType::Load>(60reinterpret_cast<uptr>(from), size);61return memcpy(to, from, size);62}6364void *__hwasan_memmove_match_all(void *to, const void *from, uptr size,65u8 match_all_tag) {66if (GetTagFromPointer(reinterpret_cast<uptr>(to)) != match_all_tag)67CheckAddressSized<ErrorAction::Recover, AccessType::Store>(68reinterpret_cast<uptr>(to), size);69if (GetTagFromPointer(reinterpret_cast<uptr>(from)) != match_all_tag)70CheckAddressSized<ErrorAction::Recover, AccessType::Load>(71reinterpret_cast<uptr>(from), size);72return memmove(to, from, size);73}747576