summaryrefslogtreecommitdiffhomepage
path: root/pkg/sentry/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/sentry/kernel')
-rw-r--r--pkg/sentry/kernel/pipe/BUILD15
-rw-r--r--pkg/sentry/kernel/pipe/buffers.go6
-rw-r--r--pkg/sentry/kernel/pipe/pipe.go8
3 files changed, 18 insertions, 11 deletions
diff --git a/pkg/sentry/kernel/pipe/BUILD b/pkg/sentry/kernel/pipe/BUILD
index 011a3f349..6b23117d9 100644
--- a/pkg/sentry/kernel/pipe/BUILD
+++ b/pkg/sentry/kernel/pipe/BUILD
@@ -1,10 +1,24 @@
package(licenses = ["notice"])
+load("//tools/go_generics:defs.bzl", "go_template_instance")
load("//tools/go_stateify:defs.bzl", "go_library", "go_test")
+go_template_instance(
+ name = "buffer_list",
+ out = "buffer_list.go",
+ package = "pipe",
+ prefix = "buffer",
+ template = "//pkg/ilist:generic_list",
+ types = {
+ "Element": "*Buffer",
+ "Linker": "*Buffer",
+ },
+)
+
go_library(
name = "pipe",
srcs = [
+ "buffer_list.go",
"buffers.go",
"device.go",
"node.go",
@@ -18,7 +32,6 @@ go_library(
deps = [
"//pkg/abi/linux",
"//pkg/amutex",
- "//pkg/ilist",
"//pkg/sentry/arch",
"//pkg/sentry/context",
"//pkg/sentry/device",
diff --git a/pkg/sentry/kernel/pipe/buffers.go b/pkg/sentry/kernel/pipe/buffers.go
index fa8045910..54e059f8b 100644
--- a/pkg/sentry/kernel/pipe/buffers.go
+++ b/pkg/sentry/kernel/pipe/buffers.go
@@ -14,16 +14,12 @@
package pipe
-import (
- "gvisor.googlesource.com/gvisor/pkg/ilist"
-)
-
// Buffer encapsulates a queueable byte buffer that can
// easily be truncated. It is designed only for use with pipes.
//
// +stateify savable
type Buffer struct {
- ilist.Entry
+ bufferEntry
data []byte
}
diff --git a/pkg/sentry/kernel/pipe/pipe.go b/pkg/sentry/kernel/pipe/pipe.go
index fad077d2d..357d1162e 100644
--- a/pkg/sentry/kernel/pipe/pipe.go
+++ b/pkg/sentry/kernel/pipe/pipe.go
@@ -25,7 +25,6 @@ import (
"sync/atomic"
"syscall"
- "gvisor.googlesource.com/gvisor/pkg/ilist"
"gvisor.googlesource.com/gvisor/pkg/sentry/context"
"gvisor.googlesource.com/gvisor/pkg/sentry/fs"
"gvisor.googlesource.com/gvisor/pkg/sentry/usermem"
@@ -51,7 +50,7 @@ type Pipe struct {
Dirent *fs.Dirent
// The buffered byte queue.
- data ilist.List
+ data bufferList
// Max size of the pipe in bytes. When this max has been reached,
// writers will get EWOULDBLOCK.
@@ -170,13 +169,12 @@ func (p *Pipe) read(ctx context.Context, dst usermem.IOSequence) (int64, error)
return 0, syserror.ErrWouldBlock
}
var n int64
- for b := p.data.Front(); b != nil; b = p.data.Front() {
- buffer := b.(*Buffer)
+ for buffer := p.data.Front(); buffer != nil; buffer = p.data.Front() {
n0, err := dst.CopyOut(ctx, buffer.bytes())
n += int64(n0)
p.size -= n0
if buffer.truncate(n0) == 0 {
- p.data.Remove(b)
+ p.data.Remove(buffer)
}
dst = dst.DropFirst(n0)
if dst.NumBytes() == 0 || err != nil {