about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux/dl-osinfo.h
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-07-29 16:56:26 +0000
committerJakub Jelinek <jakub@redhat.com>2005-07-29 16:56:26 +0000
commit979da19ab840553e3862f3b2aea50ad07118616f (patch)
tree150fffcd4616402c468e87600cf96568d7c34302 /sysdeps/unix/sysv/linux/dl-osinfo.h
parent1ce6c1300b11dcd825ee372b9354607f5069a6f1 (diff)
downloadglibc-979da19ab840553e3862f3b2aea50ad07118616f.tar.gz
glibc-979da19ab840553e3862f3b2aea50ad07118616f.tar.xz
glibc-979da19ab840553e3862f3b2aea50ad07118616f.zip
* sysdeps/unix/sysv/dl-osinfo.h: Include errno.h, hp-timing.h,
	endian.h.
	(_dl_setup_stack_chk_guard): Even without
	--enable-stackguard-randomization attempt to do some guard
	randomization using hp-timing (if available) and kernel stack and
	mmap randomization.
	* elf/tst-stackguard1.c (do_test): Don't fail if the poor man's
	randomization doesn't work well enough.
nptl/
	* tst-stackguard1.c (do_test): Don't fail if the poor man's
	randomization doesn't work well enough.
Diffstat (limited to 'sysdeps/unix/sysv/linux/dl-osinfo.h')
-rw-r--r--sysdeps/unix/sysv/linux/dl-osinfo.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/sysdeps/unix/sysv/linux/dl-osinfo.h b/sysdeps/unix/sysv/linux/dl-osinfo.h
index e374023841..fb885330f9 100644
--- a/sysdeps/unix/sysv/linux/dl-osinfo.h
+++ b/sysdeps/unix/sysv/linux/dl-osinfo.h
@@ -18,12 +18,15 @@
    02111-1307 USA.  */
 
 #include <string.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <sys/sysctl.h>
 #include <sys/utsname.h>
 #include "kernel-features.h"
 #include <dl-sysdep.h>
 #include <stdint.h>
+#include <hp-timing.h>
+#include <endian.h>
 
 #ifndef MIN
 # define MIN(a,b) (((a)<(b))?(a):(b))
@@ -177,5 +180,31 @@ _dl_setup_stack_chk_guard (void)
   unsigned char *p = (unsigned char *) &ret;
   p[sizeof (ret) - 1] = 255;
   p[sizeof (ret) - 2] = '\n';
+#ifdef HP_TIMING_NOW
+  hp_timing_t hpt;
+  HP_TIMING_NOW (hpt);
+  hpt = (hpt & 0xffff) << 8;
+  ret ^= hpt;
+#endif
+  uintptr_t stk;
+  /* Avoid GCC being too smart.  */
+  asm ("" : "=r" (stk) : "r" (p));
+  stk &= 0x7ffff0;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  stk <<= (__WORDSIZE - 23);
+#elif __WORDSIZE == 64
+  stk <<= 31;
+#endif
+  ret ^= stk;
+  /* Avoid GCC being too smart.  */
+  p = (unsigned char *) &errno;
+  asm ("" : "=r" (stk) : "r" (p));
+  stk &= 0x7fff00;
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+  stk <<= (__WORDSIZE - 29);
+#else
+  stk <<= (__WORDSIZE == 64 ? 24 : 5);
+#endif
+  ret ^= stk;
   return ret;
 }