本文整理匯總了Golang中novmm/platform.Vm.MapUserMemory方法的典型用法代碼示例。如果您正苦於以下問題:Golang Vm.MapUserMemory方法的具體用法?Golang Vm.MapUserMemory怎麽用?Golang Vm.MapUserMemory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類novmm/platform.Vm
的用法示例。
在下文中一共展示了Vm.MapUserMemory方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Reserve
func (memory *MemoryMap) Reserve(
vm *platform.Vm,
device Device,
memtype MemoryType,
start platform.Paddr,
size uint64,
user []byte) error {
// Verbose messages.
device.Debug(
"reserving (type: %d) of size %x in [%x,%x]",
memtype,
size,
start,
start.After(size-1))
// Ensure all targets are aligned.
if (start.Align(platform.PageSize, false) != start) ||
(size%platform.PageSize != 0) {
return MemoryUnaligned
}
// Ensure underlying map is aligned.
// This may be harder to detect later on.
if user != nil &&
uintptr(unsafe.Pointer(&user[0]))%platform.PageSize != 0 {
return MemoryUnaligned
}
// Add the region.
region := &TypedMemoryRegion{
MemoryRegion: MemoryRegion{start, size},
MemoryType: memtype,
Device: device,
user: user,
allocated: make(map[uint64]uint64),
}
err := memory.Add(region)
if err != nil {
return err
}
// Do the mapping.
switch region.MemoryType {
case MemoryTypeUser:
err = vm.MapUserMemory(region.Start, region.Size, region.user)
case MemoryTypeReserved:
err = vm.MapReservedMemory(region.Start, region.Size)
case MemoryTypeAcpi:
err = vm.MapUserMemory(region.Start, region.Size, region.user)
case MemoryTypeSpecial:
err = vm.MapSpecialMemory(region.Start)
}
return err
}