1 //===-- hwasan_memintrinsics.cpp --------------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 /// This file is a part of HWAddressSanitizer and contains HWASAN versions of
11 /// memset, memcpy and memmove
13 //===----------------------------------------------------------------------===//
17 #include "hwasan_checks.h"
18 #include "hwasan_flags.h"
19 #include "hwasan_interface_internal.h"
20 #include "sanitizer_common/sanitizer_libc.h"
22 using namespace __hwasan
;
24 void *__hwasan_memset(void *block
, int c
, uptr size
) {
25 CheckAddressSized
<ErrorAction::Recover
, AccessType::Store
>(
26 reinterpret_cast<uptr
>(block
), size
);
27 return memset(block
, c
, size
);
30 void *__hwasan_memcpy(void *to
, const void *from
, uptr size
) {
31 CheckAddressSized
<ErrorAction::Recover
, AccessType::Store
>(
32 reinterpret_cast<uptr
>(to
), size
);
33 CheckAddressSized
<ErrorAction::Recover
, AccessType::Load
>(
34 reinterpret_cast<uptr
>(from
), size
);
35 return memcpy(to
, from
, size
);
38 void *__hwasan_memmove(void *to
, const void *from
, uptr size
) {
39 CheckAddressSized
<ErrorAction::Recover
, AccessType::Store
>(
40 reinterpret_cast<uptr
>(to
), size
);
41 CheckAddressSized
<ErrorAction::Recover
, AccessType::Load
>(
42 reinterpret_cast<uptr
>(from
), size
);
43 return memmove(to
, from
, size
);