From 56fa3ed34941b2451701c217ad5e0f7ac659ed48 Mon Sep 17 00:00:00 2001 From: nicholastao Date: Tue, 25 Mar 2025 15:13:02 +0800 Subject: [PATCH] test random patch --- glibc.spec | 3 ++- random.patch | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 random.patch diff --git a/glibc.spec b/glibc.spec index eb3c193..5ebcb3d 100644 --- a/glibc.spec +++ b/glibc.spec @@ -71,7 +71,7 @@ ############################################################################## Name: glibc Version: 2.34 -Release: 166 +Release: 167 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -318,6 +318,7 @@ Patch226: backport-elf-Introduce-_dl_relocate_object_no_relro.patch Patch227: backport-elf-Switch-to-main-malloc-after-final-ld.so-self-rel.patch Patch228: AArch64-Optimize-memcmp.patch Patch229: backport-CVE-2025-0395-underallocation-of-abort_msg_s-struct.patch +Patch229: random.patch Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch Patch9001: delete-no-hard-link-to-avoid-all_language-package-to.patch diff --git a/random.patch b/random.patch new file mode 100644 index 0000000..b8bb47f --- /dev/null +++ b/random.patch @@ -0,0 +1,47 @@ +diff --git a/stdlib/rand.c b/stdlib/rand.c +index c250c065e4..f199dbd65f 100644 +--- a/stdlib/rand.c ++++ b/stdlib/rand.c +@@ -19,10 +19,42 @@ + + #undef rand + ++#ifdef __aarch64__ ++// A global variable to indicate whether rndr instruction is supported ++static int rndr_supported = 0; ++// A function prototype to check rndr support ++static void check_rndr_support (void) __attribute__ ((constructor)); ++#endif + + /* Return a random integer between 0 and RAND_MAX. */ + int + rand (void) + { ++ // Use armv8.5 rndr instruction if supported ++#ifdef __aarch64__ ++ if (rndr_supported) { ++ unsigned int r; ++ asm volatile("mrs %0, s3_3_c2_c4_0" : "=r" (r)); ++ // Discard the least random bit ++ r >>=1; ++ return (int) r; ++ } ++#endif + return (int) __random (); + } ++ ++#ifdef __aarch64__ ++// A function to check rndr support and set the global variable accordingly ++static void ++check_rndr_support (void) ++{ ++ unsigned long isar0; ++ // Read the ID_AA64ISAR0_EL1 register to check the rndr feature ++ asm volatile("mrs %0, id_aa64isar0_el1" : "=r" (isar0)); ++ // Check the bits [63:60] for the rndr feature ++ if ((isar0 >> 60) & 0xf) { ++ // Set the global variable to indicate rndr support ++ rndr_supported = 1; ++ } ++} + -- Gitee