use
5.008004;
our
$VERSION
=
'0.18'
;
sub
get_virtual_memory_limit
{
my
$ctx
= context();
if
($^O eq
'linux'
)
{
my
$ffi
= FFI::Platypus->new(
api
=> 1,
lib
=> [
undef
] );
my
$rlimit
;
if
(
$ffi
->find_symbol(
'getrlimit'
))
{
$ctx
->note(
"linux : found getrlimit"
)
if
$ENV
{TEST2_PLUGIN_WASM_DEBUG};
$rlimit
= FFI::C::StructDef->new(
$ffi
,
name
=>
'rlimit'
,
members
=> [
rlim_cur
=>
'uint32'
,
rlim_max
=>
'uint32'
,
],
)->create;
my
$ret
=
$ffi
->function(
getrlimit
=> [
'int'
,
'rlimit'
] =>
'int'
)->call(9,
$rlimit
);
if
(
$ret
== -1)
{
$ctx
->note(
"getrlimit failed: $!"
)
if
$ENV
{TEST2_PLUGIN_WASM_DEBUG};
undef
$rlimit
;
}
}
if
(
defined
$rlimit
)
{
my
$cur
=
$rlimit
->rlim_cur;
$ctx
->note(
"rlimit = "
. Data::Dumper->new(
[c_to_perl(
$rlimit
)])->Terse(1)->Indent(0)->Dump
)
if
$ENV
{TEST2_PLUGIN_WASM_DEBUG};
$ctx
->release;
$cur
= 0
if
$cur
== 0xffffffff;
return
$cur
;
}
}
$ctx
->release;
return
undef
;
}
our
$config_mock
;
sub
import
{
my
$ctx
= context();
my
$vm_limit
= get_virtual_memory_limit();
if
(
$vm_limit
)
{
$config_mock
= Test2::Mock->new(
class
=>
'Wasm::Wasmtime::Config'
,
around
=> [
new
=>
sub
{
my
$orig
=
shift
;
my
$self
=
shift
->
$orig
(
@_
);
my
$ctx
= context();
$ctx
->note(
"virtual memory address limit detected, try to set limits to zero"
);
$self
->static_memory_maximum_size(0);
$self
->static_memory_guard_size(0);
$self
->dynamic_memory_guard_size(0);
$ctx
->release;
$self
;
},
],
);
}
$ctx
->release;
}
1;