blob: 63600b8d2e2ffa3e99ef34677613529ba606f34c [file] [log] [blame]
Joachim Bauch58daf402017-12-21 22:00:34 +01001/*
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#if defined(WEBRTC_WIN)
12#include <windows.h>
13#else
14#include <string.h>
15#endif
16
17#include "rtc_base/checks.h"
18#include "rtc_base/zero_memory.h"
19
20namespace rtc {
21
22// Code and comment taken from "OPENSSL_cleanse" of BoringSSL.
23void ExplicitZeroMemory(void* ptr, size_t len) {
24 RTC_DCHECK(ptr || !len);
25#if defined(WEBRTC_WIN)
26 SecureZeroMemory(ptr, len);
27#else
28 memset(ptr, 0, len);
29 /* As best as we can tell, this is sufficient to break any optimisations that
30 might try to eliminate "superfluous" memsets. If there's an easy way to
31 detect memset_s, it would be better to use that. */
32 __asm__ __volatile__("" : : "r"(ptr) : "memory"); // NOLINT
33#endif
34}
35
36} // namespace rtc