summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/devpts
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fsimpl/devpts')
-rw-r--r--pkg/sentry/fsimpl/devpts/BUILD44
-rw-r--r--pkg/sentry/fsimpl/devpts/devpts_state_autogen.go161
-rw-r--r--pkg/sentry/fsimpl/devpts/devpts_test.go56
3 files changed, 161 insertions, 100 deletions
diff --git a/pkg/sentry/fsimpl/devpts/BUILD b/pkg/sentry/fsimpl/devpts/BUILD
deleted file mode 100644
index 93512c9b6..000000000
--- a/pkg/sentry/fsimpl/devpts/BUILD
+++ /dev/null
@@ -1,44 +0,0 @@
-load("//tools:defs.bzl", "go_library", "go_test")
-
-licenses(["notice"])
-
-go_library(
- name = "devpts",
- srcs = [
- "devpts.go",
- "line_discipline.go",
- "master.go",
- "queue.go",
- "slave.go",
- "terminal.go",
- ],
- visibility = ["//pkg/sentry:internal"],
- deps = [
- "//pkg/abi/linux",
- "//pkg/context",
- "//pkg/safemem",
- "//pkg/sentry/arch",
- "//pkg/sentry/fs/lock",
- "//pkg/sentry/fsimpl/kernfs",
- "//pkg/sentry/kernel",
- "//pkg/sentry/kernel/auth",
- "//pkg/sentry/unimpl",
- "//pkg/sentry/vfs",
- "//pkg/sync",
- "//pkg/syserror",
- "//pkg/usermem",
- "//pkg/waiter",
- ],
-)
-
-go_test(
- name = "devpts_test",
- size = "small",
- srcs = ["devpts_test.go"],
- library = ":devpts",
- deps = [
- "//pkg/abi/linux",
- "//pkg/sentry/contexttest",
- "//pkg/usermem",
- ],
-)
diff --git a/pkg/sentry/fsimpl/devpts/devpts_state_autogen.go b/pkg/sentry/fsimpl/devpts/devpts_state_autogen.go
new file mode 100644
index 000000000..5942f7bac
--- /dev/null
+++ b/pkg/sentry/fsimpl/devpts/devpts_state_autogen.go
@@ -0,0 +1,161 @@
+// automatically generated by stateify.
+
+package devpts
+
+import (
+ "gvisor.dev/gvisor/pkg/state"
+)
+
+func (x *lineDiscipline) StateTypeName() string {
+ return "pkg/sentry/fsimpl/devpts.lineDiscipline"
+}
+
+func (x *lineDiscipline) StateFields() []string {
+ return []string{
+ "size",
+ "inQueue",
+ "outQueue",
+ "termios",
+ "column",
+ }
+}
+
+func (x *lineDiscipline) beforeSave() {}
+
+func (x *lineDiscipline) StateSave(m state.Sink) {
+ x.beforeSave()
+ if !state.IsZeroValue(&x.masterWaiter) {
+ state.Failf("masterWaiter is %#v, expected zero", &x.masterWaiter)
+ }
+ if !state.IsZeroValue(&x.slaveWaiter) {
+ state.Failf("slaveWaiter is %#v, expected zero", &x.slaveWaiter)
+ }
+ m.Save(0, &x.size)
+ m.Save(1, &x.inQueue)
+ m.Save(2, &x.outQueue)
+ m.Save(3, &x.termios)
+ m.Save(4, &x.column)
+}
+
+func (x *lineDiscipline) afterLoad() {}
+
+func (x *lineDiscipline) StateLoad(m state.Source) {
+ m.Load(0, &x.size)
+ m.Load(1, &x.inQueue)
+ m.Load(2, &x.outQueue)
+ m.Load(3, &x.termios)
+ m.Load(4, &x.column)
+}
+
+func (x *outputQueueTransformer) StateTypeName() string {
+ return "pkg/sentry/fsimpl/devpts.outputQueueTransformer"
+}
+
+func (x *outputQueueTransformer) StateFields() []string {
+ return []string{}
+}
+
+func (x *outputQueueTransformer) beforeSave() {}
+
+func (x *outputQueueTransformer) StateSave(m state.Sink) {
+ x.beforeSave()
+}
+
+func (x *outputQueueTransformer) afterLoad() {}
+
+func (x *outputQueueTransformer) StateLoad(m state.Source) {
+}
+
+func (x *inputQueueTransformer) StateTypeName() string {
+ return "pkg/sentry/fsimpl/devpts.inputQueueTransformer"
+}
+
+func (x *inputQueueTransformer) StateFields() []string {
+ return []string{}
+}
+
+func (x *inputQueueTransformer) beforeSave() {}
+
+func (x *inputQueueTransformer) StateSave(m state.Sink) {
+ x.beforeSave()
+}
+
+func (x *inputQueueTransformer) afterLoad() {}
+
+func (x *inputQueueTransformer) StateLoad(m state.Source) {
+}
+
+func (x *queue) StateTypeName() string {
+ return "pkg/sentry/fsimpl/devpts.queue"
+}
+
+func (x *queue) StateFields() []string {
+ return []string{
+ "readBuf",
+ "waitBuf",
+ "waitBufLen",
+ "readable",
+ "transformer",
+ }
+}
+
+func (x *queue) beforeSave() {}
+
+func (x *queue) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.readBuf)
+ m.Save(1, &x.waitBuf)
+ m.Save(2, &x.waitBufLen)
+ m.Save(3, &x.readable)
+ m.Save(4, &x.transformer)
+}
+
+func (x *queue) afterLoad() {}
+
+func (x *queue) StateLoad(m state.Source) {
+ m.Load(0, &x.readBuf)
+ m.Load(1, &x.waitBuf)
+ m.Load(2, &x.waitBufLen)
+ m.Load(3, &x.readable)
+ m.Load(4, &x.transformer)
+}
+
+func (x *Terminal) StateTypeName() string {
+ return "pkg/sentry/fsimpl/devpts.Terminal"
+}
+
+func (x *Terminal) StateFields() []string {
+ return []string{
+ "n",
+ "ld",
+ "masterKTTY",
+ "slaveKTTY",
+ }
+}
+
+func (x *Terminal) beforeSave() {}
+
+func (x *Terminal) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.n)
+ m.Save(1, &x.ld)
+ m.Save(2, &x.masterKTTY)
+ m.Save(3, &x.slaveKTTY)
+}
+
+func (x *Terminal) afterLoad() {}
+
+func (x *Terminal) StateLoad(m state.Source) {
+ m.Load(0, &x.n)
+ m.Load(1, &x.ld)
+ m.Load(2, &x.masterKTTY)
+ m.Load(3, &x.slaveKTTY)
+}
+
+func init() {
+ state.Register((*lineDiscipline)(nil))
+ state.Register((*outputQueueTransformer)(nil))
+ state.Register((*inputQueueTransformer)(nil))
+ state.Register((*queue)(nil))
+ state.Register((*Terminal)(nil))
+}
diff --git a/pkg/sentry/fsimpl/devpts/devpts_test.go b/pkg/sentry/fsimpl/devpts/devpts_test.go
deleted file mode 100644
index b7c149047..000000000
--- a/pkg/sentry/fsimpl/devpts/devpts_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2018 The gVisor Authors.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package devpts
-
-import (
- "testing"
-
- "gvisor.dev/gvisor/pkg/abi/linux"
- "gvisor.dev/gvisor/pkg/sentry/contexttest"
- "gvisor.dev/gvisor/pkg/usermem"
-)
-
-func TestSimpleMasterToSlave(t *testing.T) {
- ld := newLineDiscipline(linux.DefaultSlaveTermios)
- ctx := contexttest.Context(t)
- inBytes := []byte("hello, tty\n")
- src := usermem.BytesIOSequence(inBytes)
- outBytes := make([]byte, 32)
- dst := usermem.BytesIOSequence(outBytes)
-
- // Write to the input queue.
- nw, err := ld.inputQueueWrite(ctx, src)
- if err != nil {
- t.Fatalf("error writing to input queue: %v", err)
- }
- if nw != int64(len(inBytes)) {
- t.Fatalf("wrote wrong length: got %d, want %d", nw, len(inBytes))
- }
-
- // Read from the input queue.
- nr, err := ld.inputQueueRead(ctx, dst)
- if err != nil {
- t.Fatalf("error reading from input queue: %v", err)
- }
- if nr != int64(len(inBytes)) {
- t.Fatalf("read wrong length: got %d, want %d", nr, len(inBytes))
- }
-
- outStr := string(outBytes[:nr])
- inStr := string(inBytes)
- if outStr != inStr {
- t.Fatalf("written and read strings do not match: got %q, want %q", outStr, inStr)
- }
-}