explicit_bzero.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. +----------------------------------------------------------------------+
  3. | Copyright (c) The PHP Group |
  4. +----------------------------------------------------------------------+
  5. | This source file is subject to version 3.01 of the PHP license, |
  6. | that is bundled with this package in the file LICENSE, and is |
  7. | available through the world-wide-web at the following url: |
  8. | https://www.php.net/license/3_01.txt |
  9. | If you did not receive a copy of the PHP license and are unable to |
  10. | obtain it through the world-wide-web, please send a note to |
  11. | license@php.net so we can mail you a copy immediately. |
  12. +----------------------------------------------------------------------+
  13. | Author: |
  14. +----------------------------------------------------------------------+
  15. */
  16. #include "php.h"
  17. #ifndef HAVE_EXPLICIT_BZERO
  18. /* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
  19. /*
  20. * Public domain.
  21. * Written by Matthew Dempsky.
  22. */
  23. #include <string.h>
  24. PHPAPI void php_explicit_bzero(void *dst, size_t siz)
  25. {
  26. #ifdef HAVE_EXPLICIT_MEMSET
  27. explicit_memset(dst, 0, siz);
  28. #elif defined(PHP_WIN32)
  29. RtlSecureZeroMemory(dst, siz);
  30. #elif defined(__GNUC__)
  31. memset(dst, 0, siz);
  32. asm __volatile__("" :: "r"(dst) : "memory");
  33. #else
  34. size_t i = 0;
  35. volatile unsigned char *buf = (volatile unsigned char *)dst;
  36. for (; i < siz; i ++)
  37. buf[i] = 0;
  38. #endif
  39. }
  40. #endif