github.com/ttpreport/gvisor-ligolo@v0.0.0-20240123134145-a858404967ba/pkg/sentry/mm/save_restore.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package mm 16 17 import ( 18 "fmt" 19 20 "github.com/ttpreport/gvisor-ligolo/pkg/context" 21 ) 22 23 // InvalidateUnsavable invokes memmap.Mappable.InvalidateUnsavable on all 24 // Mappables mapped by mm. 25 func (mm *MemoryManager) InvalidateUnsavable(ctx context.Context) error { 26 mm.mappingMu.RLock() 27 defer mm.mappingMu.RUnlock() 28 for vseg := mm.vmas.FirstSegment(); vseg.Ok(); vseg = vseg.NextSegment() { 29 if vma := vseg.ValuePtr(); vma.mappable != nil { 30 if err := vma.mappable.InvalidateUnsavable(ctx); err != nil { 31 return err 32 } 33 } 34 } 35 return nil 36 } 37 38 // beforeSave is invoked by stateify. 39 func (mm *MemoryManager) beforeSave() { 40 mf := mm.mfp.MemoryFile() 41 for pseg := mm.pmas.FirstSegment(); pseg.Ok(); pseg = pseg.NextSegment() { 42 if pma := pseg.ValuePtr(); pma.file != mf { 43 // InvalidateUnsavable should have caused all such pmas to be 44 // invalidated. 45 panic(fmt.Sprintf("Can't save pma %#v with non-MemoryFile of type %T:\n%s", pseg.Range(), pma.file, mm)) 46 } 47 } 48 } 49 50 // afterLoad is invoked by stateify. 51 func (mm *MemoryManager) afterLoad() { 52 mm.haveASIO = mm.p.SupportsAddressSpaceIO() 53 mf := mm.mfp.MemoryFile() 54 for pseg := mm.pmas.FirstSegment(); pseg.Ok(); pseg = pseg.NextSegment() { 55 pseg.ValuePtr().file = mf 56 } 57 }