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
17 #include "php.h"
18
19 #ifndef HAVE_EXPLICIT_BZERO
20
21 /* $OpenBSD: explicit_bzero.c,v 1.4 2015/08/31 02:53:57 guenther Exp $ */
22 /*
23 * Public domain.
24 * Written by Matthew Dempsky.
25 */
26
27 #include <string.h>
28
php_explicit_bzero(void * dst,size_t siz)29 PHPAPI void php_explicit_bzero(void *dst, size_t siz)
30 {
31 #ifdef HAVE_EXPLICIT_MEMSET
32 explicit_memset(dst, 0, siz);
33 #elif defined(PHP_WIN32)
34 RtlSecureZeroMemory(dst, siz);
35 #elif defined(__GNUC__)
36 memset(dst, 0, siz);
37 asm __volatile__("" :: "r"(dst) : "memory");
38 #else
39 size_t i = 0;
40 volatile unsigned char *buf = (volatile unsigned char *)dst;
41
42 for (; i < siz; i ++)
43 buf[i] = 0;
44 #endif
45 }
46 #endif
47