Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
sysio::chain::eosvmoc::compile_monitor_session Struct Reference

Public Member Functions

 compile_monitor_session (boost::asio::io_context &context, local::datagram_protocol::socket &&n, wrapped_fd &&c, wrapped_fd &t)
 
 ~compile_monitor_session ()
 
void read_message_from_nodeop ()
 
void kick_compile_off (const code_tuple &code_id, wrapped_fd &&wasm_code)
 
void read_message_from_compile_task (std::list< std::tuple< code_tuple, local::datagram_protocol::socket > >::iterator current_compile_it)
 

Public Attributes

boost::signals2::signal< void()> connection_dead_signal
 

Detailed Description

Definition at line 36 of file compile_monitor.cpp.

Constructor & Destructor Documentation

◆ compile_monitor_session()

sysio::chain::eosvmoc::compile_monitor_session::compile_monitor_session ( boost::asio::io_context & context,
local::datagram_protocol::socket && n,
wrapped_fd && c,
wrapped_fd & t )
inline

Definition at line 37 of file compile_monitor.cpp.

37 :
38 _ctx(context),
39 _nodeop_instance_socket(std::move(n)),
40 _cache_fd(std::move(c)),
41 _trampoline_socket(t) {
42
43 struct stat st;
44 FC_ASSERT(fstat(_cache_fd, &st) == 0, "failed to stat cache fd");
45 _code_size = st.st_size;
46 _code_mapping = (char*)mmap(nullptr, _code_size, PROT_READ|PROT_WRITE, MAP_SHARED, _cache_fd, 0);
47 FC_ASSERT(_code_mapping != MAP_FAILED, "failed to mmap cache file");
48 _allocator = reinterpret_cast<allocator_t*>(_code_mapping);
49
51 }
#define FC_ASSERT(TEST,...)
Checks a condition and throws an assert_exception if the test is FALSE.
bip::rbtree_best_fit< bip::null_mutex_family, bip::offset_ptr< void >, alignof(std::max_align_t)> allocator_t
Here is the call graph for this function:

◆ ~compile_monitor_session()

sysio::chain::eosvmoc::compile_monitor_session::~compile_monitor_session ( )
inline

Definition at line 53 of file compile_monitor.cpp.

53 {
54 munmap(_code_mapping, _code_size);
55 }

Member Function Documentation

◆ kick_compile_off()

void sysio::chain::eosvmoc::compile_monitor_session::kick_compile_off ( const code_tuple & code_id,
wrapped_fd && wasm_code )
inline

Definition at line 93 of file compile_monitor.cpp.

93 {
94 //prepare a requst to go out to the trampoline
95 int socks[2];
96 socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, socks);
97 local::datagram_protocol::socket response_socket(_ctx);
98 response_socket.assign(local::datagram_protocol(), socks[0]);
99 std::vector<wrapped_fd> fds_pass_to_trampoline;
100 fds_pass_to_trampoline.emplace_back(socks[1]);
101 fds_pass_to_trampoline.emplace_back(std::move(wasm_code));
102
103 eosvmoc_message trampoline_compile_request = compile_wasm_message{code_id};
104 if(write_message_with_fds(_trampoline_socket, trampoline_compile_request, fds_pass_to_trampoline) == false) {
105 wasm_compilation_result_message reply{code_id, compilation_result_unknownfailure{}, _allocator->get_free_memory()};
106 write_message_with_fds(_nodeop_instance_socket, reply);
107 return;
108 }
109
110 current_compiles.emplace_front(code_id, std::move(response_socket));
111 read_message_from_compile_task(current_compiles.begin());
112 }
bool write_message_with_fds(boost::asio::local::datagram_protocol::socket &s, const eosvmoc_message &message, const std::vector< wrapped_fd > &fds=std::vector< wrapped_fd >())
std::variant< initialize_message, initalize_response_message, compile_wasm_message, evict_wasms_message, code_compilation_result_message, wasm_compilation_result_message > eosvmoc_message
void read_message_from_compile_task(std::list< std::tuple< code_tuple, local::datagram_protocol::socket > >::iterator current_compile_it)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_message_from_compile_task()

