pub fn evaluate<B, I, O>(binary: B, input: &I) -> Result<O>
where
    B: AsRef<OsStr>,
    I: Serialize<BinaryProtocolSerializer<SizeCounter>>
        + Serialize<BinaryProtocolSerializer<BytesMut>>,
    O: Deserialize<BinaryProtocolDeserializer<Cursor<Bytes>>>,
{
    let input = serialize(input);

    let mut stdin = unsafe {
        File::from_raw_fd(
            nix::sys::memfd::memfd_create(
                &CString::new("input")
                    .expect("creating cstr can never fail with this static input"),
                nix::sys::memfd::MemFdCreateFlag::empty(),
            )
            .map_err(|e| Error::PrepareInput(e.into()))?,
        )
    };
    stdin.write_all(&input).map_err(Error::PrepareInput)?;
    stdin.rewind().map_err(Error::PrepareInput)?;

    let output = sandbox(binary, Default::default())
        .map_err(Error::Sandbox)?
        .stdin(stdin)
        .output()
        .map_err(Error::Spawn)?;

    if !output.status.success() {
        return Err(Error::Eval {
            status: output.status,
            stdout: String::from_utf8_lossy(&output.stdout).to_string(),
            stderr: String::from_utf8_lossy(&output.stderr).to_string(),
        });
    }

    deserialize(output.stdout).map_err(Error::Deserialize)
}
/// Run a MetalOS generator in a sandboxed environment. This handles spawning
/// the process, handing it the input struct via binary thrift and deserializing
/// the output.
Run a MetalOS generator in a sandboxed environment. This handles spawning
the process, handing it the input struct via binary thrift and deserializing
the output.
Run a MetalOS generator in a sandboxed environment . This handles spawning the process handing it the input struct via binary thrift and deserializing the output .
pub fn evaluate<B, I, O>(binary: B, input: &I) -> Result<O>
where
    B: AsRef<OsStr>,
    I: Serialize<BinaryProtocolSerializer<SizeCounter>>
        + Serialize<BinaryProtocolSerializer<BytesMut>>,
    O: Deserialize<BinaryProtocolDeserializer<Cursor<Bytes>>>,
{
    let input = serialize(input);
    let mut stdin = unsafe {
        File::from_raw_fd(
            nix::sys::memfd::memfd_create(
                &CString::new("input")
                    .expect("creating cstr can never fail with this static input"),
                nix::sys::memfd::MemFdCreateFlag::empty(),
            )
            .map_err(|e| Error::PrepareInput(e.into()))?,
        )
    };
    stdin.write_all(&input).map_err(Error::PrepareInput)?;
    stdin.rewind().map_err(Error::PrepareInput)?;
    let output = sandbox(binary, Default::default())
        .map_err(Error::Sandbox)?
        .stdin(stdin)
        .output()
        .map_err(Error::Spawn)?;
    if !output.status.success() {
        return Err(Error::Eval {
            status: output.status,
            stdout: String::from_utf8_lossy(&output.stdout).to_string(),
            stderr: String::from_utf8_lossy(&output.stderr).to_string(),
        });
    }
    deserialize(output.stdout).map_err(Error::Deserialize)
}
pub fn evaluate < B , I , O > ( binary : B , input : & I ) -> Result < O > where B : AsRef < OsStr > , I : Serialize < BinaryProtocolSerializer < SizeCounter > > + Serialize < BinaryProtocolSerializer < BytesMut > > , O : Deserialize < BinaryProtocolDeserializer < Cursor < Bytes > > > , { let input = serialize ( input ) ; let mut stdin = unsafe { File :: from_raw_fd ( nix :: sys :: memfd :: memfd_create ( & CString :: new ( " " ) . expect ( " " ) , nix :: sys :: memfd :: MemFdCreateFlag :: empty ( ) , ) . map_err ( | e | Error :: PrepareInput ( e . into ( ) ) ) ? , ) } ; stdin . write_all ( & input ) . map_err ( Error :: PrepareInput ) ? ; stdin . rewind ( ) . map_err ( Error :: PrepareInput ) ? ; let output = sandbox ( binary , Default :: default ( ) ) . map_err ( Error :: Sandbox ) ? . stdin ( stdin ) . output ( ) . map_err ( Error :: Spawn ) ? ; if ! output . status . success ( ) { return Err ( Error :: Eval { status : output . status , stdout : String :: from_utf8_lossy ( & output . stdout ) . to_string ( ) , stderr : String :: from_utf8_lossy ( & output . stderr ) . to_string ( ) , } ) ; } deserialize ( output . stdout ) . map_err ( Error :: Deserialize ) }
Run a MetalOS generator in a sandboxed environment.
Run a MetalOS generator in a sandboxed environment .
binary
B
input
&I
binary
B
input
&I