11 {
13 uint64_t previous_page_count = cb_ptr->current_linear_memory_pages;
16 if(max_pages > cb_ptr->max_linear_memory_pages)
17 max_pages = cb_ptr->max_linear_memory_pages;
18 if(grow == 0)
19 return (
int32_t)cb_ptr->current_linear_memory_pages;
20 if(previous_page_count + grow_amount > max_pages)
22
24 int was_extended = previous_page_count > max_segments;
25 int will_be_extended = previous_page_count + grow_amount > max_segments;
26 char* extended_memory_start = cb_ptr->full_linear_memory_start + max_segments * 64*1024;
28 if(will_be_extended && grow_amount > 0) {
29 uint64_t skip = was_extended ? previous_page_count - max_segments : 0;
30 gs_diff = was_extended ? 0 : max_segments - previous_page_count;
31 mprotect(extended_memory_start + skip * 64*1024, (grow_amount - gs_diff) * 64*1024, PROT_READ | PROT_WRITE);
32 } else if (was_extended && grow_amount < 0) {
33 uint64_t skip = will_be_extended ? previous_page_count + grow_amount - max_segments : 0;
34 gs_diff = will_be_extended ? 0 : previous_page_count + grow_amount - max_segments;
35 mprotect(extended_memory_start + skip * 64*1024, (-grow_amount + gs_diff) * 64*1024, PROT_NONE);
36 } else {
37 gs_diff = grow_amount;
38 }
39
43 arch_prctl(ARCH_SET_GS, (
unsigned long*)current_gs);
44 cb_ptr->current_linear_memory_pages += grow_amount;
45 cb_ptr->first_invalid_memory_address += grow_amount*64*1024;
46
47 if(grow_amount > 0)
48 memset(cb_ptr->full_linear_memory_start + previous_page_count*64u*1024u, 0, grow_amount*64u*1024u);
49
50 return (
int32_t)previous_page_count;
51}
int arch_prctl(int code, unsigned long *addr)
#define EOS_VM_OC_MEMORY_STRIDE
unsigned __int64 uint64_t
memset(pInfo->slotDescription, ' ', 64)