|
| 1 | +#![forbid(fuzzy_provenance_casts)] |
| 2 | + |
1 | 3 | use fortanix_sgx_abi::{Error, RESULT_SUCCESS};
|
2 | 4 |
|
3 | 5 | use crate::collections::HashMap;
|
4 | 6 | use crate::error::Error as StdError;
|
5 | 7 | use crate::ffi::{OsStr, OsString};
|
6 | 8 | use crate::marker::PhantomData;
|
7 | 9 | use crate::path::{self, PathBuf};
|
8 |
| -use crate::sync::atomic::{AtomicUsize, Ordering}; |
9 |
| -use crate::sync::{Mutex, Once}; |
| 10 | +use crate::sync::{Mutex, OnceLock}; |
10 | 11 | use crate::sys::{decode_error_kind, sgx_ineffective, unsupported};
|
11 | 12 | use crate::{fmt, io, str, vec};
|
12 | 13 |
|
@@ -75,21 +76,15 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
75 | 76 |
|
76 | 77 | #[cfg_attr(test, linkage = "available_externally")]
|
77 | 78 | #[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os3ENVE")]
|
78 |
| -static ENV: AtomicUsize = AtomicUsize::new(0); |
79 |
| -#[cfg_attr(test, linkage = "available_externally")] |
80 |
| -#[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os8ENV_INITE")] |
81 |
| -static ENV_INIT: Once = Once::new(); |
| 79 | +static ENV: OnceLock<EnvStore> = OnceLock::new(); |
82 | 80 | type EnvStore = Mutex<HashMap<OsString, OsString>>;
|
83 | 81 |
|
84 | 82 | fn get_env_store() -> Option<&'static EnvStore> {
|
85 |
| - unsafe { (ENV.load(Ordering::Relaxed) as *const EnvStore).as_ref() } |
| 83 | + ENV.get() |
86 | 84 | }
|
87 | 85 |
|
88 | 86 | fn create_env_store() -> &'static EnvStore {
|
89 |
| - ENV_INIT.call_once(|| { |
90 |
| - ENV.store(Box::into_raw(Box::new(EnvStore::default())) as _, Ordering::Relaxed) |
91 |
| - }); |
92 |
| - unsafe { &*(ENV.load(Ordering::Relaxed) as *const EnvStore) } |
| 87 | + ENV.get_or_init(|| EnvStore::default()) |
93 | 88 | }
|
94 | 89 |
|
95 | 90 | pub struct Env {
|
|
0 commit comments