Class: Wasmtime::WasiConfig
- Inherits:
-
Object
- Object
- Wasmtime::WasiConfig
- Defined in:
- ext/src/ruby_api/wasi_config.rs
Overview
WASI config to be sent as Store.new’s wasi_config keyword argument.
Instance methods mutate the current object and return self.
Class Method Summary collapse
-
.new ⇒ WasiConfig
Create a new WasiConfig.
Instance Method Summary collapse
-
#add_determinism ⇒ WasiConfig
Use deterministic implementations for clocks and random methods.
-
#allow_ip_name_lookup(enabled) ⇒ WasiConfig
Allow or deny IP name lookup (DNS resolution).
-
#allow_tcp(enabled) ⇒ WasiConfig
Allow or deny TCP socket access.
-
#allow_udp(enabled) ⇒ WasiConfig
Allow or deny UDP socket access.
-
#inherit_network ⇒ WasiConfig
Enable all network access by inheriting the host's network.
-
#inherit_stderr ⇒ WasiConfig
Inherit stderr from the current Ruby process.
-
#inherit_stdin ⇒ WasiConfig
Inherit stdin from the current Ruby process.
-
#inherit_stdout ⇒ WasiConfig
Inherit stdout from the current Ruby process.
-
#set_argv(args) ⇒ WasiConfig
Set the arguments (argv) to the specified
Array. -
#set_env(env) ⇒ WasiConfig
Set env to the specified
Hash. -
#set_mapped_directory(host_path, guest_path, dir_perms, file_perms) ⇒ WasiConfig
Set mapped directory for host path and guest path.
-
#set_stderr_buffer(buffer, capacity) ⇒ WasiConfig
Set stderr to write to a string buffer.
-
#set_stderr_file(path) ⇒ WasiConfig
Set stderr to write to a file.
-
#set_stdin_file(path) ⇒ WasiConfig
Set stdin to read from the specified file.
-
#set_stdin_string(content) ⇒ WasiConfig
Set stdin to the specified String.
-
#set_stdout_buffer(buffer, capacity) ⇒ WasiConfig
Set stdout to write to a string buffer.
-
#set_stdout_file(path) ⇒ WasiConfig
Set stdout to write to a file.
-
#socket_addr_check {|addr, use| ... } ⇒ WasiConfig
Set a custom check function for socket address access control.
Class Method Details
.new ⇒ WasiConfig
Create a new Wasmtime::WasiConfig. By default, it has nothing: no stdin/out/err, no env, no argv, no file access.
269 270 271 |
# File 'ext/src/ruby_api/wasi_config.rs', line 269
pub fn new() -> Self {
Self::default()
}
|
Instance Method Details
#add_determinism ⇒ WasiConfig
Use deterministic implementations for clocks and random methods.
276 277 278 279 280 |
# File 'ext/src/ruby_api/wasi_config.rs', line 276
pub fn add_determinism(rb_self: RbSelf) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.deterministic = true;
rb_self
}
|
#allow_ip_name_lookup(enabled) ⇒ WasiConfig
Allow or deny IP name lookup (DNS resolution).
472 473 474 475 476 |
# File 'ext/src/ruby_api/wasi_config.rs', line 472
pub fn allow_ip_name_lookup(rb_self: RbSelf, enabled: bool) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.allow_ip_name_lookup = Some(enabled);
rb_self
}
|
#allow_tcp(enabled) ⇒ WasiConfig
Allow or deny TCP socket access. Allowed by default, can be used to blanket disable TCP.
450 451 452 453 454 |
# File 'ext/src/ruby_api/wasi_config.rs', line 450
pub fn allow_tcp(rb_self: RbSelf, enabled: bool) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.allow_tcp = Some(enabled);
rb_self
}
|
#allow_udp(enabled) ⇒ WasiConfig
Allow or deny UDP socket access. Allowed by default, can be used to blanket disable UDP.
461 462 463 464 465 |
# File 'ext/src/ruby_api/wasi_config.rs', line 461
pub fn allow_udp(rb_self: RbSelf, enabled: bool) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.allow_udp = Some(enabled);
rb_self
}
|
#inherit_network ⇒ WasiConfig
Enable all network access by inheriting the host's network. This allows the WASI module to use TCP, UDP, and DNS resolution.
Note: any network access happens while the Global VM Lock (GVL) is held, so other threads will be blocked in the meantime.
439 440 441 442 443 |
# File 'ext/src/ruby_api/wasi_config.rs', line 439
pub fn inherit_network(rb_self: RbSelf) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.inherit_network = true;
rb_self
}
|
#inherit_stderr ⇒ WasiConfig
Inherit stderr from the current Ruby process.
351 352 353 354 355 |
# File 'ext/src/ruby_api/wasi_config.rs', line 351
pub fn inherit_stderr(rb_self: RbSelf) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stderr = Some(WriteStream::Inherit);
rb_self
}
|
#inherit_stdin ⇒ WasiConfig
Inherit stdin from the current Ruby process.
285 286 287 288 289 |
# File 'ext/src/ruby_api/wasi_config.rs', line 285
pub fn inherit_stdin(rb_self: RbSelf) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdin = Some(ReadStream::Inherit);
rb_self
}
|
#inherit_stdout ⇒ WasiConfig
Inherit stdout from the current Ruby process.
316 317 318 319 320 |
# File 'ext/src/ruby_api/wasi_config.rs', line 316
pub fn inherit_stdout(rb_self: RbSelf) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdout = Some(WriteStream::Inherit);
rb_self
}
|
#set_argv(args) ⇒ WasiConfig
Set the arguments (argv) to the specified Array.
398 399 400 401 402 |
# File 'ext/src/ruby_api/wasi_config.rs', line 398
pub fn set_argv(rb_self: RbSelf, argv: RArray) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.args = Some(argv.into());
rb_self
}
|
#set_env(env) ⇒ WasiConfig
Set env to the specified Hash.
387 388 389 390 391 |
# File 'ext/src/ruby_api/wasi_config.rs', line 387
pub fn set_env(rb_self: RbSelf, env: RHash) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.env = Some(env.into());
rb_self
}
|
#set_mapped_directory(host_path, guest_path, dir_perms, file_perms) ⇒ WasiConfig
Set mapped directory for host path and guest path.
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 |
# File 'ext/src/ruby_api/wasi_config.rs', line 412
pub fn set_mapped_directory(
rb_self: RbSelf,
host_path: RString,
guest_path: RString,
dir_perms: Symbol,
file_perms: Symbol,
) -> RbSelf {
let mapped_dir = MappedDirectory {
host_path: host_path.into(),
guest_path: guest_path.into(),
dir_perms: dir_perms.into(),
file_perms: file_perms.into(),
};
let mut inner = rb_self.inner.borrow_mut();
inner.mapped_directories.push(mapped_dir);
rb_self
}
|
#set_stderr_buffer(buffer, capacity) ⇒ WasiConfig
Set stderr to write to a string buffer. If the string buffer is frozen, Wasm execution will raise a Wasmtime::Error error. No encoding checks are done on the resulting string, it is the caller's responsibility to ensure the string contains a valid encoding
377 378 379 380 381 382 |
# File 'ext/src/ruby_api/wasi_config.rs', line 377
pub fn set_stderr_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stderr = Some(WriteStream::Buffer(buffer.into(), capacity));
rb_self
}
/// @yard
|
#set_stderr_file(path) ⇒ WasiConfig
Set stderr to write to a file. Will truncate the file if it exists, otherwise try to create it.
363 364 365 366 367 |
# File 'ext/src/ruby_api/wasi_config.rs', line 363
pub fn set_stderr_file(rb_self: RbSelf, path: RString) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stderr = Some(WriteStream::Path(path.into()));
rb_self
}
|
#set_stdin_file(path) ⇒ WasiConfig
Set stdin to read from the specified file.
296 297 298 299 300 |
# File 'ext/src/ruby_api/wasi_config.rs', line 296
pub fn set_stdin_file(rb_self: RbSelf, path: RString) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdin = Some(ReadStream::Path(path.into()));
rb_self
}
|
#set_stdin_string(content) ⇒ WasiConfig
Set stdin to the specified String.
307 308 309 310 311 |
# File 'ext/src/ruby_api/wasi_config.rs', line 307
pub fn set_stdin_string(rb_self: RbSelf, content: RString) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdin = Some(ReadStream::String(content.into()));
rb_self
}
|
#set_stdout_buffer(buffer, capacity) ⇒ WasiConfig
Set stdout to write to a string buffer. If the string buffer is frozen, Wasm execution will raise a Wasmtime::Error error. No encoding checks are done on the resulting string, it is the caller's responsibility to ensure the string contains a valid encoding
342 343 344 345 346 |
# File 'ext/src/ruby_api/wasi_config.rs', line 342
pub fn set_stdout_buffer(rb_self: RbSelf, buffer: RString, capacity: usize) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdout = Some(WriteStream::Buffer(buffer.into(), capacity));
rb_self
}
|
#set_stdout_file(path) ⇒ WasiConfig
Set stdout to write to a file. Will truncate the file if it exists, otherwise try to create it.
328 329 330 331 332 |
# File 'ext/src/ruby_api/wasi_config.rs', line 328
pub fn set_stdout_file(rb_self: RbSelf, path: RString) -> RbSelf {
let mut inner = rb_self.inner.borrow_mut();
inner.stdout = Some(WriteStream::Path(path.into()));
rb_self
}
|
#socket_addr_check {|addr, use| ... } ⇒ WasiConfig
Set a custom check function for socket address access control. The block will be called for each socket operation with the socket address (as a String) and the operation type (as a Symbol: :tcp_bind, :tcp_connect, :udp_bind, :udp_connect, :udp_outgoing_datagram). The block should return true to allow the operation or false to deny it. If the block raises an exception, the operation will be denied.
Note: any network access happens while the Global VM Lock (GVL) is held, so other threads will be blocked in the meantime.
494 495 496 497 498 499 500 501 |
# File 'ext/src/ruby_api/wasi_config.rs', line 494
pub fn socket_addr_check(ruby: &Ruby, rb_self: RbSelf) -> RbSelf {
if ruby.block_given() {
let proc = ruby.block_proc().unwrap();
let mut inner = rb_self.inner.borrow_mut();
inner.socket_addr_check = Some(proc.into());
}
rb_self
}
|