diff --git a/imports/wasi_snapshot_preview1/fs.go b/imports/wasi_snapshot_preview1/fs.go index fe7ea8b5..9226298f 100644 --- a/imports/wasi_snapshot_preview1/fs.go +++ b/imports/wasi_snapshot_preview1/fs.go @@ -6,7 +6,6 @@ import ( "io/fs" "math" "path" - "reflect" "strings" "syscall" "unsafe" @@ -1988,18 +1987,15 @@ func pathSymlinkFn(_ context.Context, mod api.Module, params []uint64) syscall.E return dir.FS.Symlink( // Do not join old path since it's only resolved when dereference the link created here. // And the dereference result depends on the opening directory's file descriptor at that point. - bufToStr(oldPathBuf, int(oldPathLen)), - path.Join(dir.Name, bufToStr(newPathBuf, int(newPathLen))), + bufToStr(oldPathBuf), + path.Join(dir.Name, bufToStr(newPathBuf)), ) } // bufToStr converts the given byte slice as string unsafely. -func bufToStr(buf []byte, l int) string { - return *(*string)(unsafe.Pointer(&reflect.SliceHeader{ //nolint - Data: uintptr(unsafe.Pointer(&buf[0])), - Len: l, - Cap: l, - })) +func bufToStr(buf []byte) string { + // TODO: use unsafe.String after flooring Go 1.20. + return *(*string)(unsafe.Pointer(&buf)) } // pathUnlinkFile is the WASI function named PathUnlinkFileName which unlinks a diff --git a/internal/integration_test/bench/testdata/case.go b/internal/integration_test/bench/testdata/case.go index 676d2380..bdc1ea9f 100644 --- a/internal/integration_test/bench/testdata/case.go +++ b/internal/integration_test/bench/testdata/case.go @@ -3,7 +3,6 @@ package main import ( "encoding/base64" "math/rand" - "reflect" "strings" "unsafe" ) @@ -27,12 +26,7 @@ func getRandomString() string { var bufPtr *byte var bufSize int getRandomStringRaw(&bufPtr, &bufSize) - //nolint - return *(*string)(unsafe.Pointer(&reflect.SliceHeader{ - Data: uintptr(unsafe.Pointer(bufPtr)), - Len: uintptr(bufSize), - Cap: uintptr(bufSize), - })) + return unsafe.String(bufPtr, bufSize) } //export base64 diff --git a/internal/integration_test/bench/testdata/case.wasm b/internal/integration_test/bench/testdata/case.wasm index 9d33eaee..9a5c9e83 100755 Binary files a/internal/integration_test/bench/testdata/case.wasm and b/internal/integration_test/bench/testdata/case.wasm differ diff --git a/internal/integration_test/fuzz/wazerolib/nodiff.go b/internal/integration_test/fuzz/wazerolib/nodiff.go index 9d0bfef2..a8141e17 100644 --- a/internal/integration_test/fuzz/wazerolib/nodiff.go +++ b/internal/integration_test/fuzz/wazerolib/nodiff.go @@ -21,17 +21,18 @@ import ( // //export require_no_diff func require_no_diff(binaryPtr uintptr, binarySize int, watPtr uintptr, watSize int, checkMemory bool) { - wasmBin := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Data: binaryPtr, - Len: binarySize, - Cap: binarySize, - })) + // TODO: use unsafe.Slice after flooring Go 1.20. + var wasmBin []byte + wasmHdr := (*reflect.SliceHeader)(unsafe.Pointer(&wasmBin)) + wasmHdr.Data = binaryPtr + wasmHdr.Len = binarySize + wasmHdr.Cap = binarySize - wat := *(*string)(unsafe.Pointer(&reflect.SliceHeader{ - Data: watPtr, - Len: watSize, - Cap: watSize, - })) + // TODO: use unsafe.String after flooring Go 1.20. + var wat string + watHdr := (*reflect.StringHeader)(unsafe.Pointer(&wat)) + watHdr.Data = watPtr + watHdr.Len = watSize failed := true defer func() { @@ -48,7 +49,6 @@ func require_no_diff(binaryPtr uintptr, binarySize int, watPtr uintptr, watSize }) failed = false - return } // We haven't had public APIs for referencing all the imported entries from wazero.CompiledModule, diff --git a/internal/integration_test/fuzz/wazerolib/validate.go b/internal/integration_test/fuzz/wazerolib/validate.go index e0237b85..79c46fa7 100644 --- a/internal/integration_test/fuzz/wazerolib/validate.go +++ b/internal/integration_test/fuzz/wazerolib/validate.go @@ -14,11 +14,12 @@ import ( // //export validate func validate(binaryPtr uintptr, binarySize int) { - wasmBin := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{ - Data: binaryPtr, - Len: binarySize, - Cap: binarySize, - })) + // TODO: use unsafe.Slice after flooring Go 1.20. + var wasmBin []byte + wasmHdr := (*reflect.SliceHeader)(unsafe.Pointer(&wasmBin)) + wasmHdr.Data = binaryPtr + wasmHdr.Len = binarySize + wasmHdr.Cap = binarySize failed := true defer func() { diff --git a/internal/integration_test/vs/time/time_test.go b/internal/integration_test/vs/time/time_test.go index 67e310ad..07de8e29 100644 --- a/internal/integration_test/vs/time/time_test.go +++ b/internal/integration_test/vs/time/time_test.go @@ -17,7 +17,6 @@ import ( "golang.org/x/sys/unix" ) -//go:noescape //go:linkname nanotime runtime.nanotime func nanotime() int64 diff --git a/internal/platform/mmap_windows.go b/internal/platform/mmap_windows.go index 9c6fa622..fb8944b4 100644 --- a/internal/platform/mmap_windows.go +++ b/internal/platform/mmap_windows.go @@ -41,10 +41,10 @@ func allocateMemory(size uintptr, protect uintptr) (uintptr, error) { // freeMemory releases the memory region via the "VirtualFree" function. // See https://docs.microsoft.com/en-us/windows/win32/api/memoryapi/nf-memoryapi-virtualfree func freeMemory(code []byte) error { - address := uintptr(unsafe.Pointer(&code[0])) + address := unsafe.Pointer(&code[0]) size := uintptr(0) // size must be 0 because we're using MEM_RELEASE. freetype := windows_MEM_RELEASE - if r, _, err := procVirtualFree.Call(address, size, freetype); r == 0 { + if r, _, err := procVirtualFree.Call(uintptr(address), size, freetype); r == 0 { return fmt.Errorf("compiler: VirtualFree error: %w", ensureErr(err)) } return nil diff --git a/internal/platform/select_windows.go b/internal/platform/select_windows.go index 55f9751d..cab24e5c 100644 --- a/internal/platform/select_windows.go +++ b/internal/platform/select_windows.go @@ -108,14 +108,14 @@ func pollNamedPipe(ctx context.Context, pipeHandle syscall.Handle, duration *tim // see https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-peeknamedpipe func peekNamedPipe(handle syscall.Handle) (bool, error) { var totalBytesAvail uint32 - totalBytesPtr := uintptr(unsafe.Pointer(&totalBytesAvail)) + totalBytesPtr := unsafe.Pointer(&totalBytesAvail) _, _, err := procPeekNamedPipe.Call( - uintptr(handle), // [in] HANDLE hNamedPipe, - 0, // [out, optional] LPVOID lpBuffer, - 0, // [in] DWORD nBufferSize, - 0, // [out, optional] LPDWORD lpBytesRead - totalBytesPtr, // [out, optional] LPDWORD lpTotalBytesAvail, - 0) // [out, optional] LPDWORD lpBytesLeftThisMessage + uintptr(handle), // [in] HANDLE hNamedPipe, + 0, // [out, optional] LPVOID lpBuffer, + 0, // [in] DWORD nBufferSize, + 0, // [out, optional] LPDWORD lpBytesRead + uintptr(totalBytesPtr), // [out, optional] LPDWORD lpTotalBytesAvail, + 0) // [out, optional] LPDWORD lpBytesLeftThisMessage if err == syscall.Errno(0) { return totalBytesAvail > 0, nil } diff --git a/internal/platform/time_cgo.go b/internal/platform/time_cgo.go index 2f6a2899..ff01d90c 100644 --- a/internal/platform/time_cgo.go +++ b/internal/platform/time_cgo.go @@ -7,6 +7,5 @@ import _ "unsafe" // for go:linkname // nanotime uses runtime.nanotime as it is available on all platforms and // benchmarks faster than using time.Since. // -//go:noescape //go:linkname nanotime runtime.nanotime func nanotime() int64