Verified Commit dcacbaed authored by jD91mZM2's avatar jD91mZM2

Add PtraceEvent for catching tracee forks

parent c89c2cb2
use core::ops::{Deref, DerefMut};
use core::{mem, slice};
use core::{fmt, mem, slice};
#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
......@@ -13,7 +13,7 @@ impl Deref for Event {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::<Event>()) as &[u8]
slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::<Event>())
}
}
}
......@@ -21,7 +21,7 @@ impl Deref for Event {
impl DerefMut for Event {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::<Event>()) as &mut [u8]
slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::<Event>())
}
}
}
......@@ -38,7 +38,7 @@ impl Deref for ITimerSpec {
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const ITimerSpec as *const u8,
mem::size_of::<ITimerSpec>()) as &[u8]
mem::size_of::<ITimerSpec>())
}
}
}
......@@ -47,7 +47,7 @@ impl DerefMut for ITimerSpec {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut ITimerSpec as *mut u8,
mem::size_of::<ITimerSpec>()) as &mut [u8]
mem::size_of::<ITimerSpec>())
}
}
}
......@@ -64,7 +64,7 @@ impl Deref for Map {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const Map as *const u8, mem::size_of::<Map>()) as &[u8]
slice::from_raw_parts(self as *const Map as *const u8, mem::size_of::<Map>())
}
}
}
......@@ -72,7 +72,7 @@ impl Deref for Map {
impl DerefMut for Map {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut Map as *mut u8, mem::size_of::<Map>()) as &mut [u8]
slice::from_raw_parts_mut(self as *mut Map as *mut u8, mem::size_of::<Map>())
}
}
}
......@@ -94,7 +94,7 @@ impl Deref for Packet {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::<Packet>()) as &[u8]
slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::<Packet>())
}
}
}
......@@ -102,7 +102,7 @@ impl Deref for Packet {
impl DerefMut for Packet {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::<Packet>()) as &mut [u8]
slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::<Packet>())
}
}
}
......@@ -150,7 +150,7 @@ impl Deref for Stat {
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const Stat as *const u8,
mem::size_of::<Stat>()) as &[u8]
mem::size_of::<Stat>())
}
}
}
......@@ -159,7 +159,7 @@ impl DerefMut for Stat {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut Stat as *mut u8,
mem::size_of::<Stat>()) as &mut [u8]
mem::size_of::<Stat>())
}
}
}
......@@ -178,7 +178,7 @@ impl Deref for StatVfs {
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const StatVfs as *const u8,
mem::size_of::<StatVfs>()) as &[u8]
mem::size_of::<StatVfs>())
}
}
}
......@@ -187,7 +187,7 @@ impl DerefMut for StatVfs {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8,
mem::size_of::<StatVfs>()) as &mut [u8]
mem::size_of::<StatVfs>())
}
}
}
......@@ -204,7 +204,7 @@ impl Deref for TimeSpec {
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const TimeSpec as *const u8,
mem::size_of::<TimeSpec>()) as &[u8]
mem::size_of::<TimeSpec>())
}
}
}
......@@ -213,7 +213,7 @@ impl DerefMut for TimeSpec {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut TimeSpec as *mut u8,
mem::size_of::<TimeSpec>()) as &mut [u8]
mem::size_of::<TimeSpec>())
}
}
}
......@@ -257,7 +257,7 @@ impl Deref for IntRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::<IntRegisters>()) as &[u8]
slice::from_raw_parts(self as *const IntRegisters as *const u8, mem::size_of::<IntRegisters>())
}
}
}
......@@ -265,7 +265,7 @@ impl Deref for IntRegisters {
impl DerefMut for IntRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::<IntRegisters>()) as &mut [u8]
slice::from_raw_parts_mut(self as *mut IntRegisters as *mut u8, mem::size_of::<IntRegisters>())
}
}
}
......@@ -291,7 +291,7 @@ impl Deref for FloatRegisters {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::<FloatRegisters>()) as &[u8]
slice::from_raw_parts(self as *const FloatRegisters as *const u8, mem::size_of::<FloatRegisters>())
}
}
}
......@@ -299,7 +299,51 @@ impl Deref for FloatRegisters {
impl DerefMut for FloatRegisters {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::<FloatRegisters>()) as &mut [u8]
slice::from_raw_parts_mut(self as *mut FloatRegisters as *mut u8, mem::size_of::<FloatRegisters>())
}
}
}
#[derive(Clone, Copy)]
#[repr(C)]
pub union PtraceEventContent {
pub clone: usize,
}
impl Default for PtraceEventContent {
fn default() -> Self {
Self {
clone: 0
}
}
}
impl fmt::Debug for PtraceEventContent {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "PtraceEventContent(...)")
}
}
#[derive(Clone, Copy, Debug, Default)]
#[repr(C)]
pub struct PtraceEvent {
pub tag: u16,
pub data: PtraceEventContent,
}
impl Deref for PtraceEvent {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const PtraceEvent as *const u8, mem::size_of::<PtraceEvent>())
}
}
}
impl DerefMut for PtraceEvent {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut PtraceEvent as *mut u8, mem::size_of::<PtraceEvent>())
}
}
}
......@@ -72,6 +72,8 @@ pub const PTRACE_WAIT: u8 = 0b0000_0100;
pub const PTRACE_OPERATIONMASK: u8 = 0b0000_1111;
pub const PTRACE_SYSEMU: u8 = 0b0001_0000;
pub const PTRACE_EVENT_CLONE: u16 = 0;
pub const SEEK_SET: usize = 0;
pub const SEEK_CUR: usize = 1;
pub const SEEK_END: usize = 2;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment