summaryrefslogtreecommitdiff
path: root/perl.h
diff options
context:
space:
mode:
authorYves Orton <demerphq@gmail.com>2022-03-06 09:42:14 +0100
committerYves Orton <demerphq@gmail.com>2022-03-10 03:22:33 +0100
commitc3c9d6b15f57fdce79988a553671a1ceb54c0f10 (patch)
treeedf6ddb1f711af36059bea8ec21790a0933d68a5 /perl.h
parent8a35994ac8fcc50aaed538b7625ba79635683630 (diff)
downloadperl-c3c9d6b15f57fdce79988a553671a1ceb54c0f10.tar.gz
hv.c - rework PL_hash_rand_bits update logic, add tests, -Dh debug mode
This moves all run time mutations of PL_hash_rand_bits into a set of macros which allow us to debug what is happening. It also moves away from our poor mans RNG based on mixing in various sources of data as we go and switches to using an XORSHIFT RNG for generating the random bits. This particular RNG is very efficient, using three xor operations and three shift operations, so it shouldn't hurt us to use it. As a bonus it also removes the conditional logic involved, as we use seed() to initialize things at the very beginning when we are running under RANDOMIZE mode, which should fix any problems with running on platforms that do not use process space randomization like cygwin. It adds support for -Dh under DEBUGGING to allow introspection of the the state of PL_hash_rand_bits and source and cause of changes to it. With -Dhv you can also get an idea of the keys which are triggering these mutations as well. -Dh has also been changed to imply PERL_HASH_SEED_DEBUG as a convenience. This goes alongside a new test, based on one from Nicholas R (atoomic) to test that the various PERL_PERTURB_KEYS options behave as expected and that 1 bit mutations of the seed actually *do* affect the key order and hashing of our strings. The test is run many times to ensure that it passes under many different randomly generated hash seeds. Parts of this test would fail without the preceding commit to this one adjusting how SBOX32 is initialized.
Diffstat (limited to 'perl.h')
-rw-r--r--perl.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/perl.h b/perl.h
index 552a106830..baf1719f84 100644
--- a/perl.h
+++ b/perl.h
@@ -4362,7 +4362,7 @@ Gid_t getegid (void);
#define DEBUG_u_FLAG 0x00000800 /* 2048 */
/* U is reserved for Unofficial, exploratory hacking */
#define DEBUG_U_FLAG 0x00001000 /* 4096 */
-/* spare 8192 */
+#define DEBUG_h_FLAG 0x00002000 /* 8192 */
#define DEBUG_X_FLAG 0x00004000 /* 16384 */
#define DEBUG_D_FLAG 0x00008000 /* 32768 */
#define DEBUG_S_FLAG 0x00010000 /* 65536 */
@@ -4401,6 +4401,7 @@ Gid_t getegid (void);
# define DEBUG_x_TEST_ UNLIKELY(PL_debug & DEBUG_x_FLAG)
# define DEBUG_u_TEST_ UNLIKELY(PL_debug & DEBUG_u_FLAG)
# define DEBUG_U_TEST_ UNLIKELY(PL_debug & DEBUG_U_FLAG)
+# define DEBUG_h_TEST_ UNLIKELY(PL_debug & DEBUG_h_FLAG)
# define DEBUG_X_TEST_ UNLIKELY(PL_debug & DEBUG_X_FLAG)
# define DEBUG_D_TEST_ UNLIKELY(PL_debug & DEBUG_D_FLAG)
# define DEBUG_S_TEST_ UNLIKELY(PL_debug & DEBUG_S_FLAG)
@@ -4437,6 +4438,7 @@ Gid_t getegid (void);
# define DEBUG_x_TEST DEBUG_x_TEST_
# define DEBUG_u_TEST DEBUG_u_TEST_
# define DEBUG_U_TEST DEBUG_U_TEST_
+# define DEBUG_h_TEST DEBUG_h_TEST_
# define DEBUG_X_TEST DEBUG_X_TEST_
# define DEBUG_D_TEST DEBUG_D_TEST_
# define DEBUG_S_TEST DEBUG_S_TEST_
@@ -4567,6 +4569,7 @@ Gid_t getegid (void);
# define DEBUG_x_TEST (0)
# define DEBUG_u_TEST (0)
# define DEBUG_U_TEST (0)
+# define DEBUG_h_TEST (0)
# define DEBUG_X_TEST (0)
# define DEBUG_D_TEST (0)
# define DEBUG_S_TEST (0)