mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
AK: Add secure_zero() implementation so it can be used on all platforms
Serenity has explicit_bzero() in LibC with the same implementation, however we need to be able to use this from Lagom on all platforms that we support building serenity on. I've implemented it in AK for this reason.
This commit is contained in:
parent
f6ad7dfc0b
commit
ff1e5aa935
1 changed files with 13 additions and 0 deletions
13
AK/Memory.h
13
AK/Memory.h
|
@ -40,3 +40,16 @@ ALWAYS_INLINE void fast_u32_fill(u32* dest, u32 value, size_t count)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace AK {
|
||||
inline void secure_zero(void* ptr, size_t size)
|
||||
{
|
||||
__builtin_memset(ptr, 0, size);
|
||||
// The memory barrier is here to avoid the compiler optimizing
|
||||
// away the memset when we rely on it for wiping secrets.
|
||||
asm volatile("" ::
|
||||
: "memory");
|
||||
}
|
||||
}
|
||||
|
||||
using AK::secure_zero;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue