Skip to content

Commit ea36f9e

Browse files
committed
Mark the highlevel functions as unsafe.
Following @RalfJung's comment here: #8 (comment) as long as the functions are still taking integer file descriptor arguments, we should mark the APIs here `unsafe`. This is particularly interesting in the context of WASI, as it aligns with the OCap security model -- Rust's `std::fs::File` is an unforgeable handle in safe Rust. So while there are still integer file descriptors at the wasm level for now, programs compiled from safe Rust still have fine-grained isolation (with the caveat that until reference types are possible, this property isn't encoded in wasm in a verifiable way).
1 parent 3bbea34 commit ea36f9e

File tree

2 files changed

+368
-467
lines changed

2 files changed

+368
-467
lines changed

crates/generate-raw/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@ fn render_highlevel(func: &InterfaceFunc, module: &str, src: &mut String) {
262262

263263
// Render the function and its arguments, and note that the arguments here
264264
// are the exact type name arguments as opposed to the pointer/length pair
265-
// ones.
266-
src.push_str("pub fn ");
265+
// ones. These functions are unsafe because they work with integer file
266+
// descriptors, which are effectively forgeable and danglable raw pointers
267+
// into the file descriptor address space.
268+
src.push_str("pub unsafe fn ");
267269
src.push_str(&rust_name);
268270
src.push_str("(");
269271
for param in func.params.iter() {
@@ -295,7 +297,7 @@ fn render_highlevel(func: &InterfaceFunc, module: &str, src: &mut String) {
295297
src.push_str(">");
296298
}
297299

298-
src.push_str("{ unsafe {");
300+
src.push_str("{");
299301
for result in func.results.iter().skip(1) {
300302
src.push_str("let mut ");
301303
result.name.render(src);
@@ -350,7 +352,7 @@ fn render_highlevel(func: &InterfaceFunc, module: &str, src: &mut String) {
350352
}
351353
src.push_str(") }");
352354
}
353-
src.push_str("} }");
355+
src.push_str("}");
354356
}
355357

356358
impl Render for InterfaceFunc {

0 commit comments

Comments
 (0)