@@ -19,18 +19,9 @@ pub(crate) static GLOBAL_ACTIVITY_SEED: LazyLock<[u8; 16]> = LazyLock::new(|| {
19
19
data
20
20
} ) ;
21
21
22
- static EVENT_METADATA : LazyLock < Box < [ ParsedEventMetadata ] > > = LazyLock :: new ( || {
22
+ fn process_static_metadata ( ) -> Box < [ ParsedEventMetadata ] > {
23
23
// The array of pointers are in a mutable section and can be sorted/deduped, but they are pointing to read-only static data
24
24
25
- // unsafe is necessary on Linux but not Windows
26
- #[ allow( unused_unsafe) ]
27
- // SAFETY These aren't "real" extern statics, they are magic statics generated by gcc/llvm that cannot be mutated by other threads.
28
- unsafe {
29
- if crate :: native:: _start__etw_kw == crate :: native:: MAGIC_STATICS_SENTINEL {
30
- return Box :: new ( [ ] ) ;
31
- }
32
- }
33
-
34
25
let start =
35
26
& raw const crate :: native:: _start__etw_kw as * mut * const EventMetadata ;
36
27
let stop =
@@ -105,7 +96,13 @@ static EVENT_METADATA: LazyLock<Box<[ParsedEventMetadata]>> = LazyLock::new(|| {
105
96
let mut sorted = vec. into_boxed_slice ( ) ;
106
97
sorted. sort_unstable_by ( |a, b| b. cmp ( a) ) ;
107
98
sorted
108
- } ) ;
99
+ }
100
+
101
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ]
102
+ static EVENT_METADATA : LazyLock < Box < [ ParsedEventMetadata ] > > = LazyLock :: new ( process_static_metadata) ;
103
+
104
+ #[ cfg( not( any( target_os = "windows" , target_os = "linux" ) ) ) ]
105
+ static EVENT_METADATA : [ ParsedEventMetadata ; 0 ] = [ ] ;
109
106
110
107
impl core:: cmp:: PartialEq for ParsedEventMetadata {
111
108
fn eq ( & self , other : & Self ) -> bool {
@@ -223,15 +220,10 @@ mod test {
223
220
sum += event. kw ;
224
221
}
225
222
226
- #[ allow( unused_unsafe) ]
227
- let expected = unsafe {
228
- if crate :: native:: _start__etw_kw != crate :: native:: MAGIC_STATICS_SENTINEL {
229
- 55
230
- }
231
- else {
232
- 0
233
- }
234
- } ;
223
+ #[ cfg( any( target_os = "windows" , target_os = "linux" ) ) ]
224
+ let expected = 55 ;
225
+ #[ cfg( not( any( target_os = "windows" , target_os = "linux" ) ) ) ]
226
+ let expected = 0 ;
235
227
236
228
assert_eq ! ( sum, expected) ;
237
229
}
0 commit comments