|
@@ -1,863 +0,0 @@
|
|
-#include "page.h"
|
|
|
|
-#include "shm_helper.h"
|
|
|
|
-#include "size_map.h"
|
|
|
|
-#include "shm_config.h"
|
|
|
|
-namespace bg
|
|
|
|
-{
|
|
|
|
- namespace detail
|
|
|
|
- {
|
|
|
|
- PageHeap::PageHeap()
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void PageHeap::DeallocateSpan(bg::detail::Span* s)
|
|
|
|
- {
|
|
|
|
- size_t m_start_page; // r12
|
|
|
|
- size_t m_page_count; // r14
|
|
|
|
- bg::detail::RadixTree<10ul, 10ul, 15ul>::NodeV1* v6; // rax
|
|
|
|
- bg::detail::RadixTree<10ul, 10ul, 15ul>::NodeV2* v7; // rax
|
|
|
|
- void** v8; // rdx
|
|
|
|
- size_t v9; // rax
|
|
|
|
- size_t v10; // rcx
|
|
|
|
- uintptr_t* v11; // rdi
|
|
|
|
- void* v12; // r8
|
|
|
|
- unsigned __int64 v13; // r12
|
|
|
|
- bg::detail::RadixTree<10ul, 10ul, 15ul>::NodeV1* v14; // rcx
|
|
|
|
- bg::detail::RadixTree<10ul, 10ul, 15ul>::NodeV2* v15; // rdx
|
|
|
|
- void** v16; // rdx
|
|
|
|
- size_t v17; // rax
|
|
|
|
- uintptr_t* v18; // rcx
|
|
|
|
- void* v19; // rsi
|
|
|
|
- size_t v20; // rax
|
|
|
|
- bg::detail::Span* p_m_large_list; // rdx
|
|
|
|
- bg::detail::Span* m_next; // rax
|
|
|
|
-
|
|
|
|
- m_start_page = s->m_start_page;
|
|
|
|
- s->m_in_use = 0;
|
|
|
|
- m_page_count = s->m_page_count;
|
|
|
|
- if(!m_start_page)
|
|
|
|
- goto LABEL_9;
|
|
|
|
- if(m_start_page - 1 > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- goto LABEL_24;
|
|
|
|
- }
|
|
|
|
- v6 = this->m_span_map.lv0[(m_start_page - 1) >> 25];
|
|
|
|
- if(!v6 || (v7 = v6->lv1[((m_start_page - 1) >> 15) & 0x3FF]) == 0LL)
|
|
|
|
- {
|
|
|
|
-LABEL_9:
|
|
|
|
- v9 = s->m_page_count;
|
|
|
|
- goto LABEL_10;
|
|
|
|
- }
|
|
|
|
- v8 = (void**)v7->lv2[((int64_t)m_start_page - 1) & 0x7FFF];
|
|
|
|
- v9 = s->m_page_count;
|
|
|
|
- if(v8 && *(char*)v8 != 1)
|
|
|
|
- {
|
|
|
|
- v10 = m_start_page - (size_t)v8[3];
|
|
|
|
- v11 = (uintptr_t*)v8[4];
|
|
|
|
- v12 = v8[5];
|
|
|
|
- s->m_start_page = v10;
|
|
|
|
- v9 = (size_t)v8[3] + m_page_count;
|
|
|
|
- s->m_page_count = v9;
|
|
|
|
- v11[5] = (uintptr_t)v12;
|
|
|
|
- *((uintptr_t*)v8[5] + 4) = (uintptr_t)v11;
|
|
|
|
- v8[4] = 0LL;
|
|
|
|
- v8[5] = 0LL;
|
|
|
|
- *v8 = this->m_span_allocator.m_free_list;
|
|
|
|
- this->m_span_allocator.m_free_list = v8;
|
|
|
|
- if(v10 <= 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[v10 >> 25]->lv1[(v10 >> 15) & 0x3FF]->lv2[v10 & 0x7FFF] = s;
|
|
|
|
- goto LABEL_10;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-LABEL_24:
|
|
|
|
- v9 = s->m_page_count;
|
|
|
|
- }
|
|
|
|
-LABEL_10:
|
|
|
|
- v13 = m_page_count + m_start_page;
|
|
|
|
- if(v13 <= 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- v14 = this->m_span_map.lv0[v13 >> 25];
|
|
|
|
- if(v14)
|
|
|
|
- {
|
|
|
|
- v15 = v14->lv1[(v13 >> 15) & 0x3FF];
|
|
|
|
- if(v15)
|
|
|
|
- {
|
|
|
|
- v16 = (void**)v15->lv2[v13 & 0x7FFF];
|
|
|
|
- if(v16)
|
|
|
|
- {
|
|
|
|
- if(*(char*)v16 != 1)
|
|
|
|
- {
|
|
|
|
- v17 = (size_t)v16[3] + v9;
|
|
|
|
- v18 = (uintptr_t*)v16[4];
|
|
|
|
- v19 = v16[5];
|
|
|
|
- s->m_page_count = v17;
|
|
|
|
- v18[5] = (uintptr_t)v19;
|
|
|
|
- *((uintptr_t*)v16[5] + 4) = (uintptr_t)v18;
|
|
|
|
- v16[4] = 0LL;
|
|
|
|
- v16[5] = 0LL;
|
|
|
|
- *v16 = this->m_span_allocator.m_free_list;
|
|
|
|
- this->m_span_allocator.m_free_list = v16;
|
|
|
|
- if(v17)
|
|
|
|
- {
|
|
|
|
- v20 = v17 + s->m_start_page - 1;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- SHM_ASSERT(m_page_count > 0);
|
|
|
|
- v20 = s->m_start_page;
|
|
|
|
- }
|
|
|
|
- if(v20 > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- this->m_span_map.lv0[v20 >> 25]->lv1[(v20 >> 15) & 0x3FF]->lv2[v20 & 0x7FFF] = s;
|
|
|
|
- v9 = s->m_page_count;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- p_m_large_list = &this->m_large_list;
|
|
|
|
- if(v9 <= 0x7F)
|
|
|
|
- p_m_large_list = &this->m_free_lists[v9];
|
|
|
|
- m_next = p_m_large_list->m_next;
|
|
|
|
- s->m_prev = p_m_large_list;
|
|
|
|
- s->m_next = m_next;
|
|
|
|
- p_m_large_list->m_next->m_prev = s;
|
|
|
|
- p_m_large_list->m_next = s;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- void PageHeap::RegisterSpan(bg::detail::Span* s)
|
|
|
|
- {
|
|
|
|
- int64_t v2; // rbx
|
|
|
|
- size_t v3; // r13
|
|
|
|
- size_t v4; // rax
|
|
|
|
-
|
|
|
|
- v2 = 1LL;
|
|
|
|
- v3 = s->m_page_count - 1;
|
|
|
|
- if(v3 > 1)
|
|
|
|
- {
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- while(1)
|
|
|
|
- {
|
|
|
|
- v4 = s->m_start_page + v2;
|
|
|
|
- if(v4 > 0x7FFFFFFFFLL)
|
|
|
|
- break;
|
|
|
|
- ++v2;
|
|
|
|
- this->m_span_map.lv0[v4 >> 25]->lv1[(v4 >> 15) & 0x3FF]->lv2[v4 & 0x7FFF] = s;
|
|
|
|
- if(v3 == v2)
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- ++v2;
|
|
|
|
-
|
|
|
|
- } while(v3 != v2);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bool PageHeap::GrowHeap(size_t page_count)
|
|
|
|
- {
|
|
|
|
- __int64 result; // rax
|
|
|
|
- unsigned __int64 v3; // rdx
|
|
|
|
- const char* RawMemory; // r9
|
|
|
|
- size_t m_page_count; // rbx
|
|
|
|
- size_t v8; // r14
|
|
|
|
- unsigned __int64* v9; // r11
|
|
|
|
- unsigned __int64 v10; // r12
|
|
|
|
- __int16 v11; // r10
|
|
|
|
- unsigned __int64 v12; // rdx
|
|
|
|
- __int64 v13; // r10
|
|
|
|
- uintptr_t* v14; // rax
|
|
|
|
- void* v15; // rax
|
|
|
|
- bg::detail::Span* m_free_list; // r12
|
|
|
|
- unsigned __int64 v17; // rax
|
|
|
|
- size_t m_free_left; // rax
|
|
|
|
- bg::detail::Span* v19; // rax
|
|
|
|
- __int64 v20; // rcx
|
|
|
|
- __int64 v21; // [rsp-20h] [rbp-68h]
|
|
|
|
- __int64 v22; // [rsp-20h] [rbp-68h]
|
|
|
|
- unsigned __int64* v23; // [rsp-18h] [rbp-60h]
|
|
|
|
- unsigned __int64* v24; // [rsp-18h] [rbp-60h]
|
|
|
|
- const char* v25; // [rsp-10h] [rbp-58h]
|
|
|
|
- const char* v26; // [rsp-10h] [rbp-58h]
|
|
|
|
- const char* v27; // [rsp-8h] [rbp-50h]
|
|
|
|
- size_t real_bytes; // [rsp+0h] [rbp-48h] BYREF
|
|
|
|
- size_t v29; // [rsp+8h] [rbp-40h] BYREF
|
|
|
|
-
|
|
|
|
- size_t page{};
|
|
|
|
- result = 0LL;
|
|
|
|
- if(page_count > 0x800000000LL)
|
|
|
|
- return false;
|
|
|
|
- if(page_count > 0x7F)
|
|
|
|
- {
|
|
|
|
- real_bytes = PAGES_TO_BYTES(page_count);
|
|
|
|
- RawMemory = (const char*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- (size_t*)&real_bytes,
|
|
|
|
- 0x2000);
|
|
|
|
- if(!RawMemory)
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- real_bytes = 0x100000LL;
|
|
|
|
- RawMemory = (const char*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- &real_bytes, 0x2000);
|
|
|
|
- if(!RawMemory)
|
|
|
|
- {
|
|
|
|
- real_bytes = PAGES_TO_BYTES(page_count);
|
|
|
|
- RawMemory = (const char*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- &real_bytes, 0x2000);
|
|
|
|
- if(!RawMemory)
|
|
|
|
- {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- page = (unsigned __int64)RawMemory >> 13;
|
|
|
|
- m_page_count = BYTES_TO_PAGES(real_bytes);
|
|
|
|
- v8 = ((unsigned __int64)RawMemory >> 13) + (real_bytes >> 13);
|
|
|
|
- if(page >= v8)
|
|
|
|
- {
|
|
|
|
-LABEL_23:
|
|
|
|
- m_free_list = (bg::detail::Span*)this->m_span_allocator.m_free_list;
|
|
|
|
- if(m_free_list)
|
|
|
|
- {
|
|
|
|
-LABEL_25:
|
|
|
|
- new (m_free_list) bg::detail::Span();
|
|
|
|
- m_free_list->m_page_count = m_page_count;
|
|
|
|
- m_free_list->m_start_page = page;
|
|
|
|
-
|
|
|
|
- if(page > ShmConfig::MAX_PAGE_COUNT)
|
|
|
|
- {
|
|
|
|
- SHM_ASSERT(page < ShmConfig::MAX_PAGE_COUNT);
|
|
|
|
- m_page_count = m_free_list->m_page_count;
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[PTR_TO_LV0(page)]->lv1[PTR_TO_LV1(page)]->lv2[PTR_TO_LV0(page)] = m_free_list;
|
|
|
|
- }
|
|
|
|
- if(m_page_count > 1)
|
|
|
|
- {
|
|
|
|
- page = m_page_count + m_free_list->m_start_page - 1;
|
|
|
|
- if(page > ShmConfig::MAX_PAGE_COUNT)
|
|
|
|
- {
|
|
|
|
- SHM_ASSERT(page < ShmConfig::MAX_PAGE_COUNT);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[PTR_TO_LV0(page)]->lv1[PTR_TO_LV1(page)]->lv2[PTR_TO_LV0(page)] = m_free_list;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- m_free_list->m_in_use = 1;
|
|
|
|
- this->DeallocateSpan(m_free_list);
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- m_free_left = this->m_span_allocator.m_free_left;
|
|
|
|
- if(m_free_left <= 0x37)
|
|
|
|
- {
|
|
|
|
- v27 = RawMemory;
|
|
|
|
- v29 = 0x20000LL;
|
|
|
|
- v19 = (bg::detail::Span*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- &v29,
|
|
|
|
- 0x20000LL);
|
|
|
|
-
|
|
|
|
- if(v19)
|
|
|
|
- {
|
|
|
|
- v20 = v29;
|
|
|
|
- m_free_list = v19;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&v19[1];
|
|
|
|
- this->m_span_allocator.m_free_left = v20 - 56;
|
|
|
|
- goto LABEL_25;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- m_free_list = (bg::detail::Span*)this->m_span_allocator.m_free_area;
|
|
|
|
- this->m_span_allocator.m_free_left = m_free_left - 56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&m_free_list[1];
|
|
|
|
- if(m_free_list)
|
|
|
|
- goto LABEL_25;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- if((unsigned __int64)RawMemory >> 48)
|
|
|
|
- {
|
|
|
|
- goto FAIL;
|
|
|
|
- }
|
|
|
|
- v3 = (unsigned __int64)RawMemory >> 13;
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- v9 = (unsigned __int64*)&this->m_span_map.lv0[v3 >> 25];
|
|
|
|
- v10 = v3 >> 15;
|
|
|
|
- v11 = v3 >> 15;
|
|
|
|
- v12 = *v9;
|
|
|
|
- v13 = v11 & 0x3FF;
|
|
|
|
- if(m_span_map.lv0[v3 >> 25])
|
|
|
|
- {
|
|
|
|
- if(m_span_map.lv0[v3 >> 25]->lv1[v13])
|
|
|
|
- {
|
|
|
|
- goto LABEL_9;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- v21 = v13;
|
|
|
|
- v23 = v9;
|
|
|
|
- v25 = RawMemory;
|
|
|
|
- v29 = sizeof(RadixTree::NodeV1);
|
|
|
|
- v14 = (uintptr_t*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- &v29, sizeof(RadixTree::NodeV1));
|
|
|
|
- RawMemory = v25;
|
|
|
|
- v9 = v23;
|
|
|
|
- v13 = v21;
|
|
|
|
- if(!v14)
|
|
|
|
- break;
|
|
|
|
- m_span_map.lv0[v3 >> 25] = (RadixTree::NodeV1*)v14;
|
|
|
|
-
|
|
|
|
- new (v14) RadixTree();
|
|
|
|
-
|
|
|
|
- v12 = *v23;
|
|
|
|
- if(m_span_map.lv0[v3 >> 25]->lv1[v21])
|
|
|
|
- goto LABEL_9;
|
|
|
|
- }
|
|
|
|
- v22 = v13;
|
|
|
|
- v24 = v9;
|
|
|
|
- v26 = RawMemory;
|
|
|
|
- v29 = sizeof(RadixTree::NodeV2);
|
|
|
|
- v15 = (void*)bg::detail::ShmAllocateRawMemory(&v29, sizeof(RadixTree::NodeV2));
|
|
|
|
- if(!v15)
|
|
|
|
- break;
|
|
|
|
- m_span_map.lv0[v3 >> 25]->lv1[v22] = (RadixTree::NodeV2*)v15;
|
|
|
|
- new (v15) RadixTree::NodeV2();
|
|
|
|
-
|
|
|
|
-LABEL_9:
|
|
|
|
- v3 = (v10 + 1) << 15;
|
|
|
|
- if(v3 >= v8)
|
|
|
|
- goto LABEL_23;
|
|
|
|
- } while(!(v3 >> 35));
|
|
|
|
-FAIL:
|
|
|
|
- SHM_ERROR("annot allocate enough space in span map, memory(%p, %#lx) leaked.", RawMemory, real_bytes);
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- bg::detail::Span* PageHeap::AllocateSpan(size_t page_count)
|
|
|
|
- {
|
|
|
|
- bg::detail::Span* p_m_large_list; // r12
|
|
|
|
- bg::detail::Span* v4; // rdx
|
|
|
|
- bg::detail::Span* v5; // rax
|
|
|
|
- bg::detail::Span* v6; // rax
|
|
|
|
- bg::detail::Span* v7; // r15
|
|
|
|
- bg::detail::Span* v8; // rbx
|
|
|
|
- size_t v9; // rdx
|
|
|
|
- bg::detail::Span* v10; // rax
|
|
|
|
- size_t v11; // rcx
|
|
|
|
- unsigned __int64 v12; // rcx
|
|
|
|
- bg::detail::Span* m_next; // rbx
|
|
|
|
- bg::detail::Span* m_prev; // rax
|
|
|
|
- size_t m_page_count; // r12
|
|
|
|
- unsigned __int64 v17; // r12
|
|
|
|
- bg::detail::Span* v18; // rdx
|
|
|
|
- bg::detail::Span* v19; // rax
|
|
|
|
- bg::detail::Span* v20; // rax
|
|
|
|
- bg::detail::Span* v21; // rax
|
|
|
|
- size_t v22; // r12
|
|
|
|
- unsigned __int64 v23; // r12
|
|
|
|
- bg::detail::Span* m_free_area; // r10
|
|
|
|
- unsigned __int64 v25; // rdx
|
|
|
|
- unsigned __int64 v26; // rax
|
|
|
|
- bg::detail::Span* v27; // rax
|
|
|
|
- size_t v28; // rax
|
|
|
|
- bg::detail::Span* v29; // rax
|
|
|
|
- size_t v30; // r12
|
|
|
|
- unsigned __int64 v31; // r12
|
|
|
|
- bg::detail::Span* m_free_list; // r15
|
|
|
|
- unsigned __int64 m_start_page; // rdx
|
|
|
|
- unsigned __int64 v34; // rax
|
|
|
|
- bg::detail::Span* v35; // rax
|
|
|
|
- bg::detail::Span* v36; // rdx
|
|
|
|
- size_t v37; // rax
|
|
|
|
- bg::detail::Span* v38; // r12
|
|
|
|
- unsigned __int64 v39; // rdx
|
|
|
|
- unsigned __int64 v40; // rax
|
|
|
|
- bg::detail::Span* v41; // rax
|
|
|
|
- size_t v42; // rax
|
|
|
|
- unsigned __int64 v43; // rdx
|
|
|
|
- unsigned __int64 v44; // rax
|
|
|
|
- size_t v45; // rax
|
|
|
|
- size_t m_free_left; // rax
|
|
|
|
- size_t v47; // rax
|
|
|
|
- size_t v48; // rax
|
|
|
|
- bg::detail::Span* RawMemory; // rax
|
|
|
|
- __int64 v50; // rsi
|
|
|
|
- bg::detail::Span* v51; // rax
|
|
|
|
- bg::detail::Span* v52; // rax
|
|
|
|
- __int64 v53; // rsi
|
|
|
|
- bg::detail::Span* v54; // rax
|
|
|
|
- __int64 v55; // rsi
|
|
|
|
- unsigned __int64 v56; // [rsp+0h] [rbp-50h]
|
|
|
|
- bg::detail::Span* v57; // [rsp+8h] [rbp-48h]
|
|
|
|
- unsigned __int64 v58; // [rsp+8h] [rbp-48h]
|
|
|
|
- unsigned __int64 v59; // [rsp+8h] [rbp-48h]
|
|
|
|
- unsigned __int64 v60; // [rsp+8h] [rbp-48h]
|
|
|
|
- bg::detail::Span* v61; // [rsp+8h] [rbp-48h]
|
|
|
|
- bg::detail::Span* v62; // [rsp+8h] [rbp-48h]
|
|
|
|
- unsigned __int64 v63; // [rsp+8h] [rbp-48h]
|
|
|
|
- bg::detail::Span* v64; // [rsp+8h] [rbp-48h]
|
|
|
|
- __int64 v65[7]; // [rsp+18h] [rbp-38h] BYREF
|
|
|
|
-
|
|
|
|
- p_m_large_list = &this->m_large_list;
|
|
|
|
- if(page_count <= 0x7F)
|
|
|
|
- {
|
|
|
|
- v4 = &this->m_free_lists[page_count];
|
|
|
|
- if(v4 == this->m_free_lists[page_count].m_next)
|
|
|
|
- {
|
|
|
|
- p_m_large_list = &this->m_large_list;
|
|
|
|
- v5 = &this->m_free_lists[page_count + 1];
|
|
|
|
- while(v5 != p_m_large_list)
|
|
|
|
- {
|
|
|
|
- v4 = v5++;
|
|
|
|
- if(v4 != v5[-1].m_next)
|
|
|
|
- goto LABEL_19;
|
|
|
|
- }
|
|
|
|
- goto LABEL_6;
|
|
|
|
- }
|
|
|
|
-LABEL_19:
|
|
|
|
- m_next = v4->m_next;
|
|
|
|
- m_prev = m_next->m_prev;
|
|
|
|
- m_page_count = m_next->m_page_count;
|
|
|
|
- m_prev->m_next = m_next->m_next;
|
|
|
|
- v17 = m_page_count - page_count;
|
|
|
|
- m_next->m_next->m_prev = m_prev;
|
|
|
|
- m_next->m_prev = 0LL;
|
|
|
|
- m_next->m_next = 0LL;
|
|
|
|
- if(!v17)
|
|
|
|
- {
|
|
|
|
-LABEL_20:
|
|
|
|
- m_next->m_in_use = 1;
|
|
|
|
- return m_next;
|
|
|
|
- }
|
|
|
|
- m_free_list = (bg::detail::Span*)this->m_span_allocator.m_free_list;
|
|
|
|
- m_start_page = m_next->m_start_page;
|
|
|
|
- if(m_free_list)
|
|
|
|
- {
|
|
|
|
- this->m_span_allocator.m_free_list = *(void**)&m_free_list->m_in_use;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- m_free_left = this->m_span_allocator.m_free_left;
|
|
|
|
- if(m_free_left <= 0x37)
|
|
|
|
- {
|
|
|
|
- v58 = m_next->m_start_page;
|
|
|
|
- v65[0] = 0x20000LL;
|
|
|
|
- RawMemory = (bg::detail::Span*)bg::detail::ShmAllocateRawMemory((size_t*)v65,
|
|
|
|
- 0x20000LL);
|
|
|
|
- if(!RawMemory)
|
|
|
|
- goto LABEL_20;
|
|
|
|
- v50 = v65[0];
|
|
|
|
- m_free_list = RawMemory;
|
|
|
|
- m_start_page = v58;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&RawMemory[1];
|
|
|
|
- this->m_span_allocator.m_free_left = v50 - 56;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- m_free_list = (bg::detail::Span*)this->m_span_allocator.m_free_area;
|
|
|
|
- this->m_span_allocator.m_free_left = m_free_left - 56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&m_free_list[1];
|
|
|
|
- if(!m_free_list)
|
|
|
|
- goto LABEL_20;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- m_free_list->m_in_use = 0;
|
|
|
|
- m_free_list->m_size_class = -1;
|
|
|
|
- m_free_list->m_used_count = 0LL;
|
|
|
|
- m_free_list->m_start_page = m_start_page + page_count;
|
|
|
|
- m_free_list->m_page_count = v17;
|
|
|
|
- m_free_list->m_prev = 0LL;
|
|
|
|
- m_free_list->m_next = 0LL;
|
|
|
|
- m_free_list->m_chunk_list = 0LL;
|
|
|
|
- if(m_start_page + page_count > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- v17 = m_free_list->m_page_count;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[(m_start_page + page_count) >> 25]->lv1[((m_start_page + page_count) >> 15) & 0x3FF]->lv2[(m_start_page + page_count) & 0x7FFF] = m_free_list;
|
|
|
|
- }
|
|
|
|
- if(v17 <= 1
|
|
|
|
- || ((v34 = v17 + m_free_list->m_start_page - 1, v34 > 0x7FFFFFFFFLL)
|
|
|
|
- ? (bg::detail::Span*)(
|
|
|
|
- v17 = m_free_list->m_page_count)
|
|
|
|
- : (this->m_span_map.lv0[v34 >> 25]->lv1[((v17 + m_free_list->m_start_page - 1) >> 15) & 0x3FF]->lv2[v34 & 0x7FFF] = m_free_list),
|
|
|
|
- v35 = &this->m_large_list,
|
|
|
|
- v17 <= 0x7F))
|
|
|
|
- {
|
|
|
|
- v35 = &this->m_free_lists[v17];
|
|
|
|
- }
|
|
|
|
- v36 = v35->m_next;
|
|
|
|
- m_free_list->m_prev = v35;
|
|
|
|
- m_free_list->m_next = v36;
|
|
|
|
- v35->m_next->m_prev = m_free_list;
|
|
|
|
- v35->m_next = m_free_list;
|
|
|
|
- m_next->m_page_count = page_count;
|
|
|
|
- if(page_count)
|
|
|
|
- {
|
|
|
|
- v37 = page_count + m_next->m_start_page - 1;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- v37 = m_next->m_start_page;
|
|
|
|
- }
|
|
|
|
- if(v37 > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- this->m_span_map.lv0[v37 >> 25]->lv1[(v37 >> 15) & 0x3FF]->lv2[v37 & 0x7FFF] = m_next;
|
|
|
|
- goto LABEL_20;
|
|
|
|
- }
|
|
|
|
-LABEL_6:
|
|
|
|
- v6 = this->m_large_list.m_next;
|
|
|
|
- v7 = p_m_large_list;
|
|
|
|
- if(v6 == p_m_large_list)
|
|
|
|
- goto LABEL_23;
|
|
|
|
- v8 = 0LL;
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- while(1)
|
|
|
|
- {
|
|
|
|
- v9 = v6->m_page_count;
|
|
|
|
- if(page_count <= v9)
|
|
|
|
- {
|
|
|
|
- if(!v8 || v9 < v8->m_page_count)
|
|
|
|
- {
|
|
|
|
- v8 = v6;
|
|
|
|
- goto LABEL_14;
|
|
|
|
- }
|
|
|
|
- if(v9 == v8->m_page_count && v6->m_start_page < v8->m_start_page)
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
- v6 = v6->m_next;
|
|
|
|
- if(p_m_large_list == v6)
|
|
|
|
- goto LABEL_15;
|
|
|
|
- }
|
|
|
|
- v8 = v6;
|
|
|
|
-LABEL_14:
|
|
|
|
- v6 = v6->m_next;
|
|
|
|
- } while(p_m_large_list != v6);
|
|
|
|
-LABEL_15:
|
|
|
|
- if(!v8)
|
|
|
|
- {
|
|
|
|
-LABEL_23:
|
|
|
|
- if(!bg::detail::PageHeap::GrowHeap(page_count))
|
|
|
|
- {
|
|
|
|
-LABEL_24:
|
|
|
|
- return 0LL;
|
|
|
|
- }
|
|
|
|
- if(page_count <= 0x7F)
|
|
|
|
- {
|
|
|
|
- v18 = &this->m_free_lists[page_count];
|
|
|
|
- if(v18 != this->m_free_lists[page_count].m_next)
|
|
|
|
- {
|
|
|
|
-LABEL_51:
|
|
|
|
- v8 = v18->m_next;
|
|
|
|
- v29 = v8->m_prev;
|
|
|
|
- v30 = v8->m_page_count;
|
|
|
|
- v29->m_next = v8->m_next;
|
|
|
|
- v31 = v30 - page_count;
|
|
|
|
- v8->m_next->m_prev = v29;
|
|
|
|
- v8->m_prev = 0LL;
|
|
|
|
- v8->m_next = 0LL;
|
|
|
|
- if(v31)
|
|
|
|
- {
|
|
|
|
- m_free_area = (bg::detail::Span*)this->m_span_allocator.m_free_list;
|
|
|
|
- v43 = v8->m_start_page;
|
|
|
|
- if(m_free_area)
|
|
|
|
- {
|
|
|
|
- this->m_span_allocator.m_free_list = *(void**)&m_free_area->m_in_use;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- v48 = this->m_span_allocator.m_free_left;
|
|
|
|
- if(v48 <= 0x37)
|
|
|
|
- {
|
|
|
|
- v60 = v8->m_start_page;
|
|
|
|
- v65[0] = 0x20000LL;
|
|
|
|
- v52 = (bg::detail::Span*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- (size_t*)v65,
|
|
|
|
- v43);
|
|
|
|
- if(!v52)
|
|
|
|
- goto LABEL_52;
|
|
|
|
- v53 = v65[0];
|
|
|
|
- m_free_area = v52;
|
|
|
|
- v43 = v60;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&v52[1];
|
|
|
|
- this->m_span_allocator.m_free_left = v53 - 56;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- m_free_area = (bg::detail::Span*)this->m_span_allocator.m_free_area;
|
|
|
|
- this->m_span_allocator.m_free_left = v48 - 56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&m_free_area[1];
|
|
|
|
- if(!m_free_area)
|
|
|
|
- goto LABEL_52;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- m_free_area->m_in_use = 0;
|
|
|
|
- m_free_area->m_size_class = -1;
|
|
|
|
- m_free_area->m_used_count = 0LL;
|
|
|
|
- m_free_area->m_start_page = v43 + page_count;
|
|
|
|
- m_free_area->m_page_count = v31;
|
|
|
|
- m_free_area->m_prev = 0LL;
|
|
|
|
- m_free_area->m_next = 0LL;
|
|
|
|
- m_free_area->m_chunk_list = 0LL;
|
|
|
|
- if(v43 + page_count > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- v57 = m_free_area;
|
|
|
|
- m_free_area = v57;
|
|
|
|
- v31 = v57->m_page_count;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[(v43 + page_count) >> 25]->lv1[((v43 + page_count) >> 15) & 0x3FF]->lv2[(v43 + page_count) & 0x7FFF] = m_free_area;
|
|
|
|
- }
|
|
|
|
- if(v31 <= 1
|
|
|
|
- || ((v44 = v31 + m_free_area->m_start_page - 1, v44 > 0x7FFFFFFFFLL)
|
|
|
|
- ? (bg::detail::Span*)(v62 = m_free_area,
|
|
|
|
- m_free_area = v62,
|
|
|
|
- v31 = v62->m_page_count)
|
|
|
|
- : (this->m_span_map.lv0[v44 >> 25]->lv1[((v31 + m_free_area->m_start_page - 1) >> 15) & 0x3FF]->lv2[v44 & 0x7FFF] = m_free_area),
|
|
|
|
- v31 <= 0x7F))
|
|
|
|
- {
|
|
|
|
- v7 = &this->m_free_lists[v31];
|
|
|
|
- }
|
|
|
|
- goto LABEL_47;
|
|
|
|
- }
|
|
|
|
-LABEL_52:
|
|
|
|
- v8->m_in_use = 1;
|
|
|
|
- return v8;
|
|
|
|
- }
|
|
|
|
- v19 = &this->m_free_lists[page_count + 1];
|
|
|
|
- while(v19 != p_m_large_list)
|
|
|
|
- {
|
|
|
|
- v18 = v19++;
|
|
|
|
- if(v18 != v19[-1].m_next)
|
|
|
|
- goto LABEL_51;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- v20 = this->m_large_list.m_next;
|
|
|
|
- if(p_m_large_list == v20)
|
|
|
|
- goto LABEL_24;
|
|
|
|
- v8 = 0LL;
|
|
|
|
- do
|
|
|
|
- {
|
|
|
|
- while(page_count > v20->m_page_count || v8 && v20->m_start_page >= v8->m_start_page)
|
|
|
|
- {
|
|
|
|
- v20 = v20->m_next;
|
|
|
|
- if(p_m_large_list == v20)
|
|
|
|
- goto LABEL_37;
|
|
|
|
- }
|
|
|
|
- v8 = v20;
|
|
|
|
- v20 = v20->m_next;
|
|
|
|
- } while(p_m_large_list != v20);
|
|
|
|
-LABEL_37:
|
|
|
|
- if(!v8)
|
|
|
|
- goto LABEL_24;
|
|
|
|
- v21 = v8->m_prev;
|
|
|
|
- v22 = v8->m_page_count;
|
|
|
|
- v21->m_next = v8->m_next;
|
|
|
|
- v23 = v22 - page_count;
|
|
|
|
- v8->m_next->m_prev = v21;
|
|
|
|
- v8->m_prev = 0LL;
|
|
|
|
- v8->m_next = 0LL;
|
|
|
|
- if(v23)
|
|
|
|
- {
|
|
|
|
- m_free_area = (bg::detail::Span*)this->m_span_allocator.m_free_list;
|
|
|
|
- v25 = v8->m_start_page;
|
|
|
|
- if(m_free_area)
|
|
|
|
- {
|
|
|
|
- this->m_span_allocator.m_free_list = *(void**)&m_free_area->m_in_use;
|
|
|
|
- goto LABEL_41;
|
|
|
|
- }
|
|
|
|
- v45 = this->m_span_allocator.m_free_left;
|
|
|
|
- if(v45 <= 0x37)
|
|
|
|
- {
|
|
|
|
- v63 = v8->m_start_page;
|
|
|
|
- v65[0] = 0x20000LL;
|
|
|
|
- v54 = (bg::detail::Span*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- (size_t*)v65,
|
|
|
|
- v25);
|
|
|
|
- if(v54)
|
|
|
|
- {
|
|
|
|
- v55 = v65[0];
|
|
|
|
- m_free_area = v54;
|
|
|
|
- v25 = v63;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&v54[1];
|
|
|
|
- this->m_span_allocator.m_free_left = v55 - 56;
|
|
|
|
- goto LABEL_41;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- m_free_area = (bg::detail::Span*)this->m_span_allocator.m_free_area;
|
|
|
|
- this->m_span_allocator.m_free_left = v45 - 56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&m_free_area[1];
|
|
|
|
- if(m_free_area)
|
|
|
|
- {
|
|
|
|
-LABEL_41:
|
|
|
|
- m_free_area->m_in_use = 0;
|
|
|
|
- m_free_area->m_size_class = -1;
|
|
|
|
- m_free_area->m_used_count = 0LL;
|
|
|
|
- m_free_area->m_start_page = v25 + page_count;
|
|
|
|
- m_free_area->m_page_count = v23;
|
|
|
|
- m_free_area->m_prev = 0LL;
|
|
|
|
- m_free_area->m_next = 0LL;
|
|
|
|
- m_free_area->m_chunk_list = 0LL;
|
|
|
|
- if(v25 + page_count > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- v61 = m_free_area;
|
|
|
|
- m_free_area = v61;
|
|
|
|
- v23 = v61->m_page_count;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[(v25 + page_count) >> 25]->lv1[((v25 + page_count) >> 15) & 0x3FF]->lv2[(v25 + page_count) & 0x7FFF] = m_free_area;
|
|
|
|
- }
|
|
|
|
- if(v23 <= 1
|
|
|
|
- || ((v26 = v23 + m_free_area->m_start_page - 1, v26 > 0x7FFFFFFFFLL)
|
|
|
|
- ? (bg::detail::Span*)(v64 = m_free_area,
|
|
|
|
- m_free_area = v64,
|
|
|
|
- v23 = v64->m_page_count)
|
|
|
|
- : (this->m_span_map.lv0[v26 >> 25]->lv1[((v23 + m_free_area->m_start_page - 1) >> 15) & 0x3FF]->lv2[v26 & 0x7FFF] = m_free_area),
|
|
|
|
- v23 <= 0x7F))
|
|
|
|
- {
|
|
|
|
- v7 = &this->m_free_lists[v23];
|
|
|
|
- }
|
|
|
|
-LABEL_47:
|
|
|
|
- v27 = v7->m_next;
|
|
|
|
- m_free_area->m_prev = v7;
|
|
|
|
- m_free_area->m_next = v27;
|
|
|
|
- v7->m_next->m_prev = m_free_area;
|
|
|
|
- v7->m_next = m_free_area;
|
|
|
|
- v8->m_page_count = page_count;
|
|
|
|
- if(page_count)
|
|
|
|
- {
|
|
|
|
- v28 = page_count + v8->m_start_page - 1;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- v28 = v8->m_start_page;
|
|
|
|
- }
|
|
|
|
- if(v28 > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- this->m_span_map.lv0[v28 >> 25]->lv1[(v28 >> 15) & 0x3FF]->lv2[v28 & 0x7FFF] = v8;
|
|
|
|
- goto LABEL_52;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- goto LABEL_52;
|
|
|
|
- }
|
|
|
|
- v10 = v8->m_prev;
|
|
|
|
- v11 = v8->m_page_count;
|
|
|
|
- v10->m_next = v8->m_next;
|
|
|
|
- v12 = v11 - page_count;
|
|
|
|
- v8->m_next->m_prev = v10;
|
|
|
|
- v8->m_prev = 0LL;
|
|
|
|
- v8->m_next = 0LL;
|
|
|
|
- if(!v12)
|
|
|
|
- goto LABEL_17;
|
|
|
|
- v38 = (bg::detail::Span*)this->m_span_allocator.m_free_list;
|
|
|
|
- v39 = v8->m_start_page;
|
|
|
|
- if(v38)
|
|
|
|
- {
|
|
|
|
- this->m_span_allocator.m_free_list = *(void**)&v38->m_in_use;
|
|
|
|
- goto LABEL_69;
|
|
|
|
- }
|
|
|
|
- v47 = this->m_span_allocator.m_free_left;
|
|
|
|
- if(v47 <= 0x37)
|
|
|
|
- {
|
|
|
|
- v56 = v8->m_start_page;
|
|
|
|
- v59 = v12;
|
|
|
|
- v65[0] = 0x20000LL;
|
|
|
|
- v51 = (bg::detail::Span*)bg::detail::ShmAllocateRawMemory(
|
|
|
|
- (size_t*)v65,
|
|
|
|
- v39);
|
|
|
|
- if(v51)
|
|
|
|
- {
|
|
|
|
- v38 = v51;
|
|
|
|
- v12 = v59;
|
|
|
|
- v39 = v56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&v51[1];
|
|
|
|
- this->m_span_allocator.m_free_left = v65[0] - 56;
|
|
|
|
- goto LABEL_69;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- v38 = (bg::detail::Span*)this->m_span_allocator.m_free_area;
|
|
|
|
- this->m_span_allocator.m_free_left = v47 - 56;
|
|
|
|
- this->m_span_allocator.m_free_area = (char*)&v38[1];
|
|
|
|
- if(v38)
|
|
|
|
- {
|
|
|
|
-LABEL_69:
|
|
|
|
- v38->m_in_use = 0;
|
|
|
|
- v38->m_size_class = -1;
|
|
|
|
- v38->m_used_count = 0LL;
|
|
|
|
- v38->m_start_page = v39 + page_count;
|
|
|
|
- v38->m_page_count = v12;
|
|
|
|
- v38->m_prev = 0LL;
|
|
|
|
- v38->m_next = 0LL;
|
|
|
|
- v38->m_chunk_list = 0LL;
|
|
|
|
- if(v39 + page_count > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- v12 = v38->m_page_count;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- this->m_span_map.lv0[(v39 + page_count) >> 25]->lv1[((v39 + page_count) >> 15) & 0x3FF]->lv2[(v39 + page_count) & 0x7FFF] = v38;
|
|
|
|
- }
|
|
|
|
- if(v12 <= 1
|
|
|
|
- || ((v40 = v12 + v38->m_start_page - 1, v40 > 0x7FFFFFFFFLL)
|
|
|
|
- ? (bg::detail::Span*)(
|
|
|
|
- v12 = v38->m_page_count)
|
|
|
|
- : (this->m_span_map.lv0[v40 >> 25]->lv1[((v12 + v38->m_start_page - 1) >> 15) & 0x3FF]->lv2[v40 & 0x7FFF] = v38),
|
|
|
|
- v12 <= 0x7F))
|
|
|
|
- {
|
|
|
|
- v7 = &this->m_free_lists[v12];
|
|
|
|
- }
|
|
|
|
- v41 = v7->m_next;
|
|
|
|
- v38->m_prev = v7;
|
|
|
|
- v38->m_next = v41;
|
|
|
|
- v7->m_next->m_prev = v38;
|
|
|
|
- v7->m_next = v38;
|
|
|
|
- v8->m_page_count = page_count;
|
|
|
|
- if(page_count)
|
|
|
|
- {
|
|
|
|
- v42 = page_count + v8->m_start_page - 1;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- v42 = v8->m_start_page;
|
|
|
|
- }
|
|
|
|
- if(v42 > 0x7FFFFFFFFLL)
|
|
|
|
- {
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- this->m_span_map.lv0[v42 >> 25]->lv1[(v42 >> 15) & 0x3FF]->lv2[v42 & 0x7FFF] = v8;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-LABEL_17:
|
|
|
|
- v8->m_in_use = 1;
|
|
|
|
- return v8;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|