Skip to content

Commit

Permalink
Avoid allocating a register in zap() assembly
Browse files Browse the repository at this point in the history
See https://bugs.llvm.org/show_bug.cgi?id=15495

Also add explicit_bzero() (glibc, FreeBSD) and explicit_memset()
(NetBSD) as alternatives.

[ghudson@mit.edu: added explicit_bzero() and explicit_memset()]
  • Loading branch information
cryptomilk authored and greghudson committed Jan 14, 2019
1 parent 7e127eb commit 7391e8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ AC_PROG_LEX
AC_C_CONST
AC_HEADER_DIRENT
AC_FUNC_STRERROR_R
AC_CHECK_FUNCS(strdup setvbuf seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell access getcwd srand48 srand srandom stat strchr strerror timegm)
AC_CHECK_FUNCS(strdup setvbuf seteuid setresuid setreuid setegid setresgid setregid setsid flock fchmod chmod strptime geteuid setenv unsetenv getenv gmtime_r localtime_r bswap16 bswap64 mkstemp getusershell access getcwd srand48 srand srandom stat strchr strerror timegm explicit_bzero explicit_memset)

AC_CHECK_FUNC(mkstemp,
[MKSTEMP_ST_OBJ=
Expand Down
6 changes: 5 additions & 1 deletion src/include/k5-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,10 @@ static inline void zap(void *ptr, size_t len)
if (len > 0)
memset_s(ptr, len, 0, len);
}
#elif defined(HAVE_EXPLICIT_BZERO)
# define zap(ptr, len) explicit_bzero(ptr, len)
#elif defined(HAVE_EXPLICIT_MEMSET)
# define zap(ptr, len) explicit_memset(ptr, 0, len)
#elif defined(__GNUC__) || defined(__clang__)
/*
* Use an asm statement which declares a memory clobber to force the memset to
Expand All @@ -1032,7 +1036,7 @@ static inline void zap(void *ptr, size_t len)
{
if (len > 0)
memset(ptr, 0, len);
__asm__ __volatile__("" : : "r" (ptr) : "memory");
__asm__ __volatile__("" : : "g" (ptr) : "memory");
}
#else
/*
Expand Down

0 comments on commit 7391e8b

Please sign in to comment.