diff options
author | Ayush Ranjan <ayushranjan@google.com> | 2021-03-03 10:23:55 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 10:25:58 -0800 |
commit | a9441aea2780da8c93da1c73da860219f98438de (patch) | |
tree | 8b12915756f5bfb926218214cd7bc0b3281605fd /pkg/safecopy/safecopy_test.go | |
parent | b8a5420f49a2afd622ec08b5019e1bf537f7da82 (diff) |
[op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.
Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
returns it and not unix.Stat_t.
Updates #214
PiperOrigin-RevId: 360701387
Diffstat (limited to 'pkg/safecopy/safecopy_test.go')
-rw-r--r-- | pkg/safecopy/safecopy_test.go | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/pkg/safecopy/safecopy_test.go b/pkg/safecopy/safecopy_test.go index 7f7f69d61..d2ce8ff86 100644 --- a/pkg/safecopy/safecopy_test.go +++ b/pkg/safecopy/safecopy_test.go @@ -21,9 +21,10 @@ import ( "math/rand" "os" "runtime/debug" - "syscall" "testing" "unsafe" + + "golang.org/x/sys/unix" ) // Size of a page in bytes. Cloned from usermem.PageSize to avoid a circular @@ -224,12 +225,12 @@ func TestCompareAndSwapUint32AlignmentError(t *testing.T) { // withSegvErrorTestMapping calls fn with a two-page mapping. The first page // contains random data, and the second page generates SIGSEGV when accessed. func withSegvErrorTestMapping(t *testing.T, fn func(m []byte)) { - mapping, err := syscall.Mmap(-1, 0, 2*pageSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_ANONYMOUS|syscall.MAP_PRIVATE) + mapping, err := unix.Mmap(-1, 0, 2*pageSize, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_ANONYMOUS|unix.MAP_PRIVATE) if err != nil { t.Fatalf("Mmap failed: %v", err) } - defer syscall.Munmap(mapping) - if err := syscall.Mprotect(mapping[pageSize:], syscall.PROT_NONE); err != nil { + defer unix.Munmap(mapping) + if err := unix.Mprotect(mapping[pageSize:], unix.PROT_NONE); err != nil { t.Fatalf("Mprotect failed: %v", err) } initRandom(mapping[:pageSize]) @@ -248,11 +249,11 @@ func withBusErrorTestMapping(t *testing.T, fn func(m []byte)) { if err := f.Truncate(pageSize); err != nil { t.Fatalf("Truncate failed: %v", err) } - mapping, err := syscall.Mmap(int(f.Fd()), 0, 2*pageSize, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) + mapping, err := unix.Mmap(int(f.Fd()), 0, 2*pageSize, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED) if err != nil { t.Fatalf("Mmap failed: %v", err) } - defer syscall.Munmap(mapping) + defer unix.Munmap(mapping) initRandom(mapping[:pageSize]) fn(mapping) @@ -583,12 +584,12 @@ func TestSegVOnMemmove(t *testing.T) { // Test that SIGSEGVs received by runtime.memmove when *not* doing // CopyIn or CopyOut work gets propagated to the runtime. const bufLen = pageSize - a, err := syscall.Mmap(-1, 0, bufLen, syscall.PROT_NONE, syscall.MAP_ANON|syscall.MAP_PRIVATE) + a, err := unix.Mmap(-1, 0, bufLen, unix.PROT_NONE, unix.MAP_ANON|unix.MAP_PRIVATE) if err != nil { t.Fatalf("Mmap failed: %v", err) } - defer syscall.Munmap(a) + defer unix.Munmap(a) b := randBuf(bufLen) if !testCopy(b, a) { @@ -611,12 +612,12 @@ func TestSigbusOnMemmove(t *testing.T) { os.Remove(f.Name()) defer f.Close() - a, err := syscall.Mmap(int(f.Fd()), 0, bufLen, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED) + a, err := unix.Mmap(int(f.Fd()), 0, bufLen, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_SHARED) if err != nil { t.Fatalf("Mmap failed: %v", err) } - defer syscall.Munmap(a) + defer unix.Munmap(a) b := randBuf(bufLen) if !testCopy(b, a) { |