From 89c722ac325a440bdd5f34befe2d28e23ec29d25 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Mon, 14 Jun 2021 22:53:17 +0800 Subject: [PATCH] Add some comments about `check_shim` --- src/shims/foreign_items.rs | 6 ++++++ src/shims/posix/foreign_items.rs | 2 ++ src/shims/posix/linux/foreign_items.rs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/src/shims/foreign_items.rs b/src/shims/foreign_items.rs index 96edfcc9cf74..87906d877f8f 100644 --- a/src/shims/foreign_items.rs +++ b/src/shims/foreign_items.rs @@ -223,12 +223,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx let (dest, ret) = match ret { None => match link_name { "miri_start_panic" => { + // `check_shim` happens inside `handle_miri_start_panic`. this.handle_miri_start_panic(abi, link_name_sym, args, unwind)?; return Ok(None); } // This matches calls to the foreign item `panic_impl`. // The implementation is provided by the function with the `#[panic_handler]` attribute. "panic_impl" => { + // We don't use `check_shim` here because we are just forwarding to the lang + // item. Argument count checking will be performed when the returned `Body` is + // called. this.check_abi_and_shim_symbol_clash(abi, Abi::Rust, link_name_sym)?; let panic_impl_id = tcx.lang_items().panic_impl().unwrap(); let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id); @@ -317,11 +321,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Obtains a Miri backtrace. See the README for details. "miri_get_backtrace" => { + // `check_shim` happens inside `handle_miri_get_backtrace`. this.handle_miri_get_backtrace(abi, link_name_sym, args, dest)?; } // Resolves a Miri backtrace frame. See the README for details. "miri_resolve_frame" => { + // `check_shim` happens inside `handle_miri_resolve_frame`. this.handle_miri_resolve_frame(abi, link_name_sym, args, dest)?; } diff --git a/src/shims/posix/foreign_items.rs b/src/shims/posix/foreign_items.rs index 45e3d502a290..2b8ea78bf3f1 100644 --- a/src/shims/posix/foreign_items.rs +++ b/src/shims/posix/foreign_items.rs @@ -60,6 +60,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx this.write_scalar(Scalar::from_i32(result), dest)?; } "fcntl" => { + // `fcntl` is variadic. The argument count is checked based on the first argument + // in`this.fcntl()`, so we do not use `check_shim` here. this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name_sym)?; let result = this.fcntl(args)?; this.write_scalar(Scalar::from_i32(result), dest)?; diff --git a/src/shims/posix/linux/foreign_items.rs b/src/shims/posix/linux/foreign_items.rs index 9af97103e07e..07d764a68e91 100644 --- a/src/shims/posix/linux/foreign_items.rs +++ b/src/shims/posix/linux/foreign_items.rs @@ -128,6 +128,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx // Dynamically invoked syscalls "syscall" => { + // We do not use `check_shim` here because `syscall` is variadic. The argument + // count is checked bellow. this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name_sym)?; // The syscall variadic function is legal to call with more arguments than needed, // extra arguments are simply ignored. However, all arguments need to be scalars;