-
Notifications
You must be signed in to change notification settings - Fork 1
/
metadata.go
81 lines (66 loc) · 2.54 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package metadata
import (
"github.com/launchdarkly/go-jsonstream/v3/jwriter"
"github.com/vkngwrapper/arsenal/memutils"
"github.com/vkngwrapper/core/v2/common"
"github.com/vkngwrapper/core/v2/driver"
"golang.org/x/exp/slog"
"unsafe"
)
type BlockMetadata interface {
Init(size int)
Size() int
Validate() error
AllocationCount() int
FreeRegionsCount() int
SumFreeSize() int
GranularityHandler() GranularityCheck
IsEmpty() bool
VisitAllBlocks(handleBlock func(handle BlockAllocationHandle, offset int, size int, userData any, free bool) error) error
AllocationListBegin() (BlockAllocationHandle, error)
FindNextAllocation(allocHandle BlockAllocationHandle) (BlockAllocationHandle, error)
FindNextFreeRegionSize(allocHandle BlockAllocationHandle) (int, error)
AllocationOffset(allocHandle BlockAllocationHandle) (int, error)
AllocationUserData(allocHandle BlockAllocationHandle) (any, error)
SetAllocationUserData(allocHandle BlockAllocationHandle, userData any) error
AddDetailedStatistics(stats *memutils.DetailedStatistics)
AddStatistics(stats *memutils.Statistics)
Clear()
DebugLogAllAllocations(log *slog.Logger, logFunc func(log *slog.Logger, offset int, size int, userData any))
PrintDetailedMapHeader(json jwriter.ObjectState)
CheckCorruption(blockData unsafe.Pointer) (common.VkResult, error)
CreateAllocationRequest(
allocSize int, allocAlignment uint,
upperAddress bool,
allocType uint32,
strategy AllocationStrategy,
) (bool, AllocationRequest, error)
Alloc(request AllocationRequest, allocType uint32, userData any) error
Free(allocHandle BlockAllocationHandle) error
}
type BlockMetadataBase struct {
size int
allocationCallbacks *driver.AllocationCallbacks
bufferImageGranlarity int
granularityHandler GranularityCheck
}
func NewBlockMetadata(bufferImageGranularity int, granularityHandler GranularityCheck) BlockMetadataBase {
return BlockMetadataBase{
size: 0,
bufferImageGranlarity: bufferImageGranularity,
granularityHandler: granularityHandler,
}
}
func (m *BlockMetadataBase) Init(size int) {
m.size = size
}
func (m *BlockMetadataBase) Size() int { return m.size }
func (m *BlockMetadataBase) GranularityHandler() GranularityCheck {
return m.granularityHandler
}
func (m *BlockMetadataBase) PrintDetailedMap_Header(json jwriter.ObjectState, unusedBytes, allocationCount, unusedRangeCount int) {
json.Name("TotalBytes").Int(m.Size())
json.Name("UnusedBytes").Int(unusedBytes)
json.Name("Allocations").Int(allocationCount)
json.Name("UnusedRanges").Int(unusedRangeCount)
}