Annotation of embedaddon/lighttpd/src/safe_memclear.c, revision 1.1
1.1 ! misho 1: #include "first.h"
! 2:
! 3: #include "settings.h"
! 4:
! 5: #include "safe_memclear.h"
! 6:
! 7: #include <string.h>
! 8:
! 9: #if !defined(HAVE_MEMSET_S) && !defined(HAVE_EXPLICIT_BZERO)
! 10:
! 11: # if defined(HAVE_WEAK_SYMBOLS)
! 12: /* it seems weak functions are never inlined, even for static builds */
! 13: __attribute__((weak)) void __li_safe_memset_hook(void *buf, size_t len);
! 14:
! 15: void __li_safe_memset_hook(void *buf, size_t len)
! 16: {
! 17: UNUSED(buf);
! 18: UNUSED(len);
! 19: }
! 20: # endif /* HAVE_WEAK_SYMBOLS */
! 21:
! 22: static void* safe_memset(void *s, int c, size_t n)
! 23: {
! 24: if (n > 0) {
! 25: volatile unsigned volatile_zero = 0;
! 26: volatile unsigned char *vs = (volatile unsigned char*)s;
! 27:
! 28: do {
! 29: memset(s, c, n);
! 30: } while (vs[volatile_zero] != (unsigned char)c);
! 31: # if defined(HAVE_WEAK_SYMBOLS)
! 32: __li_safe_memset_hook(s, n);
! 33: # endif /* HAVE_WEAK_SYMBOLS */
! 34: }
! 35:
! 36: return s;
! 37: }
! 38: #endif /* !defined(HAVE_MEMSET_S) && !defined(HAVE_EXPLICIT_BZERO) */
! 39:
! 40:
! 41: void safe_memclear(void *s, size_t n) {
! 42: #if defined(HAVE_MEMSET_S)
! 43: memset_s(s, n, 0, n);
! 44: #elif defined(HAVE_EXPLICIT_BZERO)
! 45: explicit_bzero(s, n);
! 46: #else
! 47: safe_memset(s, 0, n);
! 48: #endif
! 49: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>