]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/libc/sysdeps/linux/common/dl-osinfo.h
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / libc / sysdeps / linux / common / dl-osinfo.h
1 /*
2  * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6
7 #ifndef _DL_OSINFO_H
8 #define _DL_OSINFO_H 1
9
10 #include <features.h>
11
12 #ifdef __UCLIBC_HAS_SSP__
13 # if defined IS_IN_libc || defined IS_IN_rtld
14
15 #  if defined __SSP__ || defined __SSP_ALL__
16 #   error "file must not be compiled with stack protection enabled on it. Use -fno-stack-protector"
17 #  endif
18
19 #  include <stdint.h>
20
21 #  ifdef IS_IN_libc
22 #   include <fcntl.h>
23 #   include <unistd.h>
24 #   include <sys/time.h>
25 #   define OPEN open
26 #   define READ read
27 #   define CLOSE close
28 #   define GETTIMEOFDAY gettimeofday
29 #  else
30 #   define OPEN _dl_open
31 #   define READ _dl_read
32 #   define CLOSE _dl_close
33 #   define GETTIMEOFDAY _dl_gettimeofday
34 #  endif
35
36 static __always_inline uintptr_t _dl_setup_stack_chk_guard(void)
37 {
38         uintptr_t ret;
39 #  ifndef __SSP_QUICK_CANARY__
40         {
41                 int fd = OPEN("/dev/urandom", O_RDONLY, 0);
42                 if (fd >= 0) {
43                         size_t size = READ(fd, &ret, sizeof(ret));
44                         CLOSE(fd);
45                         if (size == (size_t) sizeof(ret))
46                                 return ret;
47                 }
48         }
49 #  endif /* !__SSP_QUICK_CANARY__ */
50
51         /* Start with the "terminator canary". */
52         ret = 0xFF0A0D00UL;
53
54         /* Everything failed? Or we are using a weakened model of the
55          * terminator canary */
56         {
57                 struct timeval tv;
58                 if (GETTIMEOFDAY(&tv, NULL) != (-1))
59                         ret ^= tv.tv_usec ^ tv.tv_sec;
60         }
61         return ret;
62 }
63 # endif /* libc || rtld */
64 #endif /* __UCLIBC_HAS_SSP__ */
65
66 #endif /* _DL_OSINFO_H */