void sysio::chain::eosvmoc::compile_monitor_session::read_message_from_compile_task ( std::list< std::tuple< code_tuple, local::datagram_protocol::socket > >::iterator current_compile_it)
inline

Definition at line 114 of file compile_monitor.cpp.

114 {
115 auto& [code, socket] = *current_compile_it;
116 socket.async_wait(local::datagram_protocol::socket::wait_read, [this, current_compile_it](auto ec) {
117 //at this point we only expect 1 of 2 things to happen: we either get a reply (success), or we get no reply (failure)
118 auto& [code, socket] = *current_compile_it;
119 auto [success, message, fds] = read_message_with_fds(socket);
120
121 wasm_compilation_result_message reply{code, compilation_result_unknownfailure{}, _allocator->get_free_memory()};
122
123 void* code_ptr = nullptr;
124 void* mem_ptr = nullptr;
125 try {
126 if(success && std::holds_alternative<code_compilation_result_message>(message) && fds.size() == 2) {
127 code_compilation_result_message& result = std::get<code_compilation_result_message>(message);
128 code_ptr = _allocator->allocate(get_size_of_fd(fds[0]));
129 mem_ptr = _allocator->allocate(get_size_of_fd(fds[1]));
130
131 if(code_ptr == nullptr || mem_ptr == nullptr) {
132 _allocator->deallocate(code_ptr);
133 _allocator->deallocate(mem_ptr);
134 reply.result = compilation_result_toofull();
135 }
136 else {
137 copy_memfd_contents_to_pointer(code_ptr, fds[0]);
138 copy_memfd_contents_to_pointer(mem_ptr, fds[1]);
139
140 reply.result = code_descriptor {
141 code.code_id,
142 code.vm_version,
143 current_codegen_version,
144 (uintptr_t)code_ptr - (uintptr_t)_code_mapping,
145 result.start,
146 result.apply_offset,
147 result.starting_memory_pages,
148 (uintptr_t)mem_ptr - (uintptr_t)_code_mapping,
149 (unsigned)get_size_of_fd(fds[1]),
150 result.initdata_prologue_size
151 };
152 }
153 }
154 }
155 catch(...) {
156 _allocator->deallocate(code_ptr);
157 _allocator->deallocate(mem_ptr);
158 }
159
160 write_message_with_fds(_nodeop_instance_socket, reply);
161
162 //either way, we are done
163 _ctx.post([this, current_compile_it]() {
164 current_compiles.erase(current_compile_it);
165 });
166 });
167
168 }
std::tuple< bool, eosvmoc_message, std::vector< wrapped_fd > > read_message_with_fds(boost::asio::local::datagram_protocol::socket &s)
_W64 unsigned int uintptr_t
Definition stdint.h:165
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_message_from_nodeop()

void sysio::chain::eosvmoc::compile_monitor_session::read_message_from_nodeop ( )
inline

Definition at line 57 of file compile_monitor.cpp.

57 {
58 _nodeop_instance_socket.async_wait(local::datagram_protocol::socket::wait_read, [this](auto ec) {
59 if(ec) {
61 return;
62 }
63 auto [success, message, fds] = read_message_with_fds(_nodeop_instance_socket);
64 if(!success) {
66 return;
67 }
68 std::visit(overloaded {
69 [&, &fds=fds](const compile_wasm_message& compile) {
70 if(fds.size() != 1) {
72 return;
73 }
74 kick_compile_off(compile.code, std::move(fds[0]));
75 },
76 [&](const evict_wasms_message& evict) {
77 for(const code_descriptor& cd : evict.codes) {
78 _allocator->deallocate(_code_mapping + cd.code_begin);
79 _allocator->deallocate(_code_mapping + cd.initdata_begin);
80 }
81 },
82 [&](const auto&) {
83 //anything else is an error
85 return;
86 }
87 }, message);
88
90 });
91 }
overloaded(Ts...) -> overloaded< Ts... >
void kick_compile_off(const code_tuple &code_id, wrapped_fd &&wasm_code)
boost::signals2::signal< void()> connection_dead_signal
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ connection_dead_signal

boost::signals2::signal<void()> sysio::chain::eosvmoc::compile_monitor_session::connection_dead_signal

Definition at line 170 of file compile_monitor.cpp.


The documentation for this struct was generated from the following file: