Fix thread_local macro
diff --git a/sgx_tstd/src/thread/local.rs b/sgx_tstd/src/thread/local.rs
index 6319514..430360d 100644
--- a/sgx_tstd/src/thread/local.rs
+++ b/sgx_tstd/src/thread/local.rs
@@ -143,13 +143,13 @@
);
}
+#[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 @@
}
}
- #[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 @@
#[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 025c4a0..3f8600c 100644
--- a/sgx_types/src/function.rs
+++ b/sgx_types/src/function.rs
@@ -1013,7 +1013,7 @@
/* 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 @@
/* 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;