unix: use unsafe.Slice instead of unsafeheader package

Go 1.18 is the minimum supported Go version and unsafe.Slice was
introduced in Go 1.17.

Change-Id: Ie5f1fad01f219e7b7a190de2c49676f366ad3bc7
Reviewed-on: https://go-review.googlesource.com/c/sys/+/428515
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
diff --git a/unix/syscall.go b/unix/syscall.go
index 649fa87..9916e5e 100644
--- a/unix/syscall.go
+++ b/unix/syscall.go
@@ -29,8 +29,6 @@
 	"bytes"
 	"strings"
 	"unsafe"
-
-	"golang.org/x/sys/internal/unsafeheader"
 )
 
 // ByteSliceFromString returns a NUL-terminated slice of bytes
@@ -82,12 +80,7 @@
 		ptr = unsafe.Pointer(uintptr(ptr) + 1)
 	}
 
-	var s []byte
-	h := (*unsafeheader.Slice)(unsafe.Pointer(&s))
-	h.Data = unsafe.Pointer(p)
-	h.Len = n
-	h.Cap = n
-
+	s := unsafe.Slice((*byte)(unsafe.Pointer(p)), n)
 	return string(s)
 }
 
diff --git a/unix/syscall_darwin.1_13.go b/unix/syscall_darwin.1_13.go
index 1596426..1259f6d 100644
--- a/unix/syscall_darwin.1_13.go
+++ b/unix/syscall_darwin.1_13.go
@@ -7,11 +7,7 @@
 
 package unix
 
-import (
-	"unsafe"
-
-	"golang.org/x/sys/internal/unsafeheader"
-)
+import "unsafe"
 
 //sys	closedir(dir uintptr) (err error)
 //sys	readdir_r(dir uintptr, entry *Dirent, result **Dirent) (res Errno)
@@ -86,11 +82,7 @@
 		}
 
 		// Copy entry into return buffer.
-		var s []byte
-		hdr := (*unsafeheader.Slice)(unsafe.Pointer(&s))
-		hdr.Data = unsafe.Pointer(&entry)
-		hdr.Cap = reclen
-		hdr.Len = reclen
+		s := unsafe.Slice((*byte)(unsafe.Pointer(&entry)), reclen)
 		copy(buf, s)
 
 		buf = buf[reclen:]
diff --git a/unix/syscall_unix.go b/unix/syscall_unix.go
index 1ff5060..9f75356 100644
--- a/unix/syscall_unix.go
+++ b/unix/syscall_unix.go
@@ -13,8 +13,6 @@
 	"sync"
 	"syscall"
 	"unsafe"
-
-	"golang.org/x/sys/internal/unsafeheader"
 )
 
 var (
@@ -117,11 +115,7 @@
 	}
 
 	// Use unsafe to convert addr into a []byte.
-	var b []byte
-	hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
-	hdr.Data = unsafe.Pointer(addr)
-	hdr.Cap = length
-	hdr.Len = length
+	b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), length)
 
 	// Register mapping in m and return it.
 	p := &b[cap(b)-1]
diff --git a/unix/sysvshm_unix.go b/unix/sysvshm_unix.go
index 0bb4c8d..5bb41d1 100644
--- a/unix/sysvshm_unix.go
+++ b/unix/sysvshm_unix.go
@@ -7,11 +7,7 @@
 
 package unix
 
-import (
-	"unsafe"
-
-	"golang.org/x/sys/internal/unsafeheader"
-)
+import "unsafe"
 
 // SysvShmAttach attaches the Sysv shared memory segment associated with the
 // shared memory identifier id.
@@ -34,12 +30,7 @@
 	}
 
 	// Use unsafe to convert addr into a []byte.
-	// TODO: convert to unsafe.Slice once we can assume Go 1.17
-	var b []byte
-	hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
-	hdr.Data = unsafe.Pointer(addr)
-	hdr.Cap = int(info.Segsz)
-	hdr.Len = int(info.Segsz)
+	b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.Segsz))
 	return b, nil
 }