|
| 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}; |
| 10 | +use crate::sync::atomic::{AtomicPtr, Ordering}; |
9 | 11 | use crate::sync::{Mutex, Once};
|
10 | 12 | use crate::sys::{decode_error_kind, sgx_ineffective, unsupported};
|
11 |
| -use crate::{fmt, io, str, vec}; |
| 13 | +use crate::{fmt, io, ptr, str, vec}; |
12 | 14 |
|
13 | 15 | pub fn errno() -> i32 {
|
14 | 16 | RESULT_SUCCESS
|
@@ -75,21 +77,20 @@ pub fn current_exe() -> io::Result<PathBuf> {
|
75 | 77 |
|
76 | 78 | #[cfg_attr(test, linkage = "available_externally")]
|
77 | 79 | #[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os3ENVE")]
|
78 |
| -static ENV: AtomicUsize = AtomicUsize::new(0); |
| 80 | +static ENV: AtomicPtr<EnvStore> = AtomicPtr::new(ptr::null_mut()); |
79 | 81 | #[cfg_attr(test, linkage = "available_externally")]
|
80 | 82 | #[unsafe(export_name = "_ZN16__rust_internals3std3sys3sgx2os8ENV_INITE")]
|
81 | 83 | static ENV_INIT: Once = Once::new();
|
82 | 84 | type EnvStore = Mutex<HashMap<OsString, OsString>>;
|
83 | 85 |
|
84 | 86 | fn get_env_store() -> Option<&'static EnvStore> {
|
85 |
| - unsafe { (ENV.load(Ordering::Relaxed) as *const EnvStore).as_ref() } |
| 87 | + unsafe { ENV.load(Ordering::Relaxed).as_ref() } |
86 | 88 | }
|
87 | 89 |
|
88 | 90 | 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) } |
| 91 | + ENV_INIT |
| 92 | + .call_once(|| ENV.store(Box::into_raw(Box::new(EnvStore::default())), Ordering::Relaxed)); |
| 93 | + unsafe { &*ENV.load(Ordering::Relaxed) } |
93 | 94 | }
|
94 | 95 |
|
95 | 96 | pub struct Env {
|
|
0 commit comments