summaryrefslogtreecommitdiffhomepage
path: root/pkg/usermem
diff options
context:
space:
mode:
authorZach Koopmans <zkoopmans@google.com>2021-07-12 15:24:04 -0700
committergVisor bot <gvisor-bot@google.com>2021-07-12 15:26:20 -0700
commite3fdd1593217894328d5a917bbc356d0a7d145f0 (patch)
tree1913cf79abb68fda218f249ffa32a7bf309330ac /pkg/usermem
parentebe99977a47d93ee769121f9463650cfb924e243 (diff)
[syserror] Update syserror to linuxerr for more errors.
Update the following from syserror to the linuxerr equivalent: EEXIST EFAULT ENOTDIR ENOTTY EOPNOTSUPP ERANGE ESRCH PiperOrigin-RevId: 384329869
Diffstat (limited to 'pkg/usermem')
-rw-r--r--pkg/usermem/BUILD2
-rw-r--r--pkg/usermem/bytes_io.go5
-rw-r--r--pkg/usermem/usermem.go7
-rw-r--r--pkg/usermem/usermem_test.go13
4 files changed, 11 insertions, 16 deletions
diff --git a/pkg/usermem/BUILD b/pkg/usermem/BUILD
index 54674ee88..9c37a9626 100644
--- a/pkg/usermem/BUILD
+++ b/pkg/usermem/BUILD
@@ -18,7 +18,6 @@ go_library(
"//pkg/gohacks",
"//pkg/hostarch",
"//pkg/safemem",
- "//pkg/syserror",
],
)
@@ -34,6 +33,5 @@ go_test(
"//pkg/errors/linuxerr",
"//pkg/hostarch",
"//pkg/safemem",
- "//pkg/syserror",
],
)
diff --git a/pkg/usermem/bytes_io.go b/pkg/usermem/bytes_io.go
index 4c97b9136..777ac59a6 100644
--- a/pkg/usermem/bytes_io.go
+++ b/pkg/usermem/bytes_io.go
@@ -19,7 +19,6 @@ import (
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/safemem"
- "gvisor.dev/gvisor/pkg/syserror"
)
const maxInt = int(^uint(0) >> 1)
@@ -94,11 +93,11 @@ func (b *BytesIO) rangeCheck(addr hostarch.Addr, length int) (int, error) {
}
max := hostarch.Addr(len(b.Bytes))
if addr >= max {
- return 0, syserror.EFAULT
+ return 0, linuxerr.EFAULT
}
end, ok := addr.AddLength(uint64(length))
if !ok || end > max {
- return int(max - addr), syserror.EFAULT
+ return int(max - addr), linuxerr.EFAULT
}
return length, nil
}
diff --git a/pkg/usermem/usermem.go b/pkg/usermem/usermem.go
index ca852558e..cde1038ed 100644
--- a/pkg/usermem/usermem.go
+++ b/pkg/usermem/usermem.go
@@ -26,7 +26,6 @@ import (
"gvisor.dev/gvisor/pkg/gohacks"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/safemem"
- "gvisor.dev/gvisor/pkg/syserror"
)
// IO provides access to the contents of a virtual memory space.
@@ -163,7 +162,7 @@ func (rw *IOReadWriter) Read(dst []byte) (int, error) {
// Disallow wraparound.
rw.Addr = ^hostarch.Addr(0)
if err != nil {
- err = syserror.EFAULT
+ err = linuxerr.EFAULT
}
}
return n, err
@@ -179,7 +178,7 @@ func (rw *IOReadWriter) Write(src []byte) (int, error) {
// Disallow wraparound.
rw.Addr = ^hostarch.Addr(0)
if err != nil {
- err = syserror.EFAULT
+ err = linuxerr.EFAULT
}
}
return n, err
@@ -214,7 +213,7 @@ func CopyStringIn(ctx context.Context, uio IO, addr hostarch.Addr, maxlen int, o
}
end, ok := addr.AddLength(uint64(readlen))
if !ok {
- return gohacks.StringFromImmutableBytes(buf[:done]), syserror.EFAULT
+ return gohacks.StringFromImmutableBytes(buf[:done]), linuxerr.EFAULT
}
// Shorten the read to avoid crossing page boundaries, since faulting
// in a page unnecessarily is expensive. This also ensures that partial
diff --git a/pkg/usermem/usermem_test.go b/pkg/usermem/usermem_test.go
index 597770ca7..a5e2fe69e 100644
--- a/pkg/usermem/usermem_test.go
+++ b/pkg/usermem/usermem_test.go
@@ -25,7 +25,6 @@ import (
"gvisor.dev/gvisor/pkg/errors/linuxerr"
"gvisor.dev/gvisor/pkg/hostarch"
"gvisor.dev/gvisor/pkg/safemem"
- "gvisor.dev/gvisor/pkg/syserror"
)
// newContext returns a context.Context that we can use in these tests (we
@@ -52,7 +51,7 @@ func TestBytesIOCopyOutSuccess(t *testing.T) {
func TestBytesIOCopyOutFailure(t *testing.T) {
b := newBytesIOString("ABC")
n, err := b.CopyOut(newContext(), 1, []byte("foo"), IOOpts{})
- if wantN, wantErr := 2, syserror.EFAULT; n != wantN || err != wantErr {
+ if wantN, wantErr := 2, linuxerr.EFAULT; n != wantN || err != wantErr {
t.Errorf("CopyOut: got (%v, %v), wanted (%v, %v)", n, err, wantN, wantErr)
}
if got, want := b.Bytes, []byte("Afo"); !bytes.Equal(got, want) {
@@ -76,7 +75,7 @@ func TestBytesIOCopyInFailure(t *testing.T) {
b := newBytesIOString("Afo")
var dst [3]byte
n, err := b.CopyIn(newContext(), 1, dst[:], IOOpts{})
- if wantN, wantErr := 2, syserror.EFAULT; n != wantN || err != wantErr {
+ if wantN, wantErr := 2, linuxerr.EFAULT; n != wantN || err != wantErr {
t.Errorf("CopyIn: got (%v, %v), wanted (%v, %v)", n, err, wantN, wantErr)
}
if got, want := dst[:], []byte("fo\x00"); !bytes.Equal(got, want) {
@@ -98,7 +97,7 @@ func TestBytesIOZeroOutSuccess(t *testing.T) {
func TestBytesIOZeroOutFailure(t *testing.T) {
b := newBytesIOString("ABC")
n, err := b.ZeroOut(newContext(), 1, 3, IOOpts{})
- if wantN, wantErr := int64(2), syserror.EFAULT; n != wantN || err != wantErr {
+ if wantN, wantErr := int64(2), linuxerr.EFAULT; n != wantN || err != wantErr {
t.Errorf("ZeroOut: got (%v, %v), wanted (%v, %v)", n, err, wantN, wantErr)
}
if got, want := b.Bytes, []byte("A\x00\x00"); !bytes.Equal(got, want) {
@@ -126,7 +125,7 @@ func TestBytesIOCopyOutFromFailure(t *testing.T) {
{Start: 1, End: 4},
{Start: 4, End: 7},
}), safemem.FromIOReader{bytes.NewBufferString("foobar")}, IOOpts{})
- if wantN, wantErr := int64(4), syserror.EFAULT; n != wantN || err != wantErr {
+ if wantN, wantErr := int64(4), linuxerr.EFAULT; n != wantN || err != wantErr {
t.Errorf("CopyOutFrom: got (%v, %v), wanted (%v, %v)", n, err, wantN, wantErr)
}
if got, want := b.Bytes, []byte("Afoob"); !bytes.Equal(got, want) {
@@ -156,7 +155,7 @@ func TestBytesIOCopyInToFailure(t *testing.T) {
{Start: 1, End: 4},
{Start: 4, End: 7},
}), safemem.FromIOWriter{&dst}, IOOpts{})
- if wantN, wantErr := int64(4), syserror.EFAULT; n != wantN || err != wantErr {
+ if wantN, wantErr := int64(4), linuxerr.EFAULT; n != wantN || err != wantErr {
t.Errorf("CopyOutFrom: got (%v, %v), wanted (%v, %v)", n, err, wantN, wantErr)
}
if got, want := dst.Bytes(), []byte("foob"); !bytes.Equal(got, want) {
@@ -207,7 +206,7 @@ func TestCopyStringInVeryLong(t *testing.T) {
func TestCopyStringInNoTerminatingZeroByte(t *testing.T) {
want := strings.Repeat("A", copyStringIncrement-1)
got, err := CopyStringIn(newContext(), newBytesIOString(want), 0, 2*copyStringIncrement, IOOpts{})
- if wantErr := syserror.EFAULT; got != want || err != wantErr {
+ if wantErr := linuxerr.EFAULT; got != want || err != wantErr {
t.Errorf("CopyStringIn: got (%q, %v), wanted (%q, %v)", got, err, want, wantErr)
}
}