Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwhite committed Sep 5, 2019
1 parent 373d7e8 commit 9c2217d
Show file tree
Hide file tree
Showing 47 changed files with 1,816 additions and 1,286 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
max_width = 80
9 changes: 5 additions & 4 deletions examples/counter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
#![feature(format_args_nl)]

#![allow(dead_code)]
#![allow(unused_attributes)]

#[allow(unused_imports)]
use std::ffi::CStr;

use reverie_helper::{ syscalls::*, counter::*, common::local_state::ProcessState, logger };
use reverie_helper::{
common::local_state::ProcessState, counter::*, logger, syscalls::*,
};

#[cfg_attr(target_os = "linux", link_section = ".ctors")]
#[used]
static ECHO_DSO_CTORS: extern fn() = {
static ECHO_DSO_CTORS: extern "C" fn() = {
extern "C" fn echo_ctor() {
let _ = logger::init();
let _ = logger::init();
};
echo_ctor
};
Expand Down
37 changes: 16 additions & 21 deletions examples/det/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,25 @@
#![allow(unused_imports)]
#![allow(unused_attributes)]

use reverie_helper::{syscalls::*, counter::*, common::local_state::ProcessState, logger};
use log::*;
use reverie_helper::{
common::local_state::ProcessState, counter::*, logger, syscalls::*,
};

#[allow(unused_imports)]
use std::ffi::CStr;

use std::cell::RefCell;
use std::sync::Arc;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use libc;

#[link_section = ".init_array"]
#[used]
static ECHO_DSO_CTORS: extern fn() = {
static ECHO_DSO_CTORS: extern "C" fn() = {
extern "C" fn echo_ctor() {
let _ = logger::init();
let _ = logger::init();
};
echo_ctor
};
Expand All @@ -44,29 +46,26 @@ pub extern "C" fn captured_syscall(
match sc {
SYS_gettimeofday => {
let tick = LOGICAL_TIME.fetch_add(1, Ordering::SeqCst) as i64;
if let Some(mut tp) = unsafe {
(a0 as *mut libc::timeval).as_mut()
} {
if let Some(mut tp) = unsafe { (a0 as *mut libc::timeval).as_mut() }
{
tp.tv_sec = tick;
tp.tv_usec = 0;
}
res = 0;
}
SYS_clock_gettime => {
let tick = LOGICAL_TIME.fetch_add(1, Ordering::SeqCst) as i64;
if let Some(mut tp) = unsafe {
(a1 as *mut libc::timespec).as_mut()
} {
if let Some(mut tp) =
unsafe { (a1 as *mut libc::timespec).as_mut() }
{
tp.tv_sec = tick;
tp.tv_nsec = 0;
}
res = 0;
}
SYS_time => {
let tick = LOGICAL_TIME.fetch_add(1, Ordering::SeqCst) as i64;
if let Some(tp) = unsafe {
(a0 as *mut libc::time_t).as_mut()
} {
if let Some(tp) = unsafe { (a0 as *mut libc::time_t).as_mut() } {
*tp = tick;
}
res = tick;
Expand All @@ -75,18 +74,14 @@ pub extern "C" fn captured_syscall(
// don't write arg0 as it is a const pointer
// use our own instead.
let t = libc::timespec {
tv_sec : 0,
tv_nsec : 0,
tv_sec: 0,
tv_nsec: 0,
};
let tp = &t as *const libc::timespec;
res = unsafe {
untraced_syscall(no, tp as i64, a1, 0, 0, 0, 0)
}
res = unsafe { untraced_syscall(no, tp as i64, a1, 0, 0, 0, 0) }
}
_ => {
res = unsafe {
untraced_syscall(no, a0, a1, a2, a3, a4, a5)
};
res = unsafe { untraced_syscall(no, a0, a1, a2, a3, a4, a5) };
}
}
res
Expand Down
41 changes: 19 additions & 22 deletions examples/echo/src/dpc.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! deferred precedure calls
//!
use reverie_helper::{ common::consts, syscalls::syscall, logger} ;
use log::debug;
use reverie_helper::{common::consts, logger, syscalls::syscall};

const DPC_PREFIX: &'static str = "/tmp/dpc-task.";

Expand All @@ -17,34 +17,34 @@ pub extern "C" fn dpc_entry_disabled(_arg: i64) -> i32 {
0
}

const HEX_DIGITS: [u8; 16] = [ '0' as u8, '1' as u8, '2' as u8, '3' as u8,
'4' as u8, '5' as u8, '6' as u8, '7' as u8,
'8' as u8, '9' as u8, 'a' as u8, 'b' as u8,
'c' as u8, 'd' as u8, 'e' as u8, 'f' as u8];
const HEX_DIGITS: [u8; 16] = [
'0' as u8, '1' as u8, '2' as u8, '3' as u8, '4' as u8, '5' as u8,
'6' as u8, '7' as u8, '8' as u8, '9' as u8, 'a' as u8, 'b' as u8,
'c' as u8, 'd' as u8, 'e' as u8, 'f' as u8,
];

fn dpc_get_unp(pid: i32) -> [u8; 108] {
let mut unp: [u8; 108] = unsafe {
core::mem::zeroed()
};
let mut unp: [u8; 108] = unsafe { core::mem::zeroed() };

let k = DPC_PREFIX.len();
unsafe {
core::ptr::copy_nonoverlapping(
DPC_PREFIX.as_ptr() as *const u8,
unp.as_mut_ptr() as *mut u8,
k)
k,
)
};
unp[k] = HEX_DIGITS[(pid as usize & 0xf000) >> 12];
unp[k+1] = HEX_DIGITS[(pid as usize & 0x0f00) >> 8];
unp[k+2] = HEX_DIGITS[(pid as usize & 0x00f0) >> 4];
unp[k+3] = HEX_DIGITS[(pid as usize & 0x000f) >> 0];
unp[k] = HEX_DIGITS[(pid as usize & 0xf000) >> 12];
unp[k + 1] = HEX_DIGITS[(pid as usize & 0x0f00) >> 8];
unp[k + 2] = HEX_DIGITS[(pid as usize & 0x00f0) >> 4];
unp[k + 3] = HEX_DIGITS[(pid as usize & 0x000f) >> 0];

unp
}

#[link_section = ".fini_array"]
#[used]
static DPC_DSO_DTORS: extern fn() = {
static DPC_DSO_DTORS: extern "C" fn() = {
extern "C" fn dpc_dtor() {
debug!("exiting dpc task..");
let pid = syscall!(SYS_getpid).unwrap() as i32;
Expand All @@ -61,7 +61,7 @@ struct sockaddr {
sa_data: [u8; 108],
}

fn dpc_main () {
fn dpc_main() {
let pid = syscall!(SYS_getpid).unwrap() as i32;
let path = dpc_get_unp(pid);

Expand All @@ -85,9 +85,7 @@ fn dpc_main () {
let _ = syscall!(SYS_listen, sockfd, 10).unwrap();

loop {
let mut client = unsafe {
core::mem::zeroed()
};
let mut client = unsafe { core::mem::zeroed() };
let client_ref = &mut client as *mut sockaddr;
let fd = syscall!(SYS_accept, sockfd, client_ref, sockfd_len).unwrap();

Expand All @@ -96,10 +94,9 @@ fn dpc_main () {
}

fn incoming_connection(fd: i32) {
let mut request: [u8; 512] = unsafe {
core::mem::uninitialized()
};
let mut request: [u8; 512] = unsafe { core::mem::uninitialized() };
let ptr = request.as_mut_ptr();
let n = syscall!(SYS_read, fd, ptr, core::mem::size_of_val(&request)).unwrap();
let n =
syscall!(SYS_read, fd, ptr, core::mem::size_of_val(&request)).unwrap();
let _ = syscall!(SYS_write, fd, ptr, n).unwrap();
}
15 changes: 12 additions & 3 deletions examples/echo/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
//!
use crate::show::*;
use reverie_helper::syscalls::*;
use reverie_helper::counter::{note_syscall, NoteInfo};
use reverie_helper::common::local_state::{ProcessState, ThreadState};
use reverie_helper::counter::{note_syscall, NoteInfo};
use reverie_helper::syscalls::*;

use reverie_helper::logger::*;
use reverie_helper::*;
Expand Down Expand Up @@ -43,6 +43,15 @@ pub extern "C" fn captured_syscall(
smsg!("{}", info);
flush!();
let ret = unsafe { untraced_syscall(no, a0, a1, a2, a3, a4, a5) };
smsgln!("{}", SyscallRetInfo::from(tid as i32, sc, info.args_after_syscall(), ret, info.nargs_before == 0));
smsgln!(
"{}",
SyscallRetInfo::from(
tid as i32,
sc,
info.args_after_syscall(),
ret,
info.nargs_before == 0
)
);
ret
}
10 changes: 5 additions & 5 deletions examples/echo/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#![feature(format_args_nl, slice_internals)]
#![allow(unused_attributes)]

use reverie_helper::{counter, common, logger};
use reverie_helper::{common, counter, logger};

#[macro_use]
pub mod macros;
pub mod entry;
pub mod dpc;
pub mod entry;
pub mod show;

pub use counter::{NoteInfo, note_syscall};
pub use common::local_state::{ProcessState, ThreadState};
pub use counter::{note_syscall, NoteInfo};

use entry::captured_syscall;

Expand All @@ -19,9 +19,9 @@ extern crate lazy_static;

#[link_section = ".init_array"]
#[used]
static ECHO_DSO_CTORS: extern fn() = {
static ECHO_DSO_CTORS: extern "C" fn() = {
extern "C" fn echo_ctor() {
let _ = logger::init();
let _ = logger::init();
};
echo_ctor
};
9 changes: 5 additions & 4 deletions examples/echo/src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

#[macro_export]
macro_rules! libc_bit_field {
($flags:ident, $bit: ident) => {
Expand All @@ -7,18 +6,20 @@ macro_rules! libc_bit_field {
} else {
None
}
}
};
}

#[macro_export]
macro_rules! libc_bit_sh {
($flags:ident, $bit: ident) => {
if ($flags as u64) & (1u64.wrapping_shl(libc::$bit as u32)) == (1u64.wrapping_shl(libc::$bit as u32)) {
if ($flags as u64) & (1u64.wrapping_shl(libc::$bit as u32))
== (1u64.wrapping_shl(libc::$bit as u32))
{
Some(stringify!($bit))
} else {
None
}
}
};
}

#[macro_export]
Expand Down
Loading

0 comments on commit 9c2217d

Please sign in to comment.