1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) 2011-2017, UDI Contributors
// All rights reserved.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
#![deny(warnings)]
#![recursion_limit = "1024"]

extern crate serde;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate downcast_rs;
#[macro_use]
extern crate derive_error_chain;

use std::fs;
use std::sync::{Mutex, Arc};

use downcast_rs::Downcast;

pub mod protocol;
mod errors;
mod create;
mod process;
mod thread;
mod events;

pub use errors::*;
pub use create::create_process;
pub use create::ProcessConfig;
pub use events::Event;
pub use events::wait_for_events;
pub use protocol::event::EventData;
pub use protocol::Architecture;
pub use protocol::Register;

pub trait UserData: Downcast + std::fmt::Debug {}
impl_downcast!(UserData);

#[derive(Debug)]
struct ProcessFileContext {
    request_file: fs::File,
    response_file: fs::File,
    events_file: fs::File
}

#[derive(Debug)]
pub struct Process {
    pid: u32,
    file_context: Option<ProcessFileContext>,
    architecture: Architecture,
    protocol_version: u32,
    multithread_capable: bool,
    running: bool,
    terminating: bool,
    user_data: Option<Box<UserData>>,
    threads: Vec<Arc<Mutex<Thread>>>,
    root_dir: String
}

#[derive(Debug,Copy,Clone,PartialEq)]
pub enum ThreadState {
    Running,
    Suspended
}

#[derive(Debug)]
struct ThreadFileContext {
    request_file: fs::File,
    response_file: fs::File
}

#[derive(Debug)]
pub struct Thread {
    initial: bool,
    tid: u64,
    file_context: Option<ThreadFileContext>,
    single_step: bool,
    state: ThreadState,
    architecture: Architecture,
    user_data: Option<Box<UserData>>
}