mirror of
https://github.com/taigrr/gopher-os
synced 2025-01-18 04:43:13 -08:00
Allow mem region visitors to abort the scan by returning false
This commit is contained in:
parent
61314a9c33
commit
e1ada1ac8a
@ -119,8 +119,9 @@ var (
|
||||
)
|
||||
|
||||
// MemRegionVisitor defies a visitor function that gets invoked by VisitMemRegions
|
||||
// for each memory region provided by the boot loader.
|
||||
type MemRegionVisitor func(entry *MemoryMapEntry)
|
||||
// for each memory region provided by the boot loader. The visitor must return true
|
||||
// to continue or false to abort the scan.
|
||||
type MemRegionVisitor func(entry *MemoryMapEntry) bool
|
||||
|
||||
// SetInfoPtr updates the internal multiboot information pointer to the given
|
||||
// value. This function must be invoked before invoking any other function
|
||||
@ -151,7 +152,9 @@ func VisitMemRegions(visitor MemRegionVisitor) {
|
||||
entry.Type = MemReserved
|
||||
}
|
||||
|
||||
visitor(entry)
|
||||
if !visitor(entry) {
|
||||
return
|
||||
}
|
||||
|
||||
curPtr += uintptr(ptrMapHeader.entrySize)
|
||||
}
|
||||
|
@ -59,8 +59,9 @@ func TestVisitMemRegion(t *testing.T) {
|
||||
var visitCount int
|
||||
|
||||
SetInfoPtr(uintptr(unsafe.Pointer(&emptyInfoData[0])))
|
||||
VisitMemRegions(func(_ *MemoryMapEntry) {
|
||||
VisitMemRegions(func(_ *MemoryMapEntry) bool {
|
||||
visitCount++
|
||||
return true
|
||||
})
|
||||
|
||||
if visitCount != 0 {
|
||||
@ -71,7 +72,7 @@ func TestVisitMemRegion(t *testing.T) {
|
||||
SetInfoPtr(uintptr(unsafe.Pointer(&multibootInfoTestData[0])))
|
||||
multibootInfoTestData[128] = 0xFF
|
||||
|
||||
VisitMemRegions(func(entry *MemoryMapEntry) {
|
||||
VisitMemRegions(func(entry *MemoryMapEntry) bool {
|
||||
if entry.PhysAddress != specs[visitCount].expPhys {
|
||||
t.Errorf("[visit %d] expected physical address to be %x; got %x", visitCount, specs[visitCount].expPhys, entry.PhysAddress)
|
||||
}
|
||||
@ -82,11 +83,23 @@ func TestVisitMemRegion(t *testing.T) {
|
||||
t.Errorf("[visit %d] expected region type to be %d; got %d", visitCount, specs[visitCount].expType, entry.Type)
|
||||
}
|
||||
visitCount++
|
||||
return true
|
||||
})
|
||||
|
||||
if visitCount != len(specs) {
|
||||
t.Errorf("expected the visitor func to be invoked %d times; got %d", len(specs), visitCount)
|
||||
}
|
||||
|
||||
// Test that the visitor function can abort the scan by returning false
|
||||
visitCount = 0
|
||||
VisitMemRegions(func(entry *MemoryMapEntry) bool {
|
||||
visitCount++
|
||||
return false
|
||||
})
|
||||
|
||||
if visitCount != 1 {
|
||||
t.Errorf("expected the visitor func to be invoked %d times; got %d", 1, visitCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFramebufferInfo(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user