mirror of
https://github.com/facebookexperimental/reverie.git
synced 2025-01-22 21:04:53 +00:00
Add test to check that syscalls are suppressed successfully
Summary: This checks that intercepted syscalls are actually skipped (by setting the syscall to -1). This was found to not be working on aarch64 and is fixed in the next diff. Reviewed By: VladimirMakaev Differential Revision: D40867424 fbshipit-source-id: 7ac514c060a2611aac8cc4a8bb7540aa3d7302fb
This commit is contained in:
parent
76adc9174f
commit
deac8c4140
1 changed files with 60 additions and 0 deletions
60
tests/suppression.rs
Normal file
60
tests/suppression.rs
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
//! Tests that syscall suppression works. That is, when we intercept a syscall,
|
||||
//! we should not run the real syscall.
|
||||
|
||||
use reverie::syscalls::Syscall;
|
||||
use reverie::Error;
|
||||
use reverie::Guest;
|
||||
use reverie::Tool;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
|
||||
struct TestTool;
|
||||
|
||||
#[reverie::tool]
|
||||
impl Tool for TestTool {
|
||||
async fn handle_syscall_event<T: Guest<Self>>(
|
||||
&self,
|
||||
guest: &mut T,
|
||||
syscall: Syscall,
|
||||
) -> Result<i64, Error> {
|
||||
match syscall {
|
||||
Syscall::Tgkill(_) => {
|
||||
// Suppress this syscall. This thread shall not be killed.
|
||||
Ok(0)
|
||||
}
|
||||
_ => guest.tail_inject(syscall).await,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(not(sanitized), test))]
|
||||
mod tests {
|
||||
use reverie_ptrace::testing::check_fn;
|
||||
use syscalls::syscall;
|
||||
use syscalls::Sysno;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn suppress_tgkill() {
|
||||
check_fn::<TestTool, _>(|| {
|
||||
let pid = unsafe { syscall!(Sysno::getpid) }.unwrap();
|
||||
let tid = unsafe { syscall!(Sysno::gettid) }.unwrap();
|
||||
|
||||
// This shouldn't work.
|
||||
for _ in 0..100 {
|
||||
let ret = unsafe { syscall!(Sysno::tgkill, pid, tid, libc::SIGTERM) };
|
||||
assert_eq!(ret, Ok(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue