1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2024 Xi Ruoyao <xry111@xry111.site>. All Rights Reserved. 4 */ 5 #ifndef __ASM_VDSO_GETRANDOM_H 6 #define __ASM_VDSO_GETRANDOM_H 7 8 #ifndef __ASSEMBLY__ 9 10 #include <asm/unistd.h> 11 #include <asm/vdso/vdso.h> 12 13 static __always_inline ssize_t getrandom_syscall(void *_buffer, size_t _len, unsigned int _flags) 14 { 15 register long ret asm("a0"); 16 register long nr asm("a7") = __NR_getrandom; 17 register void *buffer asm("a0") = _buffer; 18 register size_t len asm("a1") = _len; 19 register unsigned int flags asm("a2") = _flags; 20 21 asm volatile( 22 " syscall 0\n" 23 : "+r" (ret) 24 : "r" (nr), "r" (buffer), "r" (len), "r" (flags) 25 : "$t0", "$t1", "$t2", "$t3", "$t4", "$t5", "$t6", "$t7", "$t8", 26 "memory"); 27 28 return ret; 29 } 30 31 static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(void) 32 { 33 return (const struct vdso_rng_data *)(get_vdso_data() + VVAR_LOONGARCH_PAGES_START * 34 PAGE_SIZE + offsetof(struct loongarch_vdso_data, rng_data)); 35 } 36 37 #endif /* !__ASSEMBLY__ */ 38 39 #endif /* __ASM_VDSO_GETRANDOM_H */ 40