diff options
Diffstat (limited to 'pkg/sentry/inet')
-rw-r--r-- | pkg/sentry/inet/BUILD | 34 | ||||
-rw-r--r-- | pkg/sentry/inet/atomicptr_netns_unsafe.go | 39 | ||||
-rw-r--r-- | pkg/sentry/inet/inet_state_autogen.go | 70 | ||||
-rw-r--r-- | pkg/sentry/inet/inet_unsafe_state_autogen.go | 38 |
4 files changed, 147 insertions, 34 deletions
diff --git a/pkg/sentry/inet/BUILD b/pkg/sentry/inet/BUILD deleted file mode 100644 index 2363cec5f..000000000 --- a/pkg/sentry/inet/BUILD +++ /dev/null @@ -1,34 +0,0 @@ -load("//tools:defs.bzl", "go_library") -load("//tools/go_generics:defs.bzl", "go_template_instance") - -package( - default_visibility = ["//:sandbox"], - licenses = ["notice"], -) - -go_template_instance( - name = "atomicptr_netns", - out = "atomicptr_netns_unsafe.go", - package = "inet", - prefix = "Namespace", - template = "//pkg/sync/atomicptr:generic_atomicptr", - types = { - "Value": "Namespace", - }, -) - -go_library( - name = "inet", - srcs = [ - "atomicptr_netns_unsafe.go", - "context.go", - "inet.go", - "namespace.go", - "test_stack.go", - ], - deps = [ - "//pkg/context", - "//pkg/tcpip", - "//pkg/tcpip/stack", - ], -) diff --git a/pkg/sentry/inet/atomicptr_netns_unsafe.go b/pkg/sentry/inet/atomicptr_netns_unsafe.go new file mode 100644 index 000000000..e338ca663 --- /dev/null +++ b/pkg/sentry/inet/atomicptr_netns_unsafe.go @@ -0,0 +1,39 @@ +package inet + +import ( + "sync/atomic" + "unsafe" +) + +// An AtomicPtr is a pointer to a value of type Value that can be atomically +// loaded and stored. The zero value of an AtomicPtr represents nil. +// +// Note that copying AtomicPtr by value performs a non-atomic read of the +// stored pointer, which is unsafe if Store() can be called concurrently; in +// this case, do `dst.Store(src.Load())` instead. +// +// +stateify savable +type NamespaceAtomicPtr struct { + ptr unsafe.Pointer `state:".(*Namespace)"` +} + +func (p *NamespaceAtomicPtr) savePtr() *Namespace { + return p.Load() +} + +func (p *NamespaceAtomicPtr) loadPtr(v *Namespace) { + p.Store(v) +} + +// Load returns the value set by the most recent Store. It returns nil if there +// has been no previous call to Store. +// +//go:nosplit +func (p *NamespaceAtomicPtr) Load() *Namespace { + return (*Namespace)(atomic.LoadPointer(&p.ptr)) +} + +// Store sets the value returned by Load to x. +func (p *NamespaceAtomicPtr) Store(x *Namespace) { + atomic.StorePointer(&p.ptr, (unsafe.Pointer)(x)) +} diff --git a/pkg/sentry/inet/inet_state_autogen.go b/pkg/sentry/inet/inet_state_autogen.go new file mode 100644 index 000000000..30af4fb91 --- /dev/null +++ b/pkg/sentry/inet/inet_state_autogen.go @@ -0,0 +1,70 @@ +// automatically generated by stateify. + +package inet + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (t *TCPBufferSize) StateTypeName() string { + return "pkg/sentry/inet.TCPBufferSize" +} + +func (t *TCPBufferSize) StateFields() []string { + return []string{ + "Min", + "Default", + "Max", + } +} + +func (t *TCPBufferSize) beforeSave() {} + +// +checklocksignore +func (t *TCPBufferSize) StateSave(stateSinkObject state.Sink) { + t.beforeSave() + stateSinkObject.Save(0, &t.Min) + stateSinkObject.Save(1, &t.Default) + stateSinkObject.Save(2, &t.Max) +} + +func (t *TCPBufferSize) afterLoad() {} + +// +checklocksignore +func (t *TCPBufferSize) StateLoad(stateSourceObject state.Source) { + stateSourceObject.Load(0, &t.Min) + stateSourceObject.Load(1, &t.Default) + stateSourceObject.Load(2, &t.Max) +} + +func (n *Namespace) StateTypeName() string { + return "pkg/sentry/inet.Namespace" +} + +func (n *Namespace) StateFields() []string { + return []string{ + "creator", + "isRoot", + } +} + +func (n *Namespace) beforeSave() {} + +// +checklocksignore +func (n *Namespace) StateSave(stateSinkObject state.Sink) { + n.beforeSave() + stateSinkObject.Save(0, &n.creator) + stateSinkObject.Save(1, &n.isRoot) +} + +// +checklocksignore +func (n *Namespace) StateLoad(stateSourceObject state.Source) { + stateSourceObject.LoadWait(0, &n.creator) + stateSourceObject.Load(1, &n.isRoot) + stateSourceObject.AfterLoad(n.afterLoad) +} + +func init() { + state.Register((*TCPBufferSize)(nil)) + state.Register((*Namespace)(nil)) +} diff --git a/pkg/sentry/inet/inet_unsafe_state_autogen.go b/pkg/sentry/inet/inet_unsafe_state_autogen.go new file mode 100644 index 000000000..d1a8d74b3 --- /dev/null +++ b/pkg/sentry/inet/inet_unsafe_state_autogen.go @@ -0,0 +1,38 @@ +// automatically generated by stateify. + +package inet + +import ( + "gvisor.dev/gvisor/pkg/state" +) + +func (p *NamespaceAtomicPtr) StateTypeName() string { + return "pkg/sentry/inet.NamespaceAtomicPtr" +} + +func (p *NamespaceAtomicPtr) StateFields() []string { + return []string{ + "ptr", + } +} + +func (p *NamespaceAtomicPtr) beforeSave() {} + +// +checklocksignore +func (p *NamespaceAtomicPtr) StateSave(stateSinkObject state.Sink) { + p.beforeSave() + var ptrValue *Namespace + ptrValue = p.savePtr() + stateSinkObject.SaveValue(0, ptrValue) +} + +func (p *NamespaceAtomicPtr) afterLoad() {} + +// +checklocksignore +func (p *NamespaceAtomicPtr) StateLoad(stateSourceObject state.Source) { + stateSourceObject.LoadValue(0, new(*Namespace), func(y interface{}) { p.loadPtr(y.(*Namespace)) }) +} + +func init() { + state.Register((*NamespaceAtomicPtr)(nil)) +} |