Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gs_seg_helpers.c
Go to the documentation of this file.
2
3#include <asm/prctl.h>
4#include <sys/prctl.h>
5#include <sys/mman.h>
6
7int arch_prctl(int code, unsigned long* addr);
8
9#define SYSVMOC_MEMORY_PTR_cb_ptr GS_PTR struct eos_vm_oc_control_block* const cb_ptr = ((GS_PTR struct eos_vm_oc_control_block* const)(EOS_VM_OC_CONTROL_BLOCK_OFFSET));
10
13 uint64_t previous_page_count = cb_ptr->current_linear_memory_pages;
14 int32_t grow_amount = grow;
15 uint64_t max_pages = max;
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)
21 return (int32_t)-1;
22
23 int64_t max_segments = cb_ptr->execution_thread_memory_length / EOS_VM_OC_MEMORY_STRIDE - 1;
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;
27 int64_t gs_diff;
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
40 uint64_t current_gs;
41 arch_prctl(ARCH_GET_GS, &current_gs);
42 current_gs += gs_diff * EOS_VM_OC_MEMORY_STRIDE;
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}
52
53sigjmp_buf* eos_vm_oc_get_jmp_buf() {
55 return cb_ptr->jmp;
56}
57
60 return cb_ptr->eptr;
61}
62
65 return cb_ptr->bounce_buffers;
66}
sigjmp_buf * eos_vm_oc_get_jmp_buf()
void * eos_vm_oc_get_exception_ptr()
int arch_prctl(int code, unsigned long *addr)
int32_t eos_vm_oc_grow_memory(int32_t grow, int32_t max)
#define SYSVMOC_MEMORY_PTR_cb_ptr
void * eos_vm_oc_get_bounce_buffer_list()
#define EOS_VM_OC_MEMORY_STRIDE
signed __int64 int64_t
Definition stdint.h:135
signed int int32_t
Definition stdint.h:123
unsigned __int64 uint64_t
Definition stdint.h:136
memset(pInfo->slotDescription, ' ', 64)