Skip to content

Commit

Permalink
syscall: add wasip1 RandomGet
Browse files Browse the repository at this point in the history
This function is needed starting with Go 1.24.
  • Loading branch information
aykevl committed Feb 21, 2025
1 parent 019cff6 commit b172cac
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/syscall/syscall_libc_wasi.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ type RawSockaddrInet6 struct {
// stub
}

func RandomGet(b []byte) error {
if len(b) > 0 {
libc_arc4random_buf(unsafe.Pointer(&b[0]), uint(len(b)))
}
return nil
}

// This is a stub, it is not functional.
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno)

Expand Down Expand Up @@ -483,3 +490,8 @@ func libc_fdclosedir(unsafe.Pointer) int32
//
//export readdir
func libc_readdir(unsafe.Pointer) *Dirent

// void arc4random_buf(void *buf, size_t buflen);
//
//export arc4random_buf
func libc_arc4random_buf(buf unsafe.Pointer, buflen uint)

0 comments on commit b172cac

Please sign in to comment.