summaryrefslogtreecommitdiffhomepage
path: root/runsc/boot
diff options
context:
space:
mode:
Diffstat (limited to 'runsc/boot')
-rw-r--r--runsc/boot/BUILD2
-rw-r--r--runsc/boot/controller.go9
-rw-r--r--runsc/boot/events.go2
-rw-r--r--runsc/boot/loader.go26
4 files changed, 35 insertions, 4 deletions
diff --git a/runsc/boot/BUILD b/runsc/boot/BUILD
index daa197437..df9907e52 100644
--- a/runsc/boot/BUILD
+++ b/runsc/boot/BUILD
@@ -51,6 +51,8 @@ go_library(
"//pkg/sentry/kernel/kdefs",
"//pkg/sentry/limits",
"//pkg/sentry/loader",
+ "//pkg/sentry/memutil",
+ "//pkg/sentry/pgalloc",
"//pkg/sentry/platform",
"//pkg/sentry/platform/kvm",
"//pkg/sentry/platform/ptrace",
diff --git a/runsc/boot/controller.go b/runsc/boot/controller.go
index a864be720..14e1eba5b 100644
--- a/runsc/boot/controller.go
+++ b/runsc/boot/controller.go
@@ -332,6 +332,11 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error {
k := &kernel.Kernel{
Platform: p,
}
+ mf, err := createMemoryFile()
+ if err != nil {
+ return fmt.Errorf("creating memory file: %v", err)
+ }
+ k.SetMemoryFile(mf)
cm.l.k = k
// Set up the restore environment.
@@ -362,7 +367,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error {
loadOpts := state.LoadOpts{
Source: o.FilePayload.Files[0],
}
- if err := loadOpts.Load(k, p, networkStack); err != nil {
+ if err := loadOpts.Load(k, networkStack); err != nil {
return err
}
@@ -384,7 +389,7 @@ func (cm *containerManager) Restore(o *RestoreOpts, _ *struct{}) error {
cm.l.mu.Lock()
eid := execID{cid: o.SandboxID}
cm.l.processes = map[execID]*execProcess{
- eid: &execProcess{
+ eid: {
tg: cm.l.k.GlobalInit(),
},
}
diff --git a/runsc/boot/events.go b/runsc/boot/events.go
index f954b8c0b..717adfedd 100644
--- a/runsc/boot/events.go
+++ b/runsc/boot/events.go
@@ -68,7 +68,7 @@ func (cm *containerManager) Event(_ *struct{}, out *Event) error {
}
func (s *Stats) populateMemory(k *kernel.Kernel) {
- mem := k.Platform.Memory()
+ mem := k.MemoryFile()
mem.UpdateUsage()
_, totalUsage := usage.MemoryAccounting.Copy()
s.Memory.Usage = MemoryEntry{
diff --git a/runsc/boot/loader.go b/runsc/boot/loader.go
index 9ebe64dce..56cb137f0 100644
--- a/runsc/boot/loader.go
+++ b/runsc/boot/loader.go
@@ -37,6 +37,8 @@ import (
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel"
"gvisor.googlesource.com/gvisor/pkg/sentry/kernel/auth"
"gvisor.googlesource.com/gvisor/pkg/sentry/loader"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/memutil"
+ "gvisor.googlesource.com/gvisor/pkg/sentry/pgalloc"
"gvisor.googlesource.com/gvisor/pkg/sentry/platform"
"gvisor.googlesource.com/gvisor/pkg/sentry/platform/kvm"
"gvisor.googlesource.com/gvisor/pkg/sentry/platform/ptrace"
@@ -189,6 +191,13 @@ func New(args Args) (*Loader, error) {
Platform: p,
}
+ // Create memory file.
+ mf, err := createMemoryFile()
+ if err != nil {
+ return nil, fmt.Errorf("creating memory file: %v", err)
+ }
+ k.SetMemoryFile(mf)
+
// Create VDSO.
//
// Pass k as the platform since it is savable, unlike the actual platform.
@@ -297,7 +306,7 @@ func New(args Args) (*Loader, error) {
stdioFDs: args.StdioFDs,
rootProcArgs: procArgs,
sandboxID: args.ID,
- processes: map[execID]*execProcess{eid: &execProcess{}},
+ processes: map[execID]*execProcess{eid: {}},
}
// We don't care about child signals; some platforms can generate a
@@ -404,6 +413,21 @@ func createPlatform(conf *Config, deviceFD int) (platform.Platform, error) {
}
}
+func createMemoryFile() (*pgalloc.MemoryFile, error) {
+ const memfileName = "runsc-memory"
+ memfd, err := memutil.CreateMemFD(memfileName, 0)
+ if err != nil {
+ return nil, fmt.Errorf("error creating memfd: %v", err)
+ }
+ memfile := os.NewFile(uintptr(memfd), memfileName)
+ mf, err := pgalloc.NewMemoryFile(memfile)
+ if err != nil {
+ memfile.Close()
+ return nil, fmt.Errorf("error creating pgalloc.MemoryFile: %v", err)
+ }
+ return mf, nil
+}
+
// Run runs the root container..
func (l *Loader) Run() error {
err := l.run()