| # Copyright 2022 The Pigweed Authors |
| # |
| # 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 |
| # |
| # https://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. |
| |
| # Patch the fit::function implementation for use in Pigweed: |
| # |
| # - Use PW_ASSERT instead of __builtin_abort. |
| # - Temporarily disable sanitizers when invoking a function for b/241567321. |
| # |
| diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h |
| --- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h |
| +++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/function_internal.h |
| @@ -15,6 +15,8 @@ |
| #include <utility> |
| |
| #include "nullable.h" |
| +#include "pw_assert/assert.h" |
| +#include "pw_preprocessor/compiler.h" |
| |
| namespace fit { |
| namespace internal { |
| @@ -41,7 +43,7 @@ template <typename Result, typename... Args> |
| struct target<decltype(nullptr), |
| /*is_inline=*/true, /*is_shared=*/false, Result, Args...> |
| final { |
| - static Result invoke(void* /*bits*/, Args... /*args*/) { __builtin_abort(); } |
| + static Result invoke(void* /*bits*/, Args... /*args*/) { PW_ASSERT(false); } |
| |
| static const target_ops<Result, Args...> ops; |
| }; |
| @@ -319,7 +321,8 @@ class function_base<inline_target_size, require_inline, Result(Args...)> { |
| // Note that fit::callback will release the target immediately after |
| // invoke() (also affecting any share()d copies). |
| // Aborts if the function's target is empty. |
| - Result invoke(Args... args) const { |
| + // TODO(b/241567321): Remove "no sanitize" after pw_protobuf is fixed. |
| + Result invoke(Args... args) const PW_NO_SANITIZE("function") { |
| return storage_.ops->invoke(&storage_.bits, std::forward<Args>(args)...); |
| } |
| |
| @@ -430,7 +433,7 @@ class function_base<inline_target_size, require_inline, Result(Args...)> { |
| void check_target_type() const { |
| if (target_type<Callable>::ops.target_type_id(nullptr, &target_type<Callable>::ops) != |
| target_type_id()) { |
| - __builtin_abort(); |
| + PW_ASSERT(false); |
| } |
| } |
| |
| diff --git a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h |
| --- a/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h |
| +++ b/third_party/fuchsia/repo/sdk/lib/fit/include/lib/fit/nullable.h |
| @@ -11,6 +11,8 @@ |
| #include <type_traits> |
| #include <utility> |
| |
| +#include "pw_assert/assert.h" |
| + |
| namespace fit { |
| |
| // Determines whether a type can be compared with nullptr. |
| @@ -130,28 +132,28 @@ class nullable<T, true> final { |
| if (has_value()) { |
| return value_; |
| } else { |
| - __builtin_abort(); |
| + PW_ASSERT(false); |
| } |
| } |
| constexpr const T& value() const& { |
| if (has_value()) { |
| return value_; |
| } else { |
| - __builtin_abort(); |
| + PW_ASSERT(false); |
| } |
| } |
| constexpr T&& value() && { |
| if (has_value()) { |
| return std::move(value_); |
| } else { |
| - __builtin_abort(); |
| + PW_ASSERT(false); |
| } |
| } |
| constexpr const T&& value() const&& { |
| if (has_value()) { |
| return std::move(value_); |
| } else { |
| - __builtin_abort(); |
| + PW_ASSERT(false); |
| } |
| } |
| |