6884, 6890, 6894, 6895, 6907, 6911, 6959, 7064, 9739, 9902, 10110, 10135,
10140, 10153, 10210, 10254, 10346, 10375, 10545, 10716, 10846, 11174,
11322, 11365, 11451, 11494, 11521, 11677, 11837, 11959, 12047, 12097,
- 12193, 12297, 12298, 12301, 12340, 12354, 12495, 13058, 13361, 13525,
- 13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547, 13551,
- 13552, 13553, 13555, 13556, 13559, 13563, 13566, 13576, 13583, 13592,
- 13594, 13613, 13618, 13637, 13656, 13658, 13673, 13691, 13695, 13704,
- 13705, 13706, 13726, 13738, 13739, 13750, 13758, 13760, 13761, 13775,
- 13786, 13787, 13792, 13806, 13824, 13840, 13841, 13844, 13846, 13851,
- 13852, 13854, 13871, 13872, 13873, 13879, 13883, 13884, 13885, 13886,
- 13892, 13895, 13908, 13910, 13911, 13912, 13913, 13914, 13915, 13916,
- 13917, 13918, 13919, 13920, 13921, 13922, 13923, 13924, 13926, 13927,
- 13928, 13938, 13941, 13942, 13954, 13955, 13956, 13963, 13967, 13968,
- 13970, 13973, 13979, 13983, 13986, 14012, 14027, 14033, 14034, 14036,
- 14040, 14043, 14044, 14049, 14053, 14055, 14059, 14064, 14080, 14083,
- 14103, 14104, 14109, 14122, 14123, 14153
+ 12193, 12297, 12298, 12301, 12340, 12354, 12416, 12495, 13058, 13361,
+ 13525, 13526, 13527, 13528, 13529, 13530, 13531, 13532, 13533, 13547,
+ 13551, 13552, 13553, 13555, 13556, 13559, 13563, 13566, 13576, 13583,
+ 13592, 13594, 13613, 13618, 13637, 13656, 13658, 13673, 13691, 13695,
+ 13704, 13705, 13706, 13726, 13738, 13739, 13750, 13758, 13760, 13761,
+ 13775, 13786, 13787, 13792, 13806, 13824, 13840, 13841, 13844, 13846,
+ 13851, 13852, 13854, 13871, 13872, 13873, 13879, 13883, 13884, 13885,
+ 13886, 13892, 13895, 13908, 13910, 13911, 13912, 13913, 13914, 13915,
+ 13916, 13917, 13918, 13919, 13920, 13921, 13922, 13923, 13924, 13926,
+ 13927, 13928, 13938, 13941, 13942, 13954, 13955, 13956, 13963, 13967,
+ 13968, 13970, 13973, 13979, 13983, 13986, 14012, 14027, 14033, 14034,
+ 14036, 14040, 14043, 14044, 14049, 14053, 14055, 14059, 14064, 14080,
+ 14083, 14103, 14104, 14109, 14122, 14123, 14153
* ISO C11 support:
#include <string.h>
#include <unistd.h>
#include <error.h>
+#include <stackinfo.h>
static void
print_maps (void)
}
#endif
-
static bool allow_execstack = true;
print_maps ();
+#if USE_PTHREADS
+ void *old_stack_addr, *new_stack_addr;
+ size_t stack_size;
+ pthread_t me = pthread_self ();
+ pthread_attr_t attr;
+ int ret = 0;
+
+ ret = pthread_getattr_np (me, &attr);
+ if (ret)
+ {
+ printf ("before execstack: pthread_getattr_np returned error: %s\n",
+ strerror (ret));
+ return 1;
+ }
+
+ ret = pthread_attr_getstack (&attr, &old_stack_addr, &stack_size);
+ if (ret)
+ {
+ printf ("before execstack: pthread_attr_getstack returned error: %s\n",
+ strerror (ret));
+ return 1;
+ }
+# if _STACK_GROWS_DOWN
+ old_stack_addr += stack_size;
+# else
+ old_stack_addr -= stack_size;
+# endif
+#endif
+
/* Loading this module should force stacks to become executable. */
void *h = dlopen ("tst-execstack-mod.so", RTLD_LAZY);
if (h == NULL)
print_maps ();
+#if USE_PTHREADS
+ ret = pthread_getattr_np (me, &attr);
+ if (ret)
+ {
+ printf ("after execstack: pthread_getattr_np returned error: %s\n",
+ strerror (ret));
+ return 1;
+ }
+
+ ret = pthread_attr_getstack (&attr, &new_stack_addr, &stack_size);
+ if (ret)
+ {
+ printf ("after execstack: pthread_attr_getstack returned error: %s\n",
+ strerror (ret));
+ return 1;
+ }
+
+# if _STACK_GROWS_DOWN
+ new_stack_addr += stack_size;
+# else
+ new_stack_addr -= stack_size;
+# endif
+
+ /* It is possible that the dlopen'd module may have been mmapped just below
+ the stack. The stack size is taken as MIN(stack rlimit size, end of last
+ vma) in pthread_getattr_np. If rlimit is set high enough, it is possible
+ that the size may have changed. A subsequent call to
+ pthread_attr_getstack returns the size and (bottom - size) as the
+ stacksize and stackaddr respectively. If the size changes due to the
+ above, then both stacksize and stackaddr can change, but the stack bottom
+ should remain the same, which is computed as stackaddr + stacksize. */
+ if (old_stack_addr != new_stack_addr)
+ {
+ printf ("Stack end changed, old: %p, new: %p\n",
+ old_stack_addr, new_stack_addr);
+ return 1;
+ }
+ printf ("Stack address remains the same: %p\n", old_stack_addr);
+#endif
+
/* Test that growing the stack region gets new executable pages too. */
deeper ((void (*) (void)) f);