make sure we check argument count everywhere

This commit is contained in:
Ralf Jung 2020-05-05 11:57:08 +02:00
parent 5566e3901c
commit cd6be98852
3 changed files with 35 additions and 26 deletions

View File

@ -379,19 +379,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Incomplete shims that we "stub out" just to get pre-main initialization code to work. // Incomplete shims that we "stub out" just to get pre-main initialization code to work.
// These shims are enabled only when the caller is in the standard library. // These shims are enabled only when the caller is in the standard library.
| "pthread_attr_init" "pthread_attr_getguardsize"
| "pthread_attr_destroy" if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
| "pthread_attr_setstacksize"
| "pthread_condattr_init"
| "pthread_condattr_setclock"
| "pthread_cond_init"
| "pthread_condattr_destroy"
| "pthread_cond_destroy" if this.frame().instance.to_string().starts_with("std::sys::unix::")
=> {
this.write_null(dest)?;
}
"pthread_attr_getguardsize" if this.frame().instance.to_string().starts_with("std::sys::unix::")
=> {
let &[_attr, guard_size] = check_arg_count(args)?; let &[_attr, guard_size] = check_arg_count(args)?;
let guard_size = this.deref_operand(guard_size)?; let guard_size = this.deref_operand(guard_size)?;
let guard_size_layout = this.libc_ty_layout("size_t")?; let guard_size_layout = this.libc_ty_layout("size_t")?;
@ -401,11 +390,33 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
this.write_null(dest)?; this.write_null(dest)?;
} }
| "pthread_attr_init"
| "pthread_attr_destroy"
| "pthread_condattr_init"
| "pthread_condattr_destroy"
| "pthread_cond_destroy"
if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_] = check_arg_count(args)?;
this.write_null(dest)?;
}
| "pthread_cond_init"
| "pthread_attr_setstacksize"
| "pthread_condattr_setclock"
if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_, _] = check_arg_count(args)?;
this.write_null(dest)?;
}
| "signal" | "signal"
| "sigaction"
| "sigaltstack" | "sigaltstack"
| "mprotect" if this.frame().instance.to_string().starts_with("std::sys::unix::") if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
=> { let &[_, _] = check_arg_count(args)?;
this.write_null(dest)?;
}
| "sigaction"
| "mprotect"
if this.frame().instance.to_string().starts_with("std::sys::unix::") => {
let &[_, _, _] = check_arg_count(args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }

View File

@ -251,22 +251,19 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Just fake a HANDLE // Just fake a HANDLE
this.write_scalar(Scalar::from_machine_isize(1, this), dest)?; this.write_scalar(Scalar::from_machine_isize(1, this), dest)?;
} }
"GetModuleHandleW" if this.frame().instance.to_string().starts_with("std::sys::windows::") "GetModuleHandleW" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
=> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let &[_lpModuleName] = check_arg_count(args)?; let &[_lpModuleName] = check_arg_count(args)?;
// Pretend this does not exist / nothing happened, by returning zero. // Pretend this does not exist / nothing happened, by returning zero.
this.write_null(dest)?; this.write_null(dest)?;
} }
"GetProcAddress" if this.frame().instance.to_string().starts_with("std::sys::windows::") "GetProcAddress" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
=> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let &[_hModule, _lpProcName] = check_arg_count(args)?; let &[_hModule, _lpProcName] = check_arg_count(args)?;
// Pretend this does not exist / nothing happened, by returning zero. // Pretend this does not exist / nothing happened, by returning zero.
this.write_null(dest)?; this.write_null(dest)?;
} }
"SetConsoleTextAttribute" if this.frame().instance.to_string().starts_with("std::sys::windows::") "SetConsoleTextAttribute" if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
=> {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let &[_hConsoleOutput, _wAttribute] = check_arg_count(args)?; let &[_hConsoleOutput, _wAttribute] = check_arg_count(args)?;
// Pretend these does not exist / nothing happened, by returning zero. // Pretend these does not exist / nothing happened, by returning zero.
@ -281,8 +278,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "InitializeCriticalSection" | "InitializeCriticalSection"
| "EnterCriticalSection" | "EnterCriticalSection"
| "LeaveCriticalSection" | "LeaveCriticalSection"
| "DeleteCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::") | "DeleteCriticalSection"
=> { if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let &[_lpCriticalSection] = check_arg_count(args)?; let &[_lpCriticalSection] = check_arg_count(args)?;
assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported"); assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported");
@ -290,8 +287,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// (Windows locks are reentrant, and we have only 1 thread, // (Windows locks are reentrant, and we have only 1 thread,
// so not doing any futher checks here is at least not incorrect.) // so not doing any futher checks here is at least not incorrect.)
} }
"TryEnterCriticalSection" if this.frame().instance.to_string().starts_with("std::sys::windows::") "TryEnterCriticalSection"
=> { if this.frame().instance.to_string().starts_with("std::sys::windows::") => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let &[_lpCriticalSection] = check_arg_count(args)?; let &[_lpCriticalSection] = check_arg_count(args)?;
assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported"); assert_eq!(this.get_total_thread_count()?, 1, "concurrency on Windows not supported");

View File

@ -363,6 +363,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
| "atomic_singlethreadfence_acqrel" | "atomic_singlethreadfence_acqrel"
| "atomic_singlethreadfence" | "atomic_singlethreadfence"
=> { => {
let &[] = check_arg_count(args)?;
// we are inherently singlethreaded and singlecored, this is a nop // we are inherently singlethreaded and singlecored, this is a nop
} }