enclave_runner/library.rs
1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7use std::sync::Arc;
8
9use anyhow::Error;
10
11type LibraryFn = Arc<dyn Fn(u64, u64, u64, u64, u64) -> Result<(u64, u64), Error>>;
12
13pub struct Library {
14 f: LibraryFn
15}
16
17impl From<LibraryFn> for Library {
18 fn from(f: LibraryFn) -> Self {
19 Library {
20 f
21 }
22 }
23}
24
25impl Library {
26 /// # Safety
27 ///
28 /// The caller must ensure that the parameters passed-in match what the
29 /// enclave is expecting.
30 pub unsafe fn call(
31 &self,
32 p1: u64,
33 p2: u64,
34 p3: u64,
35 p4: u64,
36 p5: u64,
37 ) -> Result<(u64, u64), Error> {
38 (self.f)(p1, p2, p3, p4, p5)
39 }
40}