github.com/pidato/unsafe@v0.1.4/memory/rpmalloc/model.go (about) 1 package rpmalloc 2 3 type Config struct { 4 //! Map memory pages for the given number of bytes. The returned address MUST be 5 // aligned to the rpmalloc span size, which will always be a power of two. 6 // Optionally the function can store an alignment offset in the offset variable 7 // in case it performs alignment and the returned pointer is offset from the 8 // actual start of the memory region due to this alignment. The alignment offset 9 // will be passed to the memory unmap function. The alignment offset MUST NOT be 10 // larger than 65535 (storable in an uint16_t), if it is you must use natural 11 // alignment to shift it into 16 bits. If you set a memory_map function, you 12 // must also set a memory_unmap function or else the default implementation will 13 // be used for both. 14 MemoryMap uintptr 15 //! Unmap the memory pages starting at address and spanning the given number of bytes. 16 // If release is set to non-zero, the unmap is for an entire span range as returned by 17 // a previous libfuzzerCall to memory_map and that the entire range should be released. The 18 // release argument holds the size of the entire span range. If release is set to 0, 19 // the unmap is a partial decommit of a subset of the mapped memory range. 20 // If you set a memory_unmap function, you must also set a memory_map function or 21 // else the default implementation will be used for both. 22 MemoryUnmap uintptr 23 //! Called when an assert fails, if asserts are enabled. Will use the standard assert() 24 // if this is not set. 25 ErrorCallback uintptr 26 //! Called when a libfuzzerCall to map memory pages fails (out of memory). If this callback is 27 // not set or returns zero the library will return a null pointer in the allocation 28 // libfuzzerCall. If this callback returns non-zero the map libfuzzerCall will be retried. The argument 29 // passed is the number of bytes that was requested in the map libfuzzerCall. Only used if 30 // the default system memory map function is used (memory_map callback is not set). 31 MapFailCallback uintptr 32 //! Size of memory pages. The page size MUST be a power of two. All memory mapping 33 // requests to memory_map will be made with size set to a multiple of the page size. 34 // Used if RPMALLOC_CONFIGURABLE is defined to 1, otherwise system page size is used. 35 PageSize uintptr 36 //! Size of a span of memory blocks. MUST be a power of two, and in [4096,262144] 37 // range (unless 0 - set to 0 to use the default span size). Used if RPMALLOC_CONFIGURABLE 38 // is defined to 1. 39 SpanSize uintptr 40 //! Number of spans to map at each request to map new virtual memory blocks. This can 41 // be used to minimize the system libfuzzerCall overhead at the cost of virtual memory address 42 // space. The extra mapped pages will not be written until actually used, so physical 43 // committed memory should not be affected in the default implementation. Will be 44 // aligned to a multiple of spans that match memory page size in case of huge pages. 45 SpanMapCount uintptr 46 //! Enable use of large/huge pages. If this flag is set to non-zero and page size is 47 // zero, the allocator will try to enable huge pages and auto detect the configuration. 48 // If this is set to non-zero and page_size is also non-zero, the allocator will 49 // assume huge pages have been configured and enabled prior to initializing the 50 // allocator. 51 // For Windows, see https://docs.microsoft.com/en-us/windows/desktop/memory/large-page-support 52 // For Linux, see https://www.kernel.org/doc/Documentation/vm/hugetlbpage.txt 53 EnableHugePages int32 54 Unused int32 55 } 56 57 type GlobalStats struct { 58 //! Current amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1) 59 Mapped uintptr 60 //! Peak amount of virtual memory mapped, all of which might not have been committed (only if ENABLE_STATISTICS=1) 61 MappedPeak uintptr 62 //! Current amount of memory in global caches for small and medium sizes (<32KiB) 63 Cached uintptr 64 //! Current amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1) 65 HugeAlloc uintptr 66 //! Peak amount of memory allocated in huge allocations, i.e larger than LARGE_SIZE_LIMIT which is 2MiB by default (only if ENABLE_STATISTICS=1) 67 HugeAllocPeak uintptr 68 //! Total amount of memory mapped since initialization (only if ENABLE_STATISTICS=1) 69 MappedTotal uintptr 70 //! Total amount of memory unmapped since initialization (only if ENABLE_STATISTICS=1) 71 UnmappedTotal uintptr 72 } 73 74 type ThreadStats struct { 75 //! Current number of bytes available in thread size class caches for small and medium sizes (<32KiB) 76 SizeCache uintptr 77 //! Current number of bytes available in thread span caches for small and medium sizes (<32KiB) 78 SpanCache uintptr 79 //! Total number of bytes transitioned from thread cache to global cache (only if ENABLE_STATISTICS=1) 80 ThreadToGlobal uintptr 81 //! Total number of bytes transitioned from global cache to thread cache (only if ENABLE_STATISTICS=1) 82 GlobalToThread uintptr 83 //! Per span count statistics (only if ENABLE_STATISTICS=1) 84 SpanUse [64]SpanStats 85 //! Per size class statistics (only if ENABLE_STATISTICS=1) 86 SizeUse [128]SizeUse 87 } 88 89 type SpanStats struct { 90 //! Currently used number of spans 91 Current uintptr 92 //! High water mark of spans used 93 Peak uintptr 94 //! Number of spans transitioned to global cache 95 ToGlobal uintptr 96 //! Number of spans transitioned from global cache 97 FromGlobal uintptr 98 //! Number of spans transitioned to thread cache 99 ToCache uintptr 100 //! Number of spans transitioned from thread cache 101 FromCache uintptr 102 //! Number of spans transitioned to reserved state 103 ToReserved uintptr 104 //! Number of spans transitioned from reserved state 105 FromReserved uintptr 106 //! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls) 107 MapCalls uintptr 108 } 109 110 type SizeUse struct { 111 //! Current number of allocations 112 AllocCurrent uintptr 113 //! Peak number of allocations 114 AllocPeak uintptr 115 //! Total number of allocations 116 AllocTotal uintptr 117 //! Total number of frees 118 FreeTotal uintptr 119 //! Number of spans transitioned to cache 120 SpansToCache uintptr 121 //! Number of spans transitioned from cache 122 SpansFromCache uintptr 123 //! Number of spans transitioned from reserved state 124 SpansFromReserved uintptr 125 //! Number of raw memory map calls (not hitting the reserve spans but resulting in actual OS mmap calls) 126 MapCalls uintptr 127 }