blob: b9c5b380ac92479e8e70b7325df21543fce00f42 [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);
Joachim Bauch5b32f232018-03-07 20:02:26 +010029#if !defined(__pnacl__)
Joachim Bauch58daf402017-12-21 22:00:34 +010030 /* As best as we can tell, this is sufficient to break any optimisations that
31 might try to eliminate "superfluous" memsets. If there's an easy way to
32 detect memset_s, it would be better to use that. */
33 __asm__ __volatile__("" : : "r"(ptr) : "memory"); // NOLINT
34#endif
Joachim Bauch5b32f232018-03-07 20:02:26 +010035#endif // !WEBRTC_WIN
Joachim Bauch58daf402017-12-21 22:00:34 +010036}
37
38} // namespace rtc