This is an automated email from the ASF dual-hosted git repository. rduan pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-teaclave-sgx-sdk.git
commit a5bcd783d6e0daf92b115d7be1d2da09e0cb78e0 Author: volcano <[email protected]> AuthorDate: Sun Jun 19 20:44:28 2022 +0800 Fix thread_local macro --- sgx_tstd/src/thread/local.rs | 53 +++++++++++++++++++++++++++++++++++++------- sgx_types/src/function.rs | 4 ++-- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/sgx_tstd/src/thread/local.rs b/sgx_tstd/src/thread/local.rs index 63195145..430360df 100644 --- a/sgx_tstd/src/thread/local.rs +++ b/sgx_tstd/src/thread/local.rs @@ -143,13 +143,13 @@ macro_rules! thread_local { ); } +#[cfg(not(feature = "thread"))] #[macro_export] #[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] #[allow_internal_unsafe] macro_rules! __thread_local_inner { // used to generate the `LocalKey` value for const-initialized thread locals (@key $t:ty, const $init:expr) => {{ - #[cfg(not(feature = "thread"))] #[inline] // see comments below unsafe fn __getit() -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { const INIT_EXPR: $t = $init; @@ -165,7 +165,49 @@ macro_rules! __thread_local_inner { } } - #[cfg(feature = "thread")] + unsafe { + $crate::thread::LocalKey::new(__getit) + } + }}; + + // used to generate the `LocalKey` value for `thread_local!` + (@key $t:ty, $init:expr) => { + { + #[inline] + fn __init() -> $t { $init } + + #[inline] + unsafe fn __getit() -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { + #[thread_local] + static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = + $crate::thread::__StaticLocalKeyInner::new(); + + // FIXME: remove the #[allow(...)] marker when macros don't + // raise warning for missing/extraneous unsafe blocks anymore. + // See https://github.com/rust-lang/rust/issues/74838. + #[allow(unused_unsafe)] + unsafe { __KEY.get(__init) } + } + + unsafe { + $crate::thread::LocalKey::new(__getit) + } + } + }; + ($(#[$attr:meta])* $vis:vis $name:ident, $t:ty, $($init:tt)*) => { + $(#[$attr])* $vis const $name: $crate::thread::LocalKey<$t> = + $crate::__thread_local_inner!(@key $t, $($init)*); + } +} + +#[cfg(feature = "thread")] +#[macro_export] +#[allow_internal_unstable(thread_local_internals, cfg_target_thread_local, thread_local)] +#[allow_internal_unsafe] +macro_rules! __thread_local_inner { + // used to generate the `LocalKey` value for const-initialized thread locals + (@key $t:ty, const $init:expr) => {{ + #[inline] unsafe fn __getit() -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { const INIT_EXPR: $t = $init; @@ -233,13 +275,8 @@ macro_rules! __thread_local_inner { #[inline] fn __init() -> $t { $init } + #[inline] unsafe fn __getit() -> $crate::result::Result<&'static $t, $crate::thread::AccessError> { - #[cfg(not(feature = "thread"))] - #[thread_local] - static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = - $crate::thread::__StaticLocalKeyInner::new(); - - #[cfg(feature = "thread")] #[thread_local] static __KEY: $crate::thread::__FastLocalKeyInner<$t> = $crate::thread::__FastLocalKeyInner::new(); diff --git a/sgx_types/src/function.rs b/sgx_types/src/function.rs index 025c4a04..3f8600c6 100644 --- a/sgx_types/src/function.rs +++ b/sgx_types/src/function.rs @@ -1013,7 +1013,7 @@ extern "C" { /* intel DCAP 1.13 */ pub fn sgx_ql_get_quote_verification_collateral_with_params( fmspc: *const uint8_t, - fmspc_size: u16, + fmspc_size: uint16_t, pck_ra: *const c_char, custom_param: *const c_void, custom_param_length: uint16_t, @@ -1025,7 +1025,7 @@ extern "C" { /* intel DCAP 1.14 */ pub fn tdx_ql_get_quote_verification_collateral( fmspc: *const uint8_t, - fmspc_size: u16, + fmspc_size: uint16_t, pck_ra: *const c_char, pp_quote_collateral: *mut *mut tdx_ql_qve_collateral_t, ) -> sgx_quote3_error_t; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
