explicit_bzero.c 1.8 KB

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