diff options
Diffstat (limited to 'pkg/sentry/fs/tty')
-rw-r--r-- | pkg/sentry/fs/tty/BUILD | 47 | ||||
-rw-r--r-- | pkg/sentry/fs/tty/tty_state_autogen.go | 381 | ||||
-rw-r--r-- | pkg/sentry/fs/tty/tty_test.go | 56 |
3 files changed, 381 insertions, 103 deletions
diff --git a/pkg/sentry/fs/tty/BUILD b/pkg/sentry/fs/tty/BUILD deleted file mode 100644 index 5cb0e0417..000000000 --- a/pkg/sentry/fs/tty/BUILD +++ /dev/null @@ -1,47 +0,0 @@ -load("//tools:defs.bzl", "go_library", "go_test") - -package(licenses = ["notice"]) - -go_library( - name = "tty", - srcs = [ - "dir.go", - "fs.go", - "line_discipline.go", - "master.go", - "queue.go", - "slave.go", - "terminal.go", - ], - visibility = ["//pkg/sentry:internal"], - deps = [ - "//pkg/abi/linux", - "//pkg/context", - "//pkg/refs", - "//pkg/safemem", - "//pkg/sentry/arch", - "//pkg/sentry/device", - "//pkg/sentry/fs", - "//pkg/sentry/fs/fsutil", - "//pkg/sentry/kernel", - "//pkg/sentry/kernel/auth", - "//pkg/sentry/socket/unix/transport", - "//pkg/sentry/unimpl", - "//pkg/sync", - "//pkg/syserror", - "//pkg/usermem", - "//pkg/waiter", - ], -) - -go_test( - name = "tty_test", - size = "small", - srcs = ["tty_test.go"], - library = ":tty", - deps = [ - "//pkg/abi/linux", - "//pkg/sentry/contexttest", - "//pkg/usermem", - ], -) diff --git a/pkg/sentry/fs/tty/tty_state_autogen.go b/pkg/sentry/fs/tty/tty_state_autogen.go new file mode 100644 index 000000000..e82ca45a3 --- /dev/null +++ b/pkg/sentry/fs/tty/tty_state_autogen.go @@ -0,0 +1,381 @@ +// automatically generated by stateify. + +package tty + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (x *dirInodeOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.dirInodeOperations" +} + +func (x *dirInodeOperations) StateFields() []string { + return []string{ + "InodeSimpleAttributes", + "msrc", + "master", + "slaves", + "dentryMap", + "next", + } +} + +func (x *dirInodeOperations) beforeSave() {} + +func (x *dirInodeOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.InodeSimpleAttributes) + m.Save(1, &x.msrc) + m.Save(2, &x.master) + m.Save(3, &x.slaves) + m.Save(4, &x.dentryMap) + m.Save(5, &x.next) +} + +func (x *dirInodeOperations) afterLoad() {} + +func (x *dirInodeOperations) StateLoad(m state.Source) { + m.Load(0, &x.InodeSimpleAttributes) + m.Load(1, &x.msrc) + m.Load(2, &x.master) + m.Load(3, &x.slaves) + m.Load(4, &x.dentryMap) + m.Load(5, &x.next) +} + +func (x *dirFileOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.dirFileOperations" +} + +func (x *dirFileOperations) StateFields() []string { + return []string{ + "di", + "dirCursor", + } +} + +func (x *dirFileOperations) beforeSave() {} + +func (x *dirFileOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.di) + m.Save(1, &x.dirCursor) +} + +func (x *dirFileOperations) afterLoad() {} + +func (x *dirFileOperations) StateLoad(m state.Source) { + m.Load(0, &x.di) + m.Load(1, &x.dirCursor) +} + +func (x *filesystem) StateTypeName() string { + return "pkg/sentry/fs/tty.filesystem" +} + +func (x *filesystem) StateFields() []string { + return []string{} +} + +func (x *filesystem) beforeSave() {} + +func (x *filesystem) StateSave(m state.Sink) { + x.beforeSave() +} + +func (x *filesystem) afterLoad() {} + +func (x *filesystem) StateLoad(m state.Source) { +} + +func (x *superOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.superOperations" +} + +func (x *superOperations) StateFields() []string { + return []string{} +} + +func (x *superOperations) beforeSave() {} + +func (x *superOperations) StateSave(m state.Sink) { + x.beforeSave() +} + +func (x *superOperations) afterLoad() {} + +func (x *superOperations) StateLoad(m state.Source) { +} + +func (x *lineDiscipline) StateTypeName() string { + return "pkg/sentry/fs/tty.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/fs/tty.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/fs/tty.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 *masterInodeOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.masterInodeOperations" +} + +func (x *masterInodeOperations) StateFields() []string { + return []string{ + "SimpleFileInode", + "d", + } +} + +func (x *masterInodeOperations) beforeSave() {} + +func (x *masterInodeOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.SimpleFileInode) + m.Save(1, &x.d) +} + +func (x *masterInodeOperations) afterLoad() {} + +func (x *masterInodeOperations) StateLoad(m state.Source) { + m.Load(0, &x.SimpleFileInode) + m.Load(1, &x.d) +} + +func (x *masterFileOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.masterFileOperations" +} + +func (x *masterFileOperations) StateFields() []string { + return []string{ + "d", + "t", + } +} + +func (x *masterFileOperations) beforeSave() {} + +func (x *masterFileOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.d) + m.Save(1, &x.t) +} + +func (x *masterFileOperations) afterLoad() {} + +func (x *masterFileOperations) StateLoad(m state.Source) { + m.Load(0, &x.d) + m.Load(1, &x.t) +} + +func (x *queue) StateTypeName() string { + return "pkg/sentry/fs/tty.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 *slaveInodeOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.slaveInodeOperations" +} + +func (x *slaveInodeOperations) StateFields() []string { + return []string{ + "SimpleFileInode", + "d", + "t", + } +} + +func (x *slaveInodeOperations) beforeSave() {} + +func (x *slaveInodeOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.SimpleFileInode) + m.Save(1, &x.d) + m.Save(2, &x.t) +} + +func (x *slaveInodeOperations) afterLoad() {} + +func (x *slaveInodeOperations) StateLoad(m state.Source) { + m.Load(0, &x.SimpleFileInode) + m.Load(1, &x.d) + m.Load(2, &x.t) +} + +func (x *slaveFileOperations) StateTypeName() string { + return "pkg/sentry/fs/tty.slaveFileOperations" +} + +func (x *slaveFileOperations) StateFields() []string { + return []string{ + "si", + } +} + +func (x *slaveFileOperations) beforeSave() {} + +func (x *slaveFileOperations) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.si) +} + +func (x *slaveFileOperations) afterLoad() {} + +func (x *slaveFileOperations) StateLoad(m state.Source) { + m.Load(0, &x.si) +} + +func (x *Terminal) StateTypeName() string { + return "pkg/sentry/fs/tty.Terminal" +} + +func (x *Terminal) StateFields() []string { + return []string{ + "AtomicRefCount", + "n", + "d", + "ld", + "masterKTTY", + "slaveKTTY", + } +} + +func (x *Terminal) beforeSave() {} + +func (x *Terminal) StateSave(m state.Sink) { + x.beforeSave() + m.Save(0, &x.AtomicRefCount) + m.Save(1, &x.n) + m.Save(2, &x.d) + m.Save(3, &x.ld) + m.Save(4, &x.masterKTTY) + m.Save(5, &x.slaveKTTY) +} + +func (x *Terminal) afterLoad() {} + +func (x *Terminal) StateLoad(m state.Source) { + m.Load(0, &x.AtomicRefCount) + m.Load(1, &x.n) + m.Load(2, &x.d) + m.Load(3, &x.ld) + m.Load(4, &x.masterKTTY) + m.Load(5, &x.slaveKTTY) +} + +func init() { + state.Register((*dirInodeOperations)(nil)) + state.Register((*dirFileOperations)(nil)) + state.Register((*filesystem)(nil)) + state.Register((*superOperations)(nil)) + state.Register((*lineDiscipline)(nil)) + state.Register((*outputQueueTransformer)(nil)) + state.Register((*inputQueueTransformer)(nil)) + state.Register((*masterInodeOperations)(nil)) + state.Register((*masterFileOperations)(nil)) + state.Register((*queue)(nil)) + state.Register((*slaveInodeOperations)(nil)) + state.Register((*slaveFileOperations)(nil)) + state.Register((*Terminal)(nil)) +} diff --git a/pkg/sentry/fs/tty/tty_test.go b/pkg/sentry/fs/tty/tty_test.go deleted file mode 100644 index 2cbc05678..000000000 --- a/pkg/sentry/fs/tty/tty_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 tty - -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) - } -} |