blob: c5cd2d5921a1c13f2d067dacebd6720fe6344c35 [file] [log] [blame]
Joachim Bauch58daf402017-12-21 21:00:341/*
2 * Copyright 2017 The WebRTC Project Authors. All rights reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef RTC_BASE_ZERO_MEMORY_H_
12#define RTC_BASE_ZERO_MEMORY_H_
13
Yves Gerey988cc082018-10-23 10:03:0114#include <stddef.h>
Jonas Olssona4d87372019-07-05 17:08:3315
Joachim Bauch58daf402017-12-21 21:00:3416#include <type_traits>
17
18#include "api/array_view.h"
19
Evan Shrubsolefe5bdd72025-02-07 13:24:0520namespace webrtc {
Joachim Bauch58daf402017-12-21 21:00:3421
22// Fill memory with zeros in a way that the compiler doesn't optimize it away
23// even if the pointer is not used afterwards.
24void ExplicitZeroMemory(void* ptr, size_t len);
25
26template <typename T,
27 typename std::enable_if<!std::is_const<T>::value &&
28 std::is_trivial<T>::value>::type* = nullptr>
29void ExplicitZeroMemory(rtc::ArrayView<T> a) {
30 ExplicitZeroMemory(a.data(), a.size());
31}
32
Evan Shrubsolefe5bdd72025-02-07 13:24:0533} // namespace webrtc
34
35// Re-export symbols from the webrtc namespace for backwards compatibility.
36// TODO(bugs.webrtc.org/4222596): Remove once all references are updated.
37namespace rtc {
38using ::webrtc::ExplicitZeroMemory;
Joachim Bauch58daf402017-12-21 21:00:3439} // namespace rtc
40
41#endif // RTC_BASE_ZERO_MEMORY_H_