|
8 | 8 |
|
9 | 9 | //! Provides APIs to disable VDSOs at runtime. |
10 | 10 | use std::collections::HashMap; |
| 11 | +use std::sync::LazyLock; |
11 | 12 |
|
12 | 13 | use goblin::elf::Elf; |
13 | | -use lazy_static::lazy_static; |
14 | 14 | use nix::sys::mman::ProtFlags; |
15 | 15 | use nix::unistd; |
16 | 16 | use reverie::Error; |
@@ -168,33 +168,31 @@ fn align_up(value: usize, alignment: usize) -> usize { |
168 | 168 | (value + alignment - 1) & alignment.wrapping_neg() |
169 | 169 | } |
170 | 170 |
|
171 | | -lazy_static! { |
172 | | - static ref VDSO_PATCH_INFO: HashMap<&'static str, (u64, usize, &'static [u8])> = { |
173 | | - let info = vdso_get_symbols_info(); |
174 | | - let mut res = HashMap::new(); |
175 | | - |
176 | | - for (k, v) in VDSO_SYMBOLS { |
177 | | - if let Some(&(base, size)) = info.get(*k) { |
178 | | - // NOTE: There is padding at the end of every VDSO entry to |
179 | | - // bring it up to a 16-byte size alignment. The dynamic symbol |
180 | | - // table doesn't report the aligned size, so we must do the same |
181 | | - // alignment here. For example, some VDSO entries might only be |
182 | | - // 5 bytes, but they have padding to align them up to 16 bytes. |
183 | | - let aligned_size = align_up(size, 16); |
184 | | - assert!( |
185 | | - v.len() <= aligned_size, |
186 | | - "vdso symbol {}'s real size is {} bytes, but trying to replace it with {} bytes", |
187 | | - k, |
188 | | - size, |
189 | | - v.len() |
190 | | - ); |
191 | | - res.insert(*k, (base, aligned_size, *v)); |
192 | | - } |
| 171 | +static VDSO_PATCH_INFO: LazyLock<HashMap<&str, (u64, usize, &[u8])>> = LazyLock::new(|| { |
| 172 | + let info = vdso_get_symbols_info(); |
| 173 | + let mut res = HashMap::new(); |
| 174 | + |
| 175 | + for (k, v) in VDSO_SYMBOLS { |
| 176 | + if let Some(&(base, size)) = info.get(*k) { |
| 177 | + // NOTE: There is padding at the end of every VDSO entry to |
| 178 | + // bring it up to a 16-byte size alignment. The dynamic symbol |
| 179 | + // table doesn't report the aligned size, so we must do the same |
| 180 | + // alignment here. For example, some VDSO entries might only be |
| 181 | + // 5 bytes, but they have padding to align them up to 16 bytes. |
| 182 | + let aligned_size = align_up(size, 16); |
| 183 | + assert!( |
| 184 | + v.len() <= aligned_size, |
| 185 | + "vdso symbol {}'s real size is {} bytes, but trying to replace it with {} bytes", |
| 186 | + k, |
| 187 | + size, |
| 188 | + v.len() |
| 189 | + ); |
| 190 | + res.insert(*k, (base, aligned_size, *v)); |
193 | 191 | } |
| 192 | + } |
194 | 193 |
|
195 | | - res |
196 | | - }; |
197 | | -} |
| 194 | + res |
| 195 | +}); |
198 | 196 |
|
199 | 197 | // get vdso symbols offset/size from current process |
200 | 198 | // assuming vdso binary is the same for all processes |
|
0 commit comments