diff --git a/src/main.rs b/src/main.rs index aeb4cd2..76a45cb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,11 @@ use std::sync::Arc; use serde::{Serialize, Deserialize}; use serde_json; use shlex; +mod portalcall; const BUF_SIZE: usize = 65536; const CMD_TIMEOUT: Duration = Duration::from_secs(10); +const INDIV_DEBUG_PORTALCALL_MAGIC: u64 = 0xfeedbeef; #[derive(Serialize, Deserialize, Debug)] struct CmdResult { @@ -38,6 +40,8 @@ pub struct ListenAddress { #[tokio::main] async fn main() -> Result<(), Box> { env_logger::init(); + + let _: i64 = portalcall::portal_call1(INDIV_DEBUG_PORTALCALL_MAGIC, 0); let args = ListenAddress::from_args(); let cid = args.cid.unwrap_or(libc::VMADDR_CID_ANY); let addr = VsockAddr::new(cid, args.port); diff --git a/src/portalcall.rs b/src/portalcall.rs new file mode 100644 index 0000000..7d964b4 --- /dev/null +++ b/src/portalcall.rs @@ -0,0 +1,51 @@ +use libc::{syscall, SYS_sendto}; + +#[cfg(target_pointer_width = "64")] +const PORTAL_MAGIC: libc::c_ulong = 0xc1d1e1f1; +#[cfg(not(target_pointer_width = "64"))] +const PORTAL_MAGIC: libc::c_uint = 0xc1d1e1f1; + +#[inline] +pub fn portal_call(user_magic: u64, argc: i32, args: &[u64]) -> i64 { + unsafe { + syscall( + SYS_sendto, + PORTAL_MAGIC, + user_magic, + argc, + args.as_ptr(), + 0, + 0, + ) as i64 + } +} + +#[inline] +#[allow(dead_code)] +pub fn portal_call1(user_magic: u64, a1: u64) -> i64 { + portal_call(user_magic, 1, &[a1]) +} + +#[inline] +#[allow(dead_code)] +pub fn portal_call2(user_magic: u64, a1: u64, a2: u64) -> i64 { + portal_call(user_magic, 2, &[a1, a2]) +} + +#[inline] +#[allow(dead_code)] +pub fn portal_call3(user_magic: u64, a1: u64, a2: u64, a3: u64) -> i64 { + portal_call(user_magic, 3, &[a1, a2, a3]) +} + +#[inline] +#[allow(dead_code)] +pub fn portal_call4(user_magic: u64, a1: u64, a2: u64, a3: u64, a4: u64) -> i64 { + portal_call(user_magic, 4, &[a1, a2, a3, a4]) +} + +#[inline] +#[allow(dead_code)] +pub fn portal_call5(user_magic: u64, a1: u64, a2: u64, a3: u64, a4: u64, a5: u64) -> i64 { + portal_call(user_magic, 5, &[a1, a2, a3, a4, a5]) +}