@@ -68,6 +68,7 @@ pub struct EnclaveBuilder<'a> {
6868 load_and_sign : Option < Box < dyn FnOnce ( Signer ) -> Result < Sigstruct , anyhow:: Error > > > ,
6969 hash_enclave : Option < Box < dyn FnOnce ( & mut EnclaveSource < ' _ > ) -> Result < EnclaveHash , anyhow:: Error > > > ,
7070 forward_panics : bool ,
71+ force_time_usercalls : bool ,
7172 cmd_args : Option < Vec < Vec < u8 > > > ,
7273}
7374
@@ -145,6 +146,7 @@ impl<'a> EnclaveBuilder<'a> {
145146 load_and_sign : None ,
146147 hash_enclave : None ,
147148 forward_panics : false ,
149+ force_time_usercalls : true , // By default, keep the old behavior of always doing a usercall on an insecure_time call
148150 cmd_args : None ,
149151 } ;
150152
@@ -266,6 +268,16 @@ impl<'a> EnclaveBuilder<'a> {
266268 self
267269 }
268270
271+ /// SGXv2 platforms allow enclaves to use the `rdtsc` instruction. This can speed up
272+ /// performance significantly as enclave no longer need to call out to userspace to request the
273+ /// current time. Unfortunately, older enclaves are not compatible with new enclave runners.
274+ /// Also, sometimes the behavior of enclaves always calling out the userspace needs to be
275+ /// simulated. This setting enforces the old behavior.
276+ pub fn force_insecure_time_usercalls ( & mut self , force_time_usercalls : bool ) -> & mut Self {
277+ self . force_time_usercalls = force_time_usercalls;
278+ self
279+ }
280+
269281 fn initialized_args_mut ( & mut self ) -> & mut Vec < Vec < u8 > > {
270282 self . cmd_args . get_or_insert_with ( || vec ! [ b"enclave" . to_vec( ) ] )
271283 }
@@ -309,7 +321,7 @@ impl<'a> EnclaveBuilder<'a> {
309321 fn load < T : Load > (
310322 mut self ,
311323 loader : & mut T ,
312- ) -> Result < ( Vec < ErasedTcs > , * mut c_void , usize , bool ) , anyhow:: Error > {
324+ ) -> Result < ( Vec < ErasedTcs > , * mut c_void , usize , bool , bool ) , anyhow:: Error > {
313325 let signature = match self . signature {
314326 Some ( sig) => sig,
315327 None => self
@@ -320,6 +332,7 @@ impl<'a> EnclaveBuilder<'a> {
320332 let miscselect = self . miscselect . unwrap_or ( signature. miscselect ) ;
321333 let mapping = loader. load ( & mut self . enclave , & signature, attributes, miscselect) ?;
322334 let forward_panics = self . forward_panics ;
335+ let force_time_usercalls = self . force_time_usercalls ;
323336 if mapping. tcss . is_empty ( ) {
324337 unimplemented ! ( )
325338 }
@@ -328,6 +341,7 @@ impl<'a> EnclaveBuilder<'a> {
328341 mapping. info . address ( ) ,
329342 mapping. info . size ( ) ,
330343 forward_panics,
344+ force_time_usercalls,
331345 ) )
332346 }
333347
@@ -336,7 +350,7 @@ impl<'a> EnclaveBuilder<'a> {
336350 let args = self . cmd_args . take ( ) . unwrap_or_default ( ) ;
337351 let c = self . usercall_ext . take ( ) ;
338352 self . load ( loader)
339- . map ( |( t, a, s, fp) | Command :: internal_new ( t, a, s, c, fp, args) )
353+ . map ( |( t, a, s, fp, dti ) | Command :: internal_new ( t, a, s, c, fp, dti , args) )
340354 }
341355
342356 /// Panics if you have previously called [`arg`] or [`args`].
@@ -349,6 +363,6 @@ impl<'a> EnclaveBuilder<'a> {
349363 }
350364 let c = self . usercall_ext . take ( ) ;
351365 self . load ( loader)
352- . map ( |( t, a, s, fp) | Library :: internal_new ( t, a, s, c, fp) )
366+ . map ( |( t, a, s, fp, dti ) | Library :: internal_new ( t, a, s, c, fp, dti ) )
353367 }
354368}
0 commit comments