Commit e6955f4d authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

asan_region_is_poisoned

Summary: [folly] `asan_region_is_poisoned` to wrap Address Sanitizer's `__asan_region_is_poisoned`.

Reviewed By: ot, luciang, markisaa

Differential Revision: D25651040

fbshipit-source-id: 0c8f1d0203ada43746b5e2e71c1bd8b883248f68
parent 59fe375d
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/memory/SanitizeAddress.h>
// Address Sanitizer interface may be found at:
// https://github.com/llvm-mirror/compiler-rt/blob/master/include/sanitizer/asan_interface.h
extern "C" FOLLY_ATTR_WEAK void* __asan_region_is_poisoned(void*, std::size_t);
namespace folly {
namespace detail {
void* asan_region_is_poisoned_(void* const ptr, std::size_t len) {
return __asan_region_is_poisoned(ptr, len);
}
} // namespace detail
} // namespace folly
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <folly/Portability.h>
namespace folly {
namespace detail {
void* asan_region_is_poisoned_(void* ptr, std::size_t len);
}
// asan_region_is_poisoned
//
// mimic: __asan_region_is_poisoned, llvm compiler-rt
//
// Returns the address of the first byte in the region known to be poisoned,
// or nullptr if there is no such byte. If Address Sanitizer is unavailable,
// always returns nullptr.
FOLLY_ALWAYS_INLINE static void* asan_region_is_poisoned(
void* const ptr,
std::size_t const len) {
return kIsSanitizeAddress //
? detail::asan_region_is_poisoned_(ptr, len)
: nullptr;
}
} // namespace folly
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <folly/memory/SanitizeAddress.h>
#include <folly/portability/GTest.h>
class SanitizeAddressTest : public testing::Test {};
TEST_F(SanitizeAddressTest, asan_region_is_poisoned) {
auto data = malloc(4096);
EXPECT_EQ(nullptr, folly::asan_region_is_poisoned(data, 4096));
free(data);
EXPECT_EQ(
folly::kIsSanitizeAddress ? data : nullptr,
folly::asan_region_is_poisoned(data, 4096));
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment