Skip to content

Commit 31e4003

Browse files
committed
feat(io): add bounded argv process execution
1 parent b58a82c commit 31e4003

20 files changed

Lines changed: 4335 additions & 12 deletions

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ self_cell = "1"
9494
rustyline = { version = "14", optional = true }
9595

9696
[target.'cfg(windows)'.dependencies]
97-
windows-sys = { version = "0.59", features = ["Win32_System_Diagnostics_Debug", "Win32_System_Diagnostics_ToolHelp", "Win32_System_Memory", "Win32_System_ProcessStatus", "Win32_System_Threading"] }
97+
windows-sys = { version = "0.59", features = ["Win32_Security", "Win32_Storage_FileSystem", "Win32_System_Diagnostics_Debug", "Win32_System_Diagnostics_ToolHelp", "Win32_System_IO", "Win32_System_JobObjects", "Win32_System_Memory", "Win32_System_Pipes", "Win32_System_ProcessStatus", "Win32_System_Threading"] }
9898

9999
[target.'cfg(unix)'.dependencies]
100100
libc = "0.2"

pd-vm-nostd/src/generated_builtin_ids.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ pub const MATH_COPYSIGN_CALL_INDEX: u16 = 0xFFF8;
112112
pub const MATH_CLAMP_CALL_INDEX: u16 = 0xFFF9;
113113
pub const MATH_MUL_ADD_CALL_INDEX: u16 = 0xFFFA;
114114
pub const COUNT_CALL_INDEX: u16 = 0xFFFB;
115+
pub const IO_EXEC_CALL_INDEX: u16 = 0xFFFC;
115116

116117
/// Every static builtin call index, ascending.
117118
pub const ALL_CALL_INDICES: &[u16] = &[
@@ -219,4 +220,5 @@ pub const ALL_CALL_INDICES: &[u16] = &[
219220
MATH_CLAMP_CALL_INDEX,
220221
MATH_MUL_ADD_CALL_INDEX,
221222
COUNT_CALL_INDEX,
223+
IO_EXEC_CALL_INDEX,
222224
];

src/builtins/catalog.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ builtin_id!(0xFFF8, "math::copysign", MathCopySign, Ordinary, none);
125125
builtin_id!(0xFFF9, "math::clamp", MathClamp, Ordinary, none);
126126
builtin_id!(0xFFFA, "math::mul_add", MathMulAdd, Ordinary, none);
127127
builtin_id!(0xFFFB, "count", Count, Ordinary, none);
128+
builtin_id!(0xFFFC, "io::exec", IoExec, Ordinary, none);
128129
builtin_id!(0xFF9E, "__format_template", FormatTemplate, Internal, none);
129130
builtin_id!(0xFF9F, "__to_string", ToString, Internal, none);
130131
builtin_id!(0xFFA0, "type", TypeOf, Special, none);

src/builtins/runtime/io/async_io.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use pd_host_function::pd_host_function;
1313

1414
use super::super::HostCallResult;
15+
use super::super::typed::{VmArrayRef, VmMap};
1516
use super::shared::*;
1617

1718
// ---- IO builtin functions (thin wrappers with #[pd_host_function]) ----
@@ -39,6 +40,17 @@ pub(crate) fn builtin_io_popen(
3940
builtin_io_popen_body(vm, command, mode)
4041
}
4142

43+
/// Executes a bounded argv-only process and returns bounded output metadata.
44+
#[pd_host_function(name = "io::exec")]
45+
pub(crate) fn builtin_io_exec(
46+
vm: &mut Vm,
47+
argv: VmArrayRef<'_>,
48+
timeout_ms: i64,
49+
max_output_bytes: i64,
50+
) -> VmResult<HostCallResult<VmMap>> {
51+
builtin_io_exec_body(vm, argv, timeout_ms, max_output_bytes)
52+
}
53+
4254
/// Reads all remaining text from an I/O handle.
4355
/// The actual read runs on a worker thread.
4456
#[pd_host_function(name = "io::read_all")]

src/builtins/runtime/io/blocking.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use pd_host_function::pd_host_function;
1313

1414
use super::super::HostCallResult;
15+
use super::super::typed::{VmArrayRef, VmMap};
1516
use super::shared::*;
1617

1718
// ---- IO builtin functions (thin wrappers with #[pd_host_function]) ----
@@ -39,6 +40,17 @@ pub(crate) fn builtin_io_popen(
3940
builtin_io_popen_body(vm, command, mode)
4041
}
4142

43+
/// Executes a bounded argv-only process and returns bounded output metadata.
44+
#[pd_host_function(name = "io::exec")]
45+
pub(crate) fn builtin_io_exec(
46+
vm: &mut Vm,
47+
argv: VmArrayRef<'_>,
48+
timeout_ms: i64,
49+
max_output_bytes: i64,
50+
) -> VmResult<HostCallResult<VmMap>> {
51+
builtin_io_exec_body(vm, argv, timeout_ms, max_output_bytes)
52+
}
53+
4254
/// Reads all remaining text from an I/O handle.
4355
/// The actual read runs on a worker thread.
4456
#[pd_host_function(name = "io::read_all")]

0 commit comments

Comments
 (0)