Initial commit

This commit is contained in:
2024-04-03 17:00:29 +02:00
commit c12ae64d78
5 changed files with 92 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/target

16
Cargo.lock generated Normal file
View File

@@ -0,0 +1,16 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "agent_harness"
version = "0.1.0"
dependencies = [
"libc",
]
[[package]]
name = "libc"
version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"

9
Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "agent_harness"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libc = "0.2.153"

16
shell.nix Normal file
View File

@@ -0,0 +1,16 @@
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
let
agent_src = fetchgit {
url = "https://gitea.rixxc.de/rixxc/x25519_agent.git";
rev = "eafc5e9df6b316e0f9804b73e43d25f72f2c1d79";
hash = "sha256-PTSFEOSS3dKr6g+y2z/KN1lE5md+D25CKVmCc2YpigI=";
};
agent = callPackage "${agent_src}/default.nix" { };
in
pkgs.mkShell {
name = "agent-harness";
buildInputs = [ agent ];
}

50
src/main.rs Normal file
View File

@@ -0,0 +1,50 @@
use libc::{c_int, c_void, mmap, MAP_FAILED, MAP_SHARED, PROT_READ, PROT_WRITE};
use std::{env, ptr};
const SHARED_MEMORY_SIZE: usize = 1024;
#[link(name = "agent")]
extern "C" {
fn agent_start(shared_memory: *mut u8, sync_memory: *mut u8);
}
fn main() {
let args: Vec<String> = env::args().collect();
let shared_fd: c_int = args[1]
.parse()
.expect("Please provide a valid file descriptor as first argument");
let sync_fd: c_int = args[2]
.parse()
.expect("Please provide a valid file descriptor as first argument");
let shared_memory = unsafe {
mmap(
ptr::null_mut() as *mut c_void,
SHARED_MEMORY_SIZE,
PROT_READ | PROT_WRITE,
MAP_SHARED,
shared_fd,
0,
)
} as *mut u8;
assert_ne!(shared_memory, MAP_FAILED as *mut u8);
let sync_memory = unsafe {
mmap(
ptr::null_mut() as *mut c_void,
SHARED_MEMORY_SIZE,
PROT_READ | PROT_WRITE,
MAP_SHARED,
sync_fd,
0,
)
} as *mut u8;
assert_ne!(sync_memory, MAP_FAILED as *mut u8);
println!("Starting agent...");
unsafe {
agent_start(shared_memory, sync_memory);
}
}