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