You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

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