#[cfg(windows)]
#[allow(dead_code)]
const SYS_CURL: &str = "C:\\Windows\\System32\\curl.exe";
#[cfg(not(windows))]
#[allow(dead_code)]
const SYS_CURL: &str = "curl";
#[allow(dead_code)]
fn _helix_allowed(var: &str, what: &str) -> bool {
let ok = std::env::var(var).map(|v| v == "1").unwrap_or(false);
if !ok {
eprintln!("helix: BLOCKED {} -- permission denied (set {}=1 to allow; `hxc run` allows by default, a `hxc build`/`export-rust` binary does not)", what, var);
}
ok
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_exec(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_exec(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_RUN", "process execution") {
std::process::exit(13);
}
c
}
#[cfg(windows)]
#[allow(dead_code)]
fn _nw_net(mut c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
use std::os::windows::process::CommandExt;
c.creation_flags(0x08000000);
c
}
#[cfg(not(windows))]
#[allow(dead_code)]
fn _nw_net(c: std::process::Command) -> std::process::Command {
if !_helix_allowed("HELIX_ALLOW_NET", "network access") {
std::process::exit(13);
}
c
}
#[path = "../../src/check/json.rs"]
#[allow(dead_code)]
mod json;
#[path = "../../src/check/kernel.rs"]
#[allow(dead_code)]
mod kernel;
#[path = "../../src/check/digest.rs"]
#[allow(dead_code)]
mod digest;
#[path = "../../src/check/receipt.rs"]
#[allow(dead_code)]
mod receipt;
use std::cell::RefCell;
thread_local! { static OUTPUT: RefCell<Vec<u8>> = const { RefCell::new(Vec::new()) }; }
#[no_mangle]
pub extern "C" fn alloc(n: usize) -> *mut u8 {
let mut b = Vec::<u8>::with_capacity(n.max(1));
let p = b.as_mut_ptr();
std::mem::forget(b);
p
}
#[no_mangle]
pub unsafe extern "C" fn release(p: *mut u8, n: usize) {
drop(Vec::from_raw_parts(p, 0, n.max(1)));
}
#[no_mangle]
pub unsafe extern "C" fn check(p: *const u8, n: usize, mode: u32) -> usize {
let bytes = std::slice::from_raw_parts(p, n);
let (out, _) = match mode {
0 => kernel::evaluate(kernel::Mode::Run, bytes),
1 => kernel::evaluate(kernel::Mode::Validate, bytes),
2 => kernel::evaluate(kernel::Mode::Explain, bytes),
3 => receipt::create(bytes),
4 => receipt::replay(bytes),
_ => return 0,
};
OUTPUT.with(|o| {
*o.borrow_mut() = out.into_bytes();
o.borrow().len()
})
}
#[no_mangle]
pub extern "C" fn out_ptr() -> *const u8 {
OUTPUT.with(|o| o.borrow().as_ptr())
}