Skip to content

Commit 3476100

Browse files
aykevldeadprogram
authored andcommitted
syscall: add wasip1 RandomGet
This function is needed starting with Go 1.24.
1 parent 07c7eff commit 3476100

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/syscall/syscall_libc_wasi.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,13 @@ type RawSockaddrInet6 struct {
438438
// stub
439439
}
440440

441+
func RandomGet(b []byte) error {
442+
if len(b) > 0 {
443+
libc_arc4random_buf(unsafe.Pointer(&b[0]), uint(len(b)))
444+
}
445+
return nil
446+
}
447+
441448
// This is a stub, it is not functional.
442449
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)
443450

@@ -483,3 +490,8 @@ func libc_fdclosedir(unsafe.Pointer) int32
483490
//
484491
//export readdir
485492
func libc_readdir(unsafe.Pointer) *Dirent
493+
494+
// void arc4random_buf(void *buf, size_t buflen);
495+
//
496+
//export arc4random_buf
497+
func libc_arc4random_buf(buf unsafe.Pointer, buflen uint)

0 commit comments

Comments
 (0)