29 module.userSections.clear();
37 const std::map<unsigned, uintptr_t>& function_to_offsets = code.function_offsets;
41 else if(
module.startFunctionIndex <
module.functions.imports.size()) {
42 const auto&
f =
module.functions.imports[module.startFunctionIndex];
50 if(exprt.
name ==
"apply")
58 std::vector<uint8_t> prologue(
module.globals.defs.size() * 8);
59 std::vector<uint8_t>::iterator prologue_it = prologue.end();
73 global_union*
const u = (global_union*
const)&*prologue_it;
75 switch(
global.initializer.type) {
76 case InitializerExpression::Type::i32_const: u->i32 =
global.initializer.i32;
break;
77 case InitializerExpression::Type::i64_const: u->i64 =
global.initializer.i64;
break;
78 case InitializerExpression::Type::f32_const: u->f32 =
global.initializer.f32;
break;
79 case InitializerExpression::Type::f64_const: u->f64 =
global.initializer.f64;
break;
90 struct table_entry* table_index_0 = (
struct table_entry*)(code.code.data() + code.table_offset);
98 for(
Uptr i = 0; i < table_segment.
indices.size(); ++i) {
99 const Uptr function_index = table_segment.
indices[i];
102 if(effective_table_index >=
module.tables.defs[0].type.size.min)
105 if(function_index <
module.functions.imports.size()) {
106 const auto&
f =
module.functions.imports[function_index];
108 table_index_0[effective_table_index].func = ie.
ordinal*-8;
109 table_index_0[effective_table_index].type = (
uintptr_t)
module.types[
module.functions.imports[function_index].type.index];
112 table_index_0[effective_table_index].func = function_to_offsets.at(function_index -
module.functions.imports.size());
113 table_index_0[effective_table_index].type = (
uintptr_t)
module.types[
module.functions.defs[function_index -
module.functions.imports.size()].type.index];
119 std::vector<uint8_t> initial_mem;
123 if(base_offset + data_segment.
data.size() > initial_mem.size())
124 initial_mem.resize(base_offset + data_segment.
data.size(), 0x00);
125 memcpy(initial_mem.data() + base_offset, data_segment.
data.data(), data_segment.
data.size());
129 std::vector<uint8_t> initdata_prep;
130 std::move(prologue_it, prologue.end(), std::back_inserter(initdata_prep));
131 std::move(initial_mem.begin(), initial_mem.end(), std::back_inserter(initdata_prep));
133 std::vector<wrapped_fd> fds_to_send;
140 prctl(PR_SET_NAME,
"oc-trampoline");
141 prctl(PR_SET_PDEATHSIG, SIGKILL);
144 struct sigaction act;
147 act.sa_handler = SIG_IGN;
149 act.sa_flags = SA_NOCLDWAIT;
150 act.sa_sigaction =
nullptr;
151 sigaction(SIGCHLD, &act,
nullptr);
158 if(!std::holds_alternative<compile_wasm_message>(message) || fds.size() != 2) {
159 std::cerr <<
"SYS VM OC compile trampoline got unexpected message; ignoring" << std::endl;
165 prctl(PR_SET_NAME,
"oc-compile");
166 prctl(PR_SET_PDEATHSIG, SIGKILL);
168 struct rlimit cpu_limits = {20u, 20u};
169 setrlimit(RLIMIT_CPU, &cpu_limits);
171 struct rlimit vm_limits = {512u*1024u*1024u, 512u*1024u*1024u};
172 setrlimit(RLIMIT_AS, &vm_limits);
174 struct rlimit core_limits = {0u, 0u};
175 setrlimit(RLIMIT_CORE, &core_limits);
181 std::cerr <<
"SYS VM OC compile trampoline failed to spawn compile task" << std::endl;