Joachim Bauch | 58daf40 | 2017-12-21 22:00:34 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
| 20 | namespace rtc { |
| 21 | |
| 22 | // Code and comment taken from "OPENSSL_cleanse" of BoringSSL. |
| 23 | void 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 Bauch | 5b32f23 | 2018-03-07 20:02:26 +0100 | [diff] [blame] | 29 | #if !defined(__pnacl__) |
Joachim Bauch | 58daf40 | 2017-12-21 22:00:34 +0100 | [diff] [blame] | 30 | /* 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 Bauch | 5b32f23 | 2018-03-07 20:02:26 +0100 | [diff] [blame] | 35 | #endif // !WEBRTC_WIN |
Joachim Bauch | 58daf40 | 2017-12-21 22:00:34 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | } // namespace rtc |