1
0
mirror of https://github.com/taigrr/gopher-os synced 2025-01-18 04:43:13 -08:00

Unexport bitmap allocator instance and export AllocFrame helper

This allows us to mock calls to the frame allocator from other packages
while testing.
This commit is contained in:
Achilleas Anagnostopoulos 2017-06-30 07:48:37 +01:00
parent 6ee95b439e
commit 636220ab1d
2 changed files with 8 additions and 8 deletions

View File

@ -14,9 +14,9 @@ import (
)
var (
// FrameAllocator is a BitmapAllocator instance that serves as the
// bitmapAllocator is a BitmapAllocator instance that serves as the
// primary allocator for reserving pages.
FrameAllocator BitmapAllocator
bitmapAllocator BitmapAllocator
errBitmapAllocOutOfMemory = &kernel.Error{Module: "bitmap_alloc", Message: "out of memory"}
errBitmapAllocFrameNotManaged = &kernel.Error{Module: "bitmap_alloc", Message: "frame not managed by this allocator"}
@ -306,10 +306,10 @@ func earlyAllocFrame() (pmm.Frame, *kernel.Error) {
return earlyAllocator.AllocFrame()
}
// sysAllocFrame is a helper that delegates a frame allocation request to the
// AllocFrame is a helper that delegates a frame allocation request to the
// bitmap allocator instance.
func sysAllocFrame() (pmm.Frame, *kernel.Error) {
return FrameAllocator.AllocFrame()
func AllocFrame() (pmm.Frame, *kernel.Error) {
return bitmapAllocator.AllocFrame()
}
// Init sets up the kernel physical memory allocation sub-system.
@ -318,10 +318,10 @@ func Init(kernelStart, kernelEnd uintptr) *kernel.Error {
earlyAllocator.printMemoryMap()
vmm.SetFrameAllocator(earlyAllocFrame)
if err := FrameAllocator.init(); err != nil {
if err := bitmapAllocator.init(); err != nil {
return err
}
vmm.SetFrameAllocator(sysAllocFrame)
vmm.SetFrameAllocator(AllocFrame)
return nil
}

View File

@ -413,7 +413,7 @@ func TestAllocatorPackageInit(t *testing.T) {
}
// At this point sysAllocFrame should work
if _, err := sysAllocFrame(); err != nil {
if _, err := AllocFrame(); err != nil {
t.Fatal(err)
}
})