mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

The generic storage implementation provides the same features as the custom one. However it can be shared between architectures, making maintenance easier. This switch also moves the random state data out of the time data page. The currently used hardcoded __VDSO_RND_DATA_OFFSET does not take into account changes to the time data page layout. Co-developed-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Nam Cao <namcao@linutronix.de> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/all/20250204-vdso-store-rng-v3-8-13a4669dfc8c@linutronix.de
38 lines
1,009 B
C
38 lines
1,009 B
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
|
|
#ifndef __ASM_VDSO_GETRANDOM_H
|
|
#define __ASM_VDSO_GETRANDOM_H
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
#include <asm/unistd.h>
|
|
#include <asm/vdso/vsyscall.h>
|
|
#include <vdso/datapage.h>
|
|
|
|
/**
|
|
* getrandom_syscall - Invoke the getrandom() syscall.
|
|
* @buffer: Destination buffer to fill with random bytes.
|
|
* @len: Size of @buffer in bytes.
|
|
* @flags: Zero or more GRND_* flags.
|
|
* Returns: The number of random bytes written to @buffer, or a negative value indicating an error.
|
|
*/
|
|
static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, unsigned int _flags)
|
|
{
|
|
register void *buffer asm ("x0") = _buffer;
|
|
register size_t len asm ("x1") = _len;
|
|
register unsigned int flags asm ("x2") = _flags;
|
|
register long ret asm ("x0");
|
|
register long nr asm ("x8") = __NR_getrandom;
|
|
|
|
asm volatile(
|
|
" svc #0\n"
|
|
: "=r" (ret)
|
|
: "r" (buffer), "r" (len), "r" (flags), "r" (nr)
|
|
: "memory");
|
|
|
|
return ret;
|
|
}
|
|
|
|
#endif /* !__ASSEMBLY__ */
|
|
|
|
#endif /* __ASM_VDSO_GETRANDOM_H */
|