summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/fsimpl/proc
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/fsimpl/proc')
-rw-r--r--pkg/sentry/fsimpl/proc/BUILD67
-rw-r--r--pkg/sentry/fsimpl/proc/proc_state_autogen.go1245
-rw-r--r--pkg/sentry/fsimpl/proc/tasks_sys_test.go78
-rw-r--r--pkg/sentry/fsimpl/proc/tasks_test.go505
4 files changed, 1245 insertions, 650 deletions
diff --git a/pkg/sentry/fsimpl/proc/BUILD b/pkg/sentry/fsimpl/proc/BUILD
deleted file mode 100644
index 6014138ff..000000000
--- a/pkg/sentry/fsimpl/proc/BUILD
+++ /dev/null
@@ -1,67 +0,0 @@
-load("//tools:defs.bzl", "go_library", "go_test")
-
-licenses(["notice"])
-
-go_library(
- name = "proc",
- srcs = [
- "filesystem.go",
- "subtasks.go",
- "task.go",
- "task_fds.go",
- "task_files.go",
- "task_net.go",
- "tasks.go",
- "tasks_files.go",
- "tasks_sys.go",
- ],
- visibility = ["//pkg/sentry:internal"],
- deps = [
- "//pkg/abi/linux",
- "//pkg/context",
- "//pkg/log",
- "//pkg/refs",
- "//pkg/safemem",
- "//pkg/sentry/fs/lock",
- "//pkg/sentry/fsbridge",
- "//pkg/sentry/fsimpl/kernfs",
- "//pkg/sentry/inet",
- "//pkg/sentry/kernel",
- "//pkg/sentry/kernel/auth",
- "//pkg/sentry/kernel/time",
- "//pkg/sentry/limits",
- "//pkg/sentry/mm",
- "//pkg/sentry/socket",
- "//pkg/sentry/socket/unix",
- "//pkg/sentry/socket/unix/transport",
- "//pkg/sentry/usage",
- "//pkg/sentry/vfs",
- "//pkg/syserror",
- "//pkg/tcpip/header",
- "//pkg/usermem",
- ],
-)
-
-go_test(
- name = "proc_test",
- size = "small",
- srcs = [
- "tasks_sys_test.go",
- "tasks_test.go",
- ],
- library = ":proc",
- deps = [
- "//pkg/abi/linux",
- "//pkg/context",
- "//pkg/fspath",
- "//pkg/sentry/contexttest",
- "//pkg/sentry/fsimpl/testutil",
- "//pkg/sentry/fsimpl/tmpfs",
- "//pkg/sentry/inet",
- "//pkg/sentry/kernel",
- "//pkg/sentry/kernel/auth",
- "//pkg/sentry/vfs",
- "//pkg/syserror",
- "//pkg/usermem",
- ],
-)
diff --git a/pkg/sentry/fsimpl/proc/proc_state_autogen.go b/pkg/sentry/fsimpl/proc/proc_state_autogen.go
new file mode 100644
index 000000000..eca33249c
--- /dev/null
+++ b/pkg/sentry/fsimpl/proc/proc_state_autogen.go
@@ -0,0 +1,1245 @@
+// automatically generated by stateify.
+
+package proc
+
+import (
+ "gvisor.dev/gvisor/pkg/state"
+)
+
+func (x *FilesystemType) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.FilesystemType"
+}
+
+func (x *FilesystemType) StateFields() []string {
+ return []string{}
+}
+
+func (x *FilesystemType) beforeSave() {}
+
+func (x *FilesystemType) StateSave(m state.Sink) {
+ x.beforeSave()
+}
+
+func (x *FilesystemType) afterLoad() {}
+
+func (x *FilesystemType) StateLoad(m state.Source) {
+}
+
+func (x *subtasksInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.subtasksInode"
+}
+
+func (x *subtasksInode) StateFields() []string {
+ return []string{
+ "InodeNotSymlink",
+ "InodeDirectoryNoNewChildren",
+ "InodeAttrs",
+ "OrderedChildren",
+ "AlwaysValid",
+ "locks",
+ "fs",
+ "task",
+ "pidns",
+ "cgroupControllers",
+ }
+}
+
+func (x *subtasksInode) beforeSave() {}
+
+func (x *subtasksInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNotSymlink)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeAttrs)
+ m.Save(3, &x.OrderedChildren)
+ m.Save(4, &x.AlwaysValid)
+ m.Save(5, &x.locks)
+ m.Save(6, &x.fs)
+ m.Save(7, &x.task)
+ m.Save(8, &x.pidns)
+ m.Save(9, &x.cgroupControllers)
+}
+
+func (x *subtasksInode) afterLoad() {}
+
+func (x *subtasksInode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNotSymlink)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeAttrs)
+ m.Load(3, &x.OrderedChildren)
+ m.Load(4, &x.AlwaysValid)
+ m.Load(5, &x.locks)
+ m.Load(6, &x.fs)
+ m.Load(7, &x.task)
+ m.Load(8, &x.pidns)
+ m.Load(9, &x.cgroupControllers)
+}
+
+func (x *taskInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.taskInode"
+}
+
+func (x *taskInode) StateFields() []string {
+ return []string{
+ "InodeNotSymlink",
+ "InodeDirectoryNoNewChildren",
+ "InodeNoDynamicLookup",
+ "InodeAttrs",
+ "OrderedChildren",
+ "locks",
+ "task",
+ }
+}
+
+func (x *taskInode) beforeSave() {}
+
+func (x *taskInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNotSymlink)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeNoDynamicLookup)
+ m.Save(3, &x.InodeAttrs)
+ m.Save(4, &x.OrderedChildren)
+ m.Save(5, &x.locks)
+ m.Save(6, &x.task)
+}
+
+func (x *taskInode) afterLoad() {}
+
+func (x *taskInode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNotSymlink)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeNoDynamicLookup)
+ m.Load(3, &x.InodeAttrs)
+ m.Load(4, &x.OrderedChildren)
+ m.Load(5, &x.locks)
+ m.Load(6, &x.task)
+}
+
+func (x *fdDirInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.fdDirInode"
+}
+
+func (x *fdDirInode) StateFields() []string {
+ return []string{
+ "InodeNotSymlink",
+ "InodeDirectoryNoNewChildren",
+ "InodeAttrs",
+ "OrderedChildren",
+ "AlwaysValid",
+ "fdDir",
+ }
+}
+
+func (x *fdDirInode) beforeSave() {}
+
+func (x *fdDirInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNotSymlink)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeAttrs)
+ m.Save(3, &x.OrderedChildren)
+ m.Save(4, &x.AlwaysValid)
+ m.Save(5, &x.fdDir)
+}
+
+func (x *fdDirInode) afterLoad() {}
+
+func (x *fdDirInode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNotSymlink)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeAttrs)
+ m.Load(3, &x.OrderedChildren)
+ m.Load(4, &x.AlwaysValid)
+ m.Load(5, &x.fdDir)
+}
+
+func (x *fdSymlink) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.fdSymlink"
+}
+
+func (x *fdSymlink) StateFields() []string {
+ return []string{
+ "InodeAttrs",
+ "InodeNoopRefCount",
+ "InodeSymlink",
+ "task",
+ "fd",
+ }
+}
+
+func (x *fdSymlink) beforeSave() {}
+
+func (x *fdSymlink) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeAttrs)
+ m.Save(1, &x.InodeNoopRefCount)
+ m.Save(2, &x.InodeSymlink)
+ m.Save(3, &x.task)
+ m.Save(4, &x.fd)
+}
+
+func (x *fdSymlink) afterLoad() {}
+
+func (x *fdSymlink) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeAttrs)
+ m.Load(1, &x.InodeNoopRefCount)
+ m.Load(2, &x.InodeSymlink)
+ m.Load(3, &x.task)
+ m.Load(4, &x.fd)
+}
+
+func (x *fdInfoDirInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.fdInfoDirInode"
+}
+
+func (x *fdInfoDirInode) StateFields() []string {
+ return []string{
+ "InodeNotSymlink",
+ "InodeDirectoryNoNewChildren",
+ "InodeAttrs",
+ "OrderedChildren",
+ "AlwaysValid",
+ "fdDir",
+ }
+}
+
+func (x *fdInfoDirInode) beforeSave() {}
+
+func (x *fdInfoDirInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNotSymlink)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeAttrs)
+ m.Save(3, &x.OrderedChildren)
+ m.Save(4, &x.AlwaysValid)
+ m.Save(5, &x.fdDir)
+}
+
+func (x *fdInfoDirInode) afterLoad() {}
+
+func (x *fdInfoDirInode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNotSymlink)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeAttrs)
+ m.Load(3, &x.OrderedChildren)
+ m.Load(4, &x.AlwaysValid)
+ m.Load(5, &x.fdDir)
+}
+
+func (x *fdInfoData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.fdInfoData"
+}
+
+func (x *fdInfoData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "AtomicRefCount",
+ "task",
+ "fd",
+ }
+}
+
+func (x *fdInfoData) beforeSave() {}
+
+func (x *fdInfoData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.AtomicRefCount)
+ m.Save(2, &x.task)
+ m.Save(3, &x.fd)
+}
+
+func (x *fdInfoData) afterLoad() {}
+
+func (x *fdInfoData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.AtomicRefCount)
+ m.Load(2, &x.task)
+ m.Load(3, &x.fd)
+}
+
+func (x *auxvData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.auxvData"
+}
+
+func (x *auxvData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *auxvData) beforeSave() {}
+
+func (x *auxvData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *auxvData) afterLoad() {}
+
+func (x *auxvData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *cmdlineData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.cmdlineData"
+}
+
+func (x *cmdlineData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ "arg",
+ }
+}
+
+func (x *cmdlineData) beforeSave() {}
+
+func (x *cmdlineData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+ m.Save(2, &x.arg)
+}
+
+func (x *cmdlineData) afterLoad() {}
+
+func (x *cmdlineData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+ m.Load(2, &x.arg)
+}
+
+func (x *commInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.commInode"
+}
+
+func (x *commInode) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *commInode) beforeSave() {}
+
+func (x *commInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *commInode) afterLoad() {}
+
+func (x *commInode) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *commData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.commData"
+}
+
+func (x *commData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *commData) beforeSave() {}
+
+func (x *commData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *commData) afterLoad() {}
+
+func (x *commData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *idMapData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.idMapData"
+}
+
+func (x *idMapData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ "gids",
+ }
+}
+
+func (x *idMapData) beforeSave() {}
+
+func (x *idMapData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+ m.Save(2, &x.gids)
+}
+
+func (x *idMapData) afterLoad() {}
+
+func (x *idMapData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+ m.Load(2, &x.gids)
+}
+
+func (x *mapsData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.mapsData"
+}
+
+func (x *mapsData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *mapsData) beforeSave() {}
+
+func (x *mapsData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *mapsData) afterLoad() {}
+
+func (x *mapsData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *smapsData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.smapsData"
+}
+
+func (x *smapsData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *smapsData) beforeSave() {}
+
+func (x *smapsData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *smapsData) afterLoad() {}
+
+func (x *smapsData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *taskStatData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.taskStatData"
+}
+
+func (x *taskStatData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ "tgstats",
+ "pidns",
+ }
+}
+
+func (x *taskStatData) beforeSave() {}
+
+func (x *taskStatData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+ m.Save(2, &x.tgstats)
+ m.Save(3, &x.pidns)
+}
+
+func (x *taskStatData) afterLoad() {}
+
+func (x *taskStatData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+ m.Load(2, &x.tgstats)
+ m.Load(3, &x.pidns)
+}
+
+func (x *statmData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.statmData"
+}
+
+func (x *statmData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *statmData) beforeSave() {}
+
+func (x *statmData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *statmData) afterLoad() {}
+
+func (x *statmData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *statusData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.statusData"
+}
+
+func (x *statusData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ "pidns",
+ }
+}
+
+func (x *statusData) beforeSave() {}
+
+func (x *statusData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+ m.Save(2, &x.pidns)
+}
+
+func (x *statusData) afterLoad() {}
+
+func (x *statusData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+ m.Load(2, &x.pidns)
+}
+
+func (x *ioData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.ioData"
+}
+
+func (x *ioData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "ioUsage",
+ }
+}
+
+func (x *ioData) beforeSave() {}
+
+func (x *ioData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.ioUsage)
+}
+
+func (x *ioData) afterLoad() {}
+
+func (x *ioData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.ioUsage)
+}
+
+func (x *oomScoreAdj) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.oomScoreAdj"
+}
+
+func (x *oomScoreAdj) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *oomScoreAdj) beforeSave() {}
+
+func (x *oomScoreAdj) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *oomScoreAdj) afterLoad() {}
+
+func (x *oomScoreAdj) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *exeSymlink) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.exeSymlink"
+}
+
+func (x *exeSymlink) StateFields() []string {
+ return []string{
+ "InodeAttrs",
+ "InodeNoopRefCount",
+ "InodeSymlink",
+ "task",
+ }
+}
+
+func (x *exeSymlink) beforeSave() {}
+
+func (x *exeSymlink) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeAttrs)
+ m.Save(1, &x.InodeNoopRefCount)
+ m.Save(2, &x.InodeSymlink)
+ m.Save(3, &x.task)
+}
+
+func (x *exeSymlink) afterLoad() {}
+
+func (x *exeSymlink) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeAttrs)
+ m.Load(1, &x.InodeNoopRefCount)
+ m.Load(2, &x.InodeSymlink)
+ m.Load(3, &x.task)
+}
+
+func (x *mountInfoData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.mountInfoData"
+}
+
+func (x *mountInfoData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *mountInfoData) beforeSave() {}
+
+func (x *mountInfoData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *mountInfoData) afterLoad() {}
+
+func (x *mountInfoData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *mountsData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.mountsData"
+}
+
+func (x *mountsData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "task",
+ }
+}
+
+func (x *mountsData) beforeSave() {}
+
+func (x *mountsData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.task)
+}
+
+func (x *mountsData) afterLoad() {}
+
+func (x *mountsData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.task)
+}
+
+func (x *ifinet6) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.ifinet6"
+}
+
+func (x *ifinet6) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *ifinet6) beforeSave() {}
+
+func (x *ifinet6) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *ifinet6) afterLoad() {}
+
+func (x *ifinet6) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.stack)
+}
+
+func (x *netDevData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netDevData"
+}
+
+func (x *netDevData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *netDevData) beforeSave() {}
+
+func (x *netDevData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *netDevData) afterLoad() {}
+
+func (x *netDevData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.stack)
+}
+
+func (x *netUnixData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netUnixData"
+}
+
+func (x *netUnixData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "kernel",
+ }
+}
+
+func (x *netUnixData) beforeSave() {}
+
+func (x *netUnixData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.kernel)
+}
+
+func (x *netUnixData) afterLoad() {}
+
+func (x *netUnixData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.kernel)
+}
+
+func (x *netTCPData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netTCPData"
+}
+
+func (x *netTCPData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "kernel",
+ }
+}
+
+func (x *netTCPData) beforeSave() {}
+
+func (x *netTCPData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.kernel)
+}
+
+func (x *netTCPData) afterLoad() {}
+
+func (x *netTCPData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.kernel)
+}
+
+func (x *netTCP6Data) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netTCP6Data"
+}
+
+func (x *netTCP6Data) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "kernel",
+ }
+}
+
+func (x *netTCP6Data) beforeSave() {}
+
+func (x *netTCP6Data) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.kernel)
+}
+
+func (x *netTCP6Data) afterLoad() {}
+
+func (x *netTCP6Data) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.kernel)
+}
+
+func (x *netUDPData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netUDPData"
+}
+
+func (x *netUDPData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "kernel",
+ }
+}
+
+func (x *netUDPData) beforeSave() {}
+
+func (x *netUDPData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.kernel)
+}
+
+func (x *netUDPData) afterLoad() {}
+
+func (x *netUDPData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.kernel)
+}
+
+func (x *netSnmpData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netSnmpData"
+}
+
+func (x *netSnmpData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *netSnmpData) beforeSave() {}
+
+func (x *netSnmpData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *netSnmpData) afterLoad() {}
+
+func (x *netSnmpData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.stack)
+}
+
+func (x *netRouteData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netRouteData"
+}
+
+func (x *netRouteData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *netRouteData) beforeSave() {}
+
+func (x *netRouteData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *netRouteData) afterLoad() {}
+
+func (x *netRouteData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.stack)
+}
+
+func (x *netStatData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.netStatData"
+}
+
+func (x *netStatData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *netStatData) beforeSave() {}
+
+func (x *netStatData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *netStatData) afterLoad() {}
+
+func (x *netStatData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.stack)
+}
+
+func (x *tasksInode) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.tasksInode"
+}
+
+func (x *tasksInode) StateFields() []string {
+ return []string{
+ "InodeNotSymlink",
+ "InodeDirectoryNoNewChildren",
+ "InodeAttrs",
+ "OrderedChildren",
+ "AlwaysValid",
+ "locks",
+ "fs",
+ "pidns",
+ "selfSymlink",
+ "threadSelfSymlink",
+ "cgroupControllers",
+ }
+}
+
+func (x *tasksInode) beforeSave() {}
+
+func (x *tasksInode) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.InodeNotSymlink)
+ m.Save(1, &x.InodeDirectoryNoNewChildren)
+ m.Save(2, &x.InodeAttrs)
+ m.Save(3, &x.OrderedChildren)
+ m.Save(4, &x.AlwaysValid)
+ m.Save(5, &x.locks)
+ m.Save(6, &x.fs)
+ m.Save(7, &x.pidns)
+ m.Save(8, &x.selfSymlink)
+ m.Save(9, &x.threadSelfSymlink)
+ m.Save(10, &x.cgroupControllers)
+}
+
+func (x *tasksInode) afterLoad() {}
+
+func (x *tasksInode) StateLoad(m state.Source) {
+ m.Load(0, &x.InodeNotSymlink)
+ m.Load(1, &x.InodeDirectoryNoNewChildren)
+ m.Load(2, &x.InodeAttrs)
+ m.Load(3, &x.OrderedChildren)
+ m.Load(4, &x.AlwaysValid)
+ m.Load(5, &x.locks)
+ m.Load(6, &x.fs)
+ m.Load(7, &x.pidns)
+ m.Load(8, &x.selfSymlink)
+ m.Load(9, &x.threadSelfSymlink)
+ m.Load(10, &x.cgroupControllers)
+}
+
+func (x *statData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.statData"
+}
+
+func (x *statData) StateFields() []string {
+ return []string{
+ "dynamicBytesFileSetAttr",
+ }
+}
+
+func (x *statData) beforeSave() {}
+
+func (x *statData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *statData) afterLoad() {}
+
+func (x *statData) StateLoad(m state.Source) {
+ m.Load(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *loadavgData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.loadavgData"
+}
+
+func (x *loadavgData) StateFields() []string {
+ return []string{
+ "dynamicBytesFileSetAttr",
+ }
+}
+
+func (x *loadavgData) beforeSave() {}
+
+func (x *loadavgData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *loadavgData) afterLoad() {}
+
+func (x *loadavgData) StateLoad(m state.Source) {
+ m.Load(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *meminfoData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.meminfoData"
+}
+
+func (x *meminfoData) StateFields() []string {
+ return []string{
+ "dynamicBytesFileSetAttr",
+ }
+}
+
+func (x *meminfoData) beforeSave() {}
+
+func (x *meminfoData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *meminfoData) afterLoad() {}
+
+func (x *meminfoData) StateLoad(m state.Source) {
+ m.Load(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *uptimeData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.uptimeData"
+}
+
+func (x *uptimeData) StateFields() []string {
+ return []string{
+ "dynamicBytesFileSetAttr",
+ }
+}
+
+func (x *uptimeData) beforeSave() {}
+
+func (x *uptimeData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *uptimeData) afterLoad() {}
+
+func (x *uptimeData) StateLoad(m state.Source) {
+ m.Load(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *versionData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.versionData"
+}
+
+func (x *versionData) StateFields() []string {
+ return []string{
+ "dynamicBytesFileSetAttr",
+ }
+}
+
+func (x *versionData) beforeSave() {}
+
+func (x *versionData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *versionData) afterLoad() {}
+
+func (x *versionData) StateLoad(m state.Source) {
+ m.Load(0, &x.dynamicBytesFileSetAttr)
+}
+
+func (x *filesystemsData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.filesystemsData"
+}
+
+func (x *filesystemsData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ }
+}
+
+func (x *filesystemsData) beforeSave() {}
+
+func (x *filesystemsData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+}
+
+func (x *filesystemsData) afterLoad() {}
+
+func (x *filesystemsData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+}
+
+func (x *mmapMinAddrData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.mmapMinAddrData"
+}
+
+func (x *mmapMinAddrData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "k",
+ }
+}
+
+func (x *mmapMinAddrData) beforeSave() {}
+
+func (x *mmapMinAddrData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.k)
+}
+
+func (x *mmapMinAddrData) afterLoad() {}
+
+func (x *mmapMinAddrData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.Load(1, &x.k)
+}
+
+func (x *hostnameData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.hostnameData"
+}
+
+func (x *hostnameData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ }
+}
+
+func (x *hostnameData) beforeSave() {}
+
+func (x *hostnameData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+}
+
+func (x *hostnameData) afterLoad() {}
+
+func (x *hostnameData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+}
+
+func (x *tcpSackData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.tcpSackData"
+}
+
+func (x *tcpSackData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ "enabled",
+ }
+}
+
+func (x *tcpSackData) beforeSave() {}
+
+func (x *tcpSackData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+ m.Save(2, &x.enabled)
+}
+
+func (x *tcpSackData) afterLoad() {}
+
+func (x *tcpSackData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.LoadWait(1, &x.stack)
+ m.Load(2, &x.enabled)
+}
+
+func (x *tcpRecoveryData) StateTypeName() string {
+ return "pkg/sentry/fsimpl/proc.tcpRecoveryData"
+}
+
+func (x *tcpRecoveryData) StateFields() []string {
+ return []string{
+ "DynamicBytesFile",
+ "stack",
+ }
+}
+
+func (x *tcpRecoveryData) beforeSave() {}
+
+func (x *tcpRecoveryData) StateSave(m state.Sink) {
+ x.beforeSave()
+ m.Save(0, &x.DynamicBytesFile)
+ m.Save(1, &x.stack)
+}
+
+func (x *tcpRecoveryData) afterLoad() {}
+
+func (x *tcpRecoveryData) StateLoad(m state.Source) {
+ m.Load(0, &x.DynamicBytesFile)
+ m.LoadWait(1, &x.stack)
+}
+
+func init() {
+ state.Register((*FilesystemType)(nil))
+ state.Register((*subtasksInode)(nil))
+ state.Register((*taskInode)(nil))
+ state.Register((*fdDirInode)(nil))
+ state.Register((*fdSymlink)(nil))
+ state.Register((*fdInfoDirInode)(nil))
+ state.Register((*fdInfoData)(nil))
+ state.Register((*auxvData)(nil))
+ state.Register((*cmdlineData)(nil))
+ state.Register((*commInode)(nil))
+ state.Register((*commData)(nil))
+ state.Register((*idMapData)(nil))
+ state.Register((*mapsData)(nil))
+ state.Register((*smapsData)(nil))
+ state.Register((*taskStatData)(nil))
+ state.Register((*statmData)(nil))
+ state.Register((*statusData)(nil))
+ state.Register((*ioData)(nil))
+ state.Register((*oomScoreAdj)(nil))
+ state.Register((*exeSymlink)(nil))
+ state.Register((*mountInfoData)(nil))
+ state.Register((*mountsData)(nil))
+ state.Register((*ifinet6)(nil))
+ state.Register((*netDevData)(nil))
+ state.Register((*netUnixData)(nil))
+ state.Register((*netTCPData)(nil))
+ state.Register((*netTCP6Data)(nil))
+ state.Register((*netUDPData)(nil))
+ state.Register((*netSnmpData)(nil))
+ state.Register((*netRouteData)(nil))
+ state.Register((*netStatData)(nil))
+ state.Register((*tasksInode)(nil))
+ state.Register((*statData)(nil))
+ state.Register((*loadavgData)(nil))
+ state.Register((*meminfoData)(nil))
+ state.Register((*uptimeData)(nil))
+ state.Register((*versionData)(nil))
+ state.Register((*filesystemsData)(nil))
+ state.Register((*mmapMinAddrData)(nil))
+ state.Register((*hostnameData)(nil))
+ state.Register((*tcpSackData)(nil))
+ state.Register((*tcpRecoveryData)(nil))
+}
diff --git a/pkg/sentry/fsimpl/proc/tasks_sys_test.go b/pkg/sentry/fsimpl/proc/tasks_sys_test.go
deleted file mode 100644
index be54897bb..000000000
--- a/pkg/sentry/fsimpl/proc/tasks_sys_test.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2019 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 proc
-
-import (
- "bytes"
- "reflect"
- "testing"
-
- "gvisor.dev/gvisor/pkg/abi/linux"
- "gvisor.dev/gvisor/pkg/sentry/contexttest"
- "gvisor.dev/gvisor/pkg/sentry/inet"
-)
-
-func newIPv6TestStack() *inet.TestStack {
- s := inet.NewTestStack()
- s.SupportsIPv6Flag = true
- return s
-}
-
-func TestIfinet6NoAddresses(t *testing.T) {
- n := &ifinet6{stack: newIPv6TestStack()}
- var buf bytes.Buffer
- n.Generate(contexttest.Context(t), &buf)
- if buf.Len() > 0 {
- t.Errorf("n.Generate() generated = %v, want = %v", buf.Bytes(), []byte{})
- }
-}
-
-func TestIfinet6(t *testing.T) {
- s := newIPv6TestStack()
- s.InterfacesMap[1] = inet.Interface{Name: "eth0"}
- s.InterfaceAddrsMap[1] = []inet.InterfaceAddr{
- {
- Family: linux.AF_INET6,
- PrefixLen: 128,
- Addr: []byte("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"),
- },
- }
- s.InterfacesMap[2] = inet.Interface{Name: "eth1"}
- s.InterfaceAddrsMap[2] = []inet.InterfaceAddr{
- {
- Family: linux.AF_INET6,
- PrefixLen: 128,
- Addr: []byte("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"),
- },
- }
- want := map[string]struct{}{
- "000102030405060708090a0b0c0d0e0f 01 80 00 00 eth0\n": {},
- "101112131415161718191a1b1c1d1e1f 02 80 00 00 eth1\n": {},
- }
-
- n := &ifinet6{stack: s}
- contents := n.contents()
- if len(contents) != len(want) {
- t.Errorf("Got len(n.contents()) = %d, want = %d", len(contents), len(want))
- }
- got := map[string]struct{}{}
- for _, l := range contents {
- got[l] = struct{}{}
- }
-
- if !reflect.DeepEqual(got, want) {
- t.Errorf("Got n.contents() = %v, want = %v", got, want)
- }
-}
diff --git a/pkg/sentry/fsimpl/proc/tasks_test.go b/pkg/sentry/fsimpl/proc/tasks_test.go
deleted file mode 100644
index 3c9297dee..000000000
--- a/pkg/sentry/fsimpl/proc/tasks_test.go
+++ /dev/null
@@ -1,505 +0,0 @@
-// Copyright 2019 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 proc
-
-import (
- "fmt"
- "math"
- "path"
- "strconv"
- "testing"
-
- "gvisor.dev/gvisor/pkg/abi/linux"
- "gvisor.dev/gvisor/pkg/context"
- "gvisor.dev/gvisor/pkg/fspath"
- "gvisor.dev/gvisor/pkg/sentry/fsimpl/testutil"
- "gvisor.dev/gvisor/pkg/sentry/fsimpl/tmpfs"
- "gvisor.dev/gvisor/pkg/sentry/kernel"
- "gvisor.dev/gvisor/pkg/sentry/kernel/auth"
- "gvisor.dev/gvisor/pkg/sentry/vfs"
- "gvisor.dev/gvisor/pkg/syserror"
- "gvisor.dev/gvisor/pkg/usermem"
-)
-
-var (
- // Next offset 256 by convention. Adds 1 for the next offset.
- selfLink = vfs.Dirent{Type: linux.DT_LNK, NextOff: 256 + 0 + 1}
- threadSelfLink = vfs.Dirent{Type: linux.DT_LNK, NextOff: 256 + 1 + 1}
-
- // /proc/[pid] next offset starts at 256+2 (files above), then adds the
- // PID, and adds 1 for the next offset.
- proc1 = vfs.Dirent{Type: linux.DT_DIR, NextOff: 258 + 1 + 1}
- proc2 = vfs.Dirent{Type: linux.DT_DIR, NextOff: 258 + 2 + 1}
- proc3 = vfs.Dirent{Type: linux.DT_DIR, NextOff: 258 + 3 + 1}
-)
-
-var (
- tasksStaticFiles = map[string]testutil.DirentType{
- "cpuinfo": linux.DT_REG,
- "filesystems": linux.DT_REG,
- "loadavg": linux.DT_REG,
- "meminfo": linux.DT_REG,
- "mounts": linux.DT_LNK,
- "net": linux.DT_LNK,
- "self": linux.DT_LNK,
- "stat": linux.DT_REG,
- "sys": linux.DT_DIR,
- "thread-self": linux.DT_LNK,
- "uptime": linux.DT_REG,
- "version": linux.DT_REG,
- }
- tasksStaticFilesNextOffs = map[string]int64{
- "self": selfLink.NextOff,
- "thread-self": threadSelfLink.NextOff,
- }
- taskStaticFiles = map[string]testutil.DirentType{
- "auxv": linux.DT_REG,
- "cgroup": linux.DT_REG,
- "cmdline": linux.DT_REG,
- "comm": linux.DT_REG,
- "environ": linux.DT_REG,
- "exe": linux.DT_LNK,
- "fd": linux.DT_DIR,
- "fdinfo": linux.DT_DIR,
- "gid_map": linux.DT_REG,
- "io": linux.DT_REG,
- "maps": linux.DT_REG,
- "mountinfo": linux.DT_REG,
- "mounts": linux.DT_REG,
- "net": linux.DT_DIR,
- "ns": linux.DT_DIR,
- "oom_score": linux.DT_REG,
- "oom_score_adj": linux.DT_REG,
- "smaps": linux.DT_REG,
- "stat": linux.DT_REG,
- "statm": linux.DT_REG,
- "status": linux.DT_REG,
- "task": linux.DT_DIR,
- "uid_map": linux.DT_REG,
- }
-)
-
-func setup(t *testing.T) *testutil.System {
- k, err := testutil.Boot()
- if err != nil {
- t.Fatalf("Error creating kernel: %v", err)
- }
-
- ctx := k.SupervisorContext()
- creds := auth.CredentialsFromContext(ctx)
-
- k.VFS().MustRegisterFilesystemType(Name, &FilesystemType{}, &vfs.RegisterFilesystemTypeOptions{
- AllowUserMount: true,
- })
-
- mntns, err := k.VFS().NewMountNamespace(ctx, creds, "", tmpfs.Name, &vfs.GetFilesystemOptions{})
- if err != nil {
- t.Fatalf("NewMountNamespace(): %v", err)
- }
- pop := &vfs.PathOperation{
- Root: mntns.Root(),
- Start: mntns.Root(),
- Path: fspath.Parse("/proc"),
- }
- if err := k.VFS().MkdirAt(ctx, creds, pop, &vfs.MkdirOptions{Mode: 0777}); err != nil {
- t.Fatalf("MkDir(/proc): %v", err)
- }
-
- pop = &vfs.PathOperation{
- Root: mntns.Root(),
- Start: mntns.Root(),
- Path: fspath.Parse("/proc"),
- }
- mntOpts := &vfs.MountOptions{
- GetFilesystemOptions: vfs.GetFilesystemOptions{
- InternalData: &InternalData{
- Cgroups: map[string]string{
- "cpuset": "/foo/cpuset",
- "memory": "/foo/memory",
- },
- },
- },
- }
- if err := k.VFS().MountAt(ctx, creds, "", pop, Name, mntOpts); err != nil {
- t.Fatalf("MountAt(/proc): %v", err)
- }
- return testutil.NewSystem(ctx, t, k.VFS(), mntns)
-}
-
-func TestTasksEmpty(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- collector := s.ListDirents(s.PathOpAtRoot("/proc"))
- s.AssertAllDirentTypes(collector, tasksStaticFiles)
- s.AssertDirentOffsets(collector, tasksStaticFilesNextOffs)
-}
-
-func TestTasks(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- expectedDirents := make(map[string]testutil.DirentType)
- for n, d := range tasksStaticFiles {
- expectedDirents[n] = d
- }
-
- k := kernel.KernelFromContext(s.Ctx)
- var tasks []*kernel.Task
- for i := 0; i < 5; i++ {
- tc := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, k.GlobalInit().Limits())
- task, err := testutil.CreateTask(s.Ctx, fmt.Sprintf("name-%d", i), tc, s.MntNs, s.Root, s.Root)
- if err != nil {
- t.Fatalf("CreateTask(): %v", err)
- }
- tasks = append(tasks, task)
- expectedDirents[fmt.Sprintf("%d", i+1)] = linux.DT_DIR
- }
-
- collector := s.ListDirents(s.PathOpAtRoot("/proc"))
- s.AssertAllDirentTypes(collector, expectedDirents)
- s.AssertDirentOffsets(collector, tasksStaticFilesNextOffs)
-
- lastPid := 0
- dirents := collector.OrderedDirents()
- doneSkippingNonTaskDirs := false
- for _, d := range dirents {
- pid, err := strconv.Atoi(d.Name)
- if err != nil {
- if !doneSkippingNonTaskDirs {
- // We haven't gotten to the task dirs yet.
- continue
- }
- t.Fatalf("Invalid process directory %q", d.Name)
- }
- doneSkippingNonTaskDirs = true
- if lastPid > pid {
- t.Errorf("pids not in order: %v", dirents)
- }
- found := false
- for _, t := range tasks {
- if k.TaskSet().Root.IDOfTask(t) == kernel.ThreadID(pid) {
- found = true
- }
- }
- if !found {
- t.Errorf("Additional task ID %d listed: %v", pid, tasks)
- }
- // Next offset starts at 256+2 ('self' and 'thread-self'), then adds the
- // PID, and adds 1 for the next offset.
- if want := int64(256 + 2 + pid + 1); d.NextOff != want {
- t.Errorf("Wrong dirent offset want: %d got: %d: %+v", want, d.NextOff, d)
- }
- }
- if !doneSkippingNonTaskDirs {
- t.Fatalf("Never found any process directories.")
- }
-
- // Test lookup.
- for _, path := range []string{"/proc/1", "/proc/2"} {
- fd, err := s.VFS.OpenAt(
- s.Ctx,
- s.Creds,
- s.PathOpAtRoot(path),
- &vfs.OpenOptions{},
- )
- if err != nil {
- t.Fatalf("vfsfs.OpenAt(%q) failed: %v", path, err)
- }
- defer fd.DecRef(s.Ctx)
- buf := make([]byte, 1)
- bufIOSeq := usermem.BytesIOSequence(buf)
- if _, err := fd.Read(s.Ctx, bufIOSeq, vfs.ReadOptions{}); err != syserror.EISDIR {
- t.Errorf("wrong error reading directory: %v", err)
- }
- }
-
- if _, err := s.VFS.OpenAt(
- s.Ctx,
- s.Creds,
- s.PathOpAtRoot("/proc/9999"),
- &vfs.OpenOptions{},
- ); err != syserror.ENOENT {
- t.Fatalf("wrong error from vfsfs.OpenAt(/proc/9999): %v", err)
- }
-}
-
-func TestTasksOffset(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- k := kernel.KernelFromContext(s.Ctx)
- for i := 0; i < 3; i++ {
- tc := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, k.GlobalInit().Limits())
- if _, err := testutil.CreateTask(s.Ctx, fmt.Sprintf("name-%d", i), tc, s.MntNs, s.Root, s.Root); err != nil {
- t.Fatalf("CreateTask(): %v", err)
- }
- }
-
- for _, tc := range []struct {
- name string
- offset int64
- wants map[string]vfs.Dirent
- }{
- {
- name: "small offset",
- offset: 100,
- wants: map[string]vfs.Dirent{
- "self": selfLink,
- "thread-self": threadSelfLink,
- "1": proc1,
- "2": proc2,
- "3": proc3,
- },
- },
- {
- name: "offset at start",
- offset: 256,
- wants: map[string]vfs.Dirent{
- "self": selfLink,
- "thread-self": threadSelfLink,
- "1": proc1,
- "2": proc2,
- "3": proc3,
- },
- },
- {
- name: "skip /proc/self",
- offset: 257,
- wants: map[string]vfs.Dirent{
- "thread-self": threadSelfLink,
- "1": proc1,
- "2": proc2,
- "3": proc3,
- },
- },
- {
- name: "skip symlinks",
- offset: 258,
- wants: map[string]vfs.Dirent{
- "1": proc1,
- "2": proc2,
- "3": proc3,
- },
- },
- {
- name: "skip first process",
- offset: 260,
- wants: map[string]vfs.Dirent{
- "2": proc2,
- "3": proc3,
- },
- },
- {
- name: "last process",
- offset: 261,
- wants: map[string]vfs.Dirent{
- "3": proc3,
- },
- },
- {
- name: "after last",
- offset: 262,
- wants: nil,
- },
- {
- name: "TaskLimit+1",
- offset: kernel.TasksLimit + 1,
- wants: nil,
- },
- {
- name: "max",
- offset: math.MaxInt64,
- wants: nil,
- },
- } {
- t.Run(tc.name, func(t *testing.T) {
- s := s.WithSubtest(t)
- fd, err := s.VFS.OpenAt(
- s.Ctx,
- s.Creds,
- s.PathOpAtRoot("/proc"),
- &vfs.OpenOptions{},
- )
- if err != nil {
- t.Fatalf("vfsfs.OpenAt(/) failed: %v", err)
- }
- defer fd.DecRef(s.Ctx)
- if _, err := fd.Seek(s.Ctx, tc.offset, linux.SEEK_SET); err != nil {
- t.Fatalf("Seek(%d, SEEK_SET): %v", tc.offset, err)
- }
-
- var collector testutil.DirentCollector
- if err := fd.IterDirents(s.Ctx, &collector); err != nil {
- t.Fatalf("IterDirent(): %v", err)
- }
-
- expectedTypes := make(map[string]testutil.DirentType)
- expectedOffsets := make(map[string]int64)
- for name, want := range tc.wants {
- expectedTypes[name] = want.Type
- if want.NextOff != 0 {
- expectedOffsets[name] = want.NextOff
- }
- }
-
- collector.SkipDotsChecks(true) // We seek()ed past the dots.
- s.AssertAllDirentTypes(&collector, expectedTypes)
- s.AssertDirentOffsets(&collector, expectedOffsets)
- })
- }
-}
-
-func TestTask(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- k := kernel.KernelFromContext(s.Ctx)
- tc := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, k.GlobalInit().Limits())
- _, err := testutil.CreateTask(s.Ctx, "name", tc, s.MntNs, s.Root, s.Root)
- if err != nil {
- t.Fatalf("CreateTask(): %v", err)
- }
-
- collector := s.ListDirents(s.PathOpAtRoot("/proc/1"))
- s.AssertAllDirentTypes(collector, taskStaticFiles)
-}
-
-func TestProcSelf(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- k := kernel.KernelFromContext(s.Ctx)
- tc := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, k.GlobalInit().Limits())
- task, err := testutil.CreateTask(s.Ctx, "name", tc, s.MntNs, s.Root, s.Root)
- if err != nil {
- t.Fatalf("CreateTask(): %v", err)
- }
-
- collector := s.WithTemporaryContext(task).ListDirents(&vfs.PathOperation{
- Root: s.Root,
- Start: s.Root,
- Path: fspath.Parse("/proc/self/"),
- FollowFinalSymlink: true,
- })
- s.AssertAllDirentTypes(collector, taskStaticFiles)
-}
-
-func iterateDir(ctx context.Context, t *testing.T, s *testutil.System, fd *vfs.FileDescription) {
- t.Logf("Iterating: %s", fd.MappedName(ctx))
-
- var collector testutil.DirentCollector
- if err := fd.IterDirents(ctx, &collector); err != nil {
- t.Fatalf("IterDirents(): %v", err)
- }
- if err := collector.Contains(".", linux.DT_DIR); err != nil {
- t.Error(err.Error())
- }
- if err := collector.Contains("..", linux.DT_DIR); err != nil {
- t.Error(err.Error())
- }
-
- for _, d := range collector.Dirents() {
- if d.Name == "." || d.Name == ".." {
- continue
- }
- absPath := path.Join(fd.MappedName(ctx), d.Name)
- if d.Type == linux.DT_LNK {
- link, err := s.VFS.ReadlinkAt(
- ctx,
- auth.CredentialsFromContext(ctx),
- &vfs.PathOperation{Root: s.Root, Start: s.Root, Path: fspath.Parse(absPath)},
- )
- if err != nil {
- t.Errorf("vfsfs.ReadlinkAt(%v) failed: %v", absPath, err)
- } else {
- t.Logf("Skipping symlink: %s => %s", absPath, link)
- }
- continue
- }
-
- t.Logf("Opening: %s", absPath)
- child, err := s.VFS.OpenAt(
- ctx,
- auth.CredentialsFromContext(ctx),
- &vfs.PathOperation{Root: s.Root, Start: s.Root, Path: fspath.Parse(absPath)},
- &vfs.OpenOptions{},
- )
- if err != nil {
- t.Errorf("vfsfs.OpenAt(%v) failed: %v", absPath, err)
- continue
- }
- defer child.DecRef(ctx)
- stat, err := child.Stat(ctx, vfs.StatOptions{})
- if err != nil {
- t.Errorf("Stat(%v) failed: %v", absPath, err)
- }
- if got := linux.FileMode(stat.Mode).DirentType(); got != d.Type {
- t.Errorf("wrong file mode, stat: %v, dirent: %v", got, d.Type)
- }
- if d.Type == linux.DT_DIR {
- // Found another dir, let's do it again!
- iterateDir(ctx, t, s, child)
- }
- }
-}
-
-// TestTree iterates all directories and stats every file.
-func TestTree(t *testing.T) {
- s := setup(t)
- defer s.Destroy()
-
- k := kernel.KernelFromContext(s.Ctx)
-
- pop := &vfs.PathOperation{
- Root: s.Root,
- Start: s.Root,
- Path: fspath.Parse("test-file"),
- }
- opts := &vfs.OpenOptions{
- Flags: linux.O_RDONLY | linux.O_CREAT,
- Mode: 0777,
- }
- file, err := s.VFS.OpenAt(s.Ctx, s.Creds, pop, opts)
- if err != nil {
- t.Fatalf("failed to create test file: %v", err)
- }
- defer file.DecRef(s.Ctx)
-
- var tasks []*kernel.Task
- for i := 0; i < 5; i++ {
- tc := k.NewThreadGroup(nil, k.RootPIDNamespace(), kernel.NewSignalHandlers(), linux.SIGCHLD, k.GlobalInit().Limits())
- task, err := testutil.CreateTask(s.Ctx, fmt.Sprintf("name-%d", i), tc, s.MntNs, s.Root, s.Root)
- if err != nil {
- t.Fatalf("CreateTask(): %v", err)
- }
- // Add file to populate /proc/[pid]/fd and fdinfo directories.
- task.FDTable().NewFDVFS2(task, 0, file, kernel.FDFlags{})
- tasks = append(tasks, task)
- }
-
- ctx := tasks[0]
- fd, err := s.VFS.OpenAt(
- ctx,
- auth.CredentialsFromContext(s.Ctx),
- &vfs.PathOperation{Root: s.Root, Start: s.Root, Path: fspath.Parse("/proc")},
- &vfs.OpenOptions{},
- )
- if err != nil {
- t.Fatalf("vfsfs.OpenAt(/proc) failed: %v", err)
- }
- iterateDir(ctx, t, s, fd)
- fd.DecRef(ctx)
-}