commonlibsse_ng\re\b/
BSSmallBlockAllocator.rs1use crate::re::{BSAtomic::BSCriticalSection, IMemoryStore::IMemoryStore};
2use core::ptr::NonNull;
3
4#[repr(C)]
6#[derive(Debug)]
7pub struct FreeBlock {
8    pub next: *mut FreeBlock, }
10
11const _: () = {
12    assert!(std::mem::size_of::<FreeBlock>() == 0x8);
13};
14
15impl Default for FreeBlock {
16    #[inline]
17    fn default() -> Self {
18        unsafe { core::mem::zeroed() }
19    }
20}
21
22#[repr(C)]
24#[derive(Debug)]
25pub struct BlockPage {
26    pub left: *mut BlockPage,   pub right: *mut BlockPage,  pub blocks: *mut FreeBlock, pub totalElem: u16,         pub freeElem: u16,          pub pad1C: u32,             }
33
34const _: () = {
35    assert!(std::mem::size_of::<BlockPage>() == 0x20);
36};
37
38impl Default for BlockPage {
39    #[inline]
40    fn default() -> Self {
41        unsafe { core::mem::zeroed() }
42    }
43}
44
45#[repr(C)]
47#[derive(Debug, Clone, Copy, PartialEq)]
48pub struct BlockPageInternal {
49    pub left: *mut BlockPageInternal,  pub right: *mut BlockPageInternal, pub blocks: *mut FreeBlock,        pub totalElem: u16,                pub freeElem: u16,                 pub elemSize: u16,                 pub check: u16,                    }
57const _: () = {
58    assert!(std::mem::size_of::<BlockPageInternal>() == 0x20);
59};
60
61impl Default for BlockPageInternal {
62    #[inline]
63    fn default() -> Self {
64        unsafe { core::mem::zeroed() }
65    }
66}
67
68#[repr(C)]
70#[derive(Debug, Clone, PartialEq)]
71pub struct Pool {
72    pub pageList: *mut BlockPage,  pub currAlloc: *mut BlockPage, pub totalFreeBlocks: u32,      pub totalAllocatedBlocks: u32, pub totalBytes: u32,           pub elementSize: u32,          pub lock: BSCriticalSection,   }
80const _: () = {
81    assert!(std::mem::size_of::<Pool>() == 0x48);
82};
83impl Default for Pool {
84    #[inline]
85    fn default() -> Self {
86        unsafe { core::mem::zeroed() }
87    }
88}
89
90#[repr(C)]
92#[derive(Debug)]
93pub struct MegaBlockPage {
94    pub mem: [u8; 0x1FE000],                   pub blockPages: [BlockPageInternal; 255],  pub left: Option<NonNull<MegaBlockPage>>,  pub right: Option<NonNull<MegaBlockPage>>, pub freeBlockPages: *mut BlockPage,        pub numFreeBlockPages: u16,                pub nextBlockPageAlloc: u16,               pub decommitted: bool,                     pub pad1FFFFD: u8,                         pub pad1FFFFE: u16,                        }
105const _: () = {
106    assert!(core::mem::size_of::<MegaBlockPage>() == 0x200000); };
108
109impl MegaBlockPage {
110    #[inline]
112    pub unsafe fn alloc_zeroed() -> Option<NonNull<Self>> {
113        const SELF_ALIGN: usize = core::mem::align_of::<MegaBlockPage>();
114        const SELF_SIZE: usize = core::mem::size_of::<MegaBlockPage>();
115
116        const _: () = {
118            assert!(SELF_ALIGN != 0);
119            assert!(SELF_ALIGN % 2 == 0);
120            assert!(SELF_SIZE <= (isize::MAX as usize));
121        };
122
123        unsafe {
124            let layout = core::alloc::Layout::from_size_align_unchecked(SELF_SIZE, SELF_ALIGN);
125            NonNull::new(std::alloc::alloc_zeroed(layout).cast::<Self>())
126        }
127    }
128}
129
130#[repr(C)]
132#[derive(Debug, Clone, PartialEq)]
133pub struct BSSmallBlockAllocator {
134    pub __base: IMemoryStore,                   pub pools: [Pool; 64],                      pub lock: BSCriticalSection,                pub addressSpaceSize: u32,                  pub pad1234: u32,                           pub allocBase: *mut u8,                     pub blockPageCommitMin: *mut u8,            pub blockPageCommit: *mut u8,               pub megaBlockPageList: *mut MegaBlockPage,  pub megaBlockCurrAlloc: *mut MegaBlockPage, pub totalFreeBlockPages: u32,               pub allowDecommits: bool,                   pub pad1265: u8,                            pub pad1266: u16,                           }
149
150const _: () = {
151    assert!(std::mem::size_of::<BSSmallBlockAllocator>() == 0x1268);
152};
153
154impl Default for BSSmallBlockAllocator {
155    #[inline]
156    fn default() -> Self {
157        unsafe { core::mem::zeroed() }
158    }
159}
160
161#[repr(C)]
163pub struct BSSmallBlockAllocatorVtbl {
164    pub CxxDrop: unsafe extern "C" fn(this: &mut BSSmallBlockAllocator),
166
167    pub Size: unsafe extern "C" fn(this: &BSSmallBlockAllocator, block: *const u8) -> usize,
168    pub GetMemoryStats: unsafe extern "C" fn(this: &BSSmallBlockAllocator, stats: *mut ()) -> (),
169    pub ContainsBlockImpl:
170        unsafe extern "C" fn(this: &BSSmallBlockAllocator, block: *const u8) -> bool,
171    pub AllocateAlignImpl:
172        unsafe extern "C" fn(this: &mut BSSmallBlockAllocator, size: usize, align: u32) -> *mut u8,
173    pub DeallocateAlignImpl:
174        unsafe extern "C" fn(this: &mut BSSmallBlockAllocator, free_block: *mut *mut u8),
175    pub TryAllocateImpl:
176        unsafe extern "C" fn(this: &mut BSSmallBlockAllocator, size: usize, align: u32) -> *mut u8,
177}