@@ -25,7 +25,7 @@ use linux_raw_sys::general::{
2525} ;
2626#[ cfg( feature = "runtime" ) ]
2727use linux_raw_sys:: general:: {
28- AT_EGID , AT_ENTRY , AT_EUID , AT_GID , AT_PHDR , AT_PHENT , AT_PHNUM , AT_SECURE , AT_UID ,
28+ AT_EGID , AT_ENTRY , AT_EUID , AT_GID , AT_PHDR , AT_PHENT , AT_PHNUM , AT_RANDOM , AT_SECURE , AT_UID ,
2929} ;
3030
3131#[ cfg( feature = "param" ) ]
@@ -145,6 +145,19 @@ pub(crate) fn entry() -> usize {
145145 entry
146146}
147147
148+ #[ cfg( feature = "runtime" ) ]
149+ #[ inline]
150+ pub ( crate ) fn random ( ) -> * const [ u8 ; 16 ] {
151+ let mut random = RANDOM . load ( Relaxed ) ;
152+
153+ if random. is_null ( ) {
154+ init_auxv ( ) ;
155+ random = RANDOM . load ( Relaxed ) ;
156+ }
157+
158+ random
159+ }
160+
148161static PAGE_SIZE : AtomicUsize = AtomicUsize :: new ( 0 ) ;
149162static CLOCK_TICKS_PER_SECOND : AtomicUsize = AtomicUsize :: new ( 0 ) ;
150163static HWCAP : AtomicUsize = AtomicUsize :: new ( 0 ) ;
@@ -161,6 +174,8 @@ static PHENT: AtomicUsize = AtomicUsize::new(0);
161174static PHNUM : AtomicUsize = AtomicUsize :: new ( 0 ) ;
162175#[ cfg( feature = "runtime" ) ]
163176static ENTRY : AtomicUsize = AtomicUsize :: new ( 0 ) ;
177+ #[ cfg( feature = "runtime" ) ]
178+ static RANDOM : AtomicPtr < [ u8 ; 16 ] > = AtomicPtr :: new ( null_mut ( ) ) ;
164179
165180#[ cfg( feature = "alloc" ) ]
166181fn pr_get_auxv ( ) -> crate :: io:: Result < Vec < u8 > > {
@@ -296,6 +311,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
296311 let mut gid = None ;
297312 #[ cfg( feature = "runtime" ) ]
298313 let mut egid = None ;
314+ #[ cfg( feature = "runtime" ) ]
315+ let mut random = null_mut ( ) ;
299316
300317 for Elf_auxv_t { a_type, a_val } in aux_iter {
301318 match a_type as _ {
@@ -332,6 +349,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
332349 AT_PHENT => phent = a_val as usize ,
333350 #[ cfg( feature = "runtime" ) ]
334351 AT_ENTRY => entry = a_val as usize ,
352+ #[ cfg( feature = "runtime" ) ]
353+ AT_RANDOM => random = check_raw_pointer :: < [ u8 ; 16 ] > ( a_val as * mut _ ) ?. as_ptr ( ) ,
335354
336355 AT_NULL => break ,
337356 _ => ( ) ,
@@ -365,6 +384,8 @@ unsafe fn init_from_aux_iter(aux_iter: impl Iterator<Item = Elf_auxv_t>) -> Opti
365384 PHNUM . store ( phnum, Relaxed ) ;
366385 #[ cfg( feature = "runtime" ) ]
367386 ENTRY . store ( entry, Relaxed ) ;
387+ #[ cfg( feature = "runtime" ) ]
388+ RANDOM . store ( random, Relaxed ) ;
368389
369390 Some ( ( ) )
370391}
0 commit comments