diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-09-24 17:45:52 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-09-24 17:45:52 +0000 |
commit | 375943dc8b969a88287164fc1e1ceaf86add3813 (patch) | |
tree | 5d95e0d51607368d79fefd5801de4c1a52b6b09d /pkg/sentry/inet/atomicptr_netns_unsafe.go | |
parent | a1b00da7bd8df0b7d98fdd14b0cbcf314013bb3d (diff) | |
parent | b510c9846446d7f423c0531ec661c4344f96c578 (diff) |
Merge release-20210921.0-29-gb510c9846 (automated)
Diffstat (limited to 'pkg/sentry/inet/atomicptr_netns_unsafe.go')
-rw-r--r-- | pkg/sentry/inet/atomicptr_netns_unsafe.go | 39 |
1 files changed, 39 insertions, 0 deletions
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)) +} |