You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.5 KiB
79 lines
2.5 KiB
New test case to verify padding usage. |
|
|
|
diff --git a/nptl/Makefile b/nptl/Makefile |
|
index ff4d590f11c38277..9a56d34313d06444 100644 |
|
--- a/nptl/Makefile |
|
+++ b/nptl/Makefile |
|
@@ -319,6 +319,8 @@ tests-internal := tst-robustpi8 tst-rwlock19 tst-rwlock20 \ |
|
tst-barrier5 tst-signal7 tst-mutex8 tst-mutex8-static \ |
|
tst-mutexpi8 tst-mutexpi8-static \ |
|
tst-setgetname \ |
|
+ tst-nptl-padding \ |
|
+ # tests-internal |
|
|
|
xtests = tst-setuid1 tst-setuid1-static tst-setuid2 \ |
|
tst-mutexpp1 tst-mutexpp6 tst-mutexpp10 tst-setgroups \ |
|
diff --git a/nptl/tst-nptl-padding.c b/nptl/tst-nptl-padding.c |
|
new file mode 100644 |
|
index 0000000000000000..5bb64f4a54335e36 |
|
--- /dev/null |
|
+++ b/nptl/tst-nptl-padding.c |
|
@@ -0,0 +1,57 @@ |
|
+/* Downstream-only test for verifying that fields that have been |
|
+ relocated into struct pthread padding actually use the padding. |
|
+ |
|
+ At present, only rtld_catch (downstream: rtld_catch_f) has been |
|
+ placed into padding. */ |
|
+ |
|
+#include <descr.h> |
|
+#include <stddef.h> |
|
+#include <stdint.h> |
|
+#include <string.h> |
|
+#include <support/check.h> |
|
+ |
|
+static int |
|
+do_test (void) |
|
+{ |
|
+ struct pthread descr; |
|
+ |
|
+ /* Mark the entire descriptor as used. */ |
|
+ memset (&descr, 0xff, sizeof (descr)); |
|
+ |
|
+ /* Mark the padding as unused. */ |
|
+#ifdef __x86_64__ |
|
+ /* Special case: Usable padding is in the header. */ |
|
+ memset (&descr.header.__padding, 0, sizeof (descr.header.__padding)); |
|
+#else |
|
+ /* The padding should be directly adjacent to the first real |
|
+ struct field. */ |
|
+ TEST_COMPARE (sizeof (descr.__padding), offsetof (struct pthread, list)); |
|
+ |
|
+ /* Clear the unused tail of the padding. */ |
|
+ { |
|
+ char *base = (char *) &descr; |
|
+ char *end_of_header = base + sizeof (descr.header); |
|
+ char *end_of_padding = base + sizeof (descr.__padding); |
|
+ memset (end_of_header, 0, end_of_padding - end_of_header); |
|
+ } |
|
+#endif |
|
+ |
|
+ /* These fields are not in padding and should remain marked as used. */ |
|
+ TEST_COMPARE (descr.header.gscope_flag, -1); |
|
+ TEST_COMPARE ((intptr_t) descr.list.next, -1); |
|
+ TEST_COMPARE ((intptr_t) descr.list.prev, -1); |
|
+ |
|
+ /* But this field remains in padding. */ |
|
+ TEST_COMPARE ((intptr_t) descr.rtld_catch_f, 0); |
|
+ |
|
+ /* Write to all padding-relocated fields below to show that they |
|
+ have independent locations. */ |
|
+ struct rtld_catch *rtld_catch_dummy = (void *) "rtld_catch_dummy"; |
|
+ descr.rtld_catch_f = rtld_catch_dummy; |
|
+ |
|
+ TEST_VERIFY (descr.rtld_catch_f == rtld_catch_dummy); |
|
+ |
|
+ return 0; |
|
+} |
|
+ |
|
+#include <support/test-driver.c> |
|
|
|
|