File Index
Files and directories
Sign in
FILE

getrandom.h

File preview with syntax highlighting.

linux-6.19.14/arch/x86/include/asm/vdso/getrandom.h C
 1/* SPDX-License-Identifier: GPL-2.0 */
 2/*
 3 * Copyright (C) 2022-2024 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
 4 */
 5#ifndef __ASM_VDSO_GETRANDOM_H
 6#define __ASM_VDSO_GETRANDOM_H
 7
 8#ifndef __ASSEMBLER__
 9
10#include <asm/unistd.h>
11
12/**
13 * getrandom_syscall - Invoke the getrandom() syscall.
14 * @buffer:	Destination buffer to fill with random bytes.
15 * @len:	Size of @buffer in bytes.
16 * @flags:	Zero or more GRND_* flags.
17 * Returns:	The number of random bytes written to @buffer, or a negative value indicating an error.
18 */
19static __always_inline ssize_t getrandom_syscall(void *buffer, size_t len, unsigned int flags)
20{
21	long ret;
22
23	asm ("syscall" : "=a" (ret) :
24	     "0" (__NR_getrandom), "D" (buffer), "S" (len), "d" (flags) :
25	     "rcx", "r11", "memory");
26
27	return ret;
28}
29
30#endif /* !__ASSEMBLER__ */
31
32#endif /* __ASM_VDSO_GETRANDOM_H */
~/ Read-only file preview.