Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
gs_seg_helpers.c File Reference
#include <sysio/chain/webassembly/sys-vm-oc/gs_seg_helpers.h>
#include <asm/prctl.h>
#include <sys/prctl.h>
#include <sys/mman.h>
Include dependency graph for gs_seg_helpers.c:

Go to the source code of this file.

Macros

#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));
 

Functions

int arch_prctl (int code, unsigned long *addr)
 
int32_t eos_vm_oc_grow_memory (int32_t grow, int32_t max)
 
sigjmp_buf * eos_vm_oc_get_jmp_buf ()
 
void * eos_vm_oc_get_exception_ptr ()
 
void * eos_vm_oc_get_bounce_buffer_list ()
 

Macro Definition Documentation

◆ SYSVMOC_MEMORY_PTR_cb_ptr

#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));

Definition at line 9 of file gs_seg_helpers.c.

Function Documentation

◆ arch_prctl()

int arch_prctl ( int code,
unsigned long * addr )
Here is the caller graph for this function:

◆ eos_vm_oc_get_bounce_buffer_list()

void * eos_vm_oc_get_bounce_buffer_list ( )

Definition at line 63 of file gs_seg_helpers.c.

63 {
65 return cb_ptr->bounce_buffers;
66}
#define SYSVMOC_MEMORY_PTR_cb_ptr

◆ eos_vm_oc_get_exception_ptr()

void * eos_vm_oc_get_exception_ptr ( )

Definition at line 58 of file gs_seg_helpers.c.

58 {
60 return cb_ptr->eptr;
61}
Here is the caller graph for this function:

◆ eos_vm_oc_get_jmp_buf()

sigjmp_buf * eos_vm_oc_get_jmp_buf ( )

Definition at line 53 of file gs_seg_helpers.c.

53 {
55 return cb_ptr->jmp;
56}
Here is the caller graph for this function:

◆ eos_vm_oc_grow_memory()

int32_t eos_vm_oc_grow_memory ( int32_t grow,
int32_t max )

Definition at line 11 of file gs_seg_helpers.c.

11 {
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}
int arch_prctl(int code, unsigned long *addr)
#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)
Here is the call graph for this function: