feat: protect existing objects during read-only calls and track reads

This commit is contained in:
2026-10-21 14:17:38 +08:00
parent 44a02c9fd6
commit ff49f266a2
11 changed files with 249 additions and 6 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
| [lib.rs](lib.rs) | VM 类型导出、objects 类型兼容重导出、宿主调用与字节码 rustdoc 示例 |
| [vm.rs](vm.rs) | Vm 拥有 ObjectStore 与错误位置记录;对象操作和宿主 new_class 注册显式委托给 objects |
| [frame.rs](frame.rs) | EndorFrame、栈条目、执行位置元数据、ExecutionLimits |
| [eval.rs](eval.rs) | execute/call、参数绑定、帧切换、取指分派、MakeFunction、结果根转移与失败清理 |
| [eval.rs](eval.rs) | execute/call、只读调用与依赖结果、参数绑定、帧切换、取指分派、MakeFunction、结果根转移与失败清理 |
## 常见修改入口
+15
View File
@@ -48,6 +48,21 @@ impl Vm {
self.call_with_limits(function, arguments, ExecutionLimits::default())
}
/// Allow result allocation while rejecting mutations of objects that were
/// already alive on entry. All reads share the call's normal frame budget.
/// Returned read handles are borrowed dependency identities, not owned roots.
pub fn call_read_only_with_limits(
&mut self,
function: ObjectRef,
arguments: &[Value],
limits: ExecutionLimits,
) -> Result<(Value, Vec<ObjectRef>), VmError> {
let scope = self.objects.begin_read_only();
let result = self.call_with_limits(function, arguments, limits);
let reads = self.objects.end_read_only(scope)?;
result.map(|value| (value, reads))
}
pub fn call_with_limits(
&mut self,
function: ObjectRef,