1 #ifndef os
2 # define os(ptr) __builtin_object_size (ptr, 0)
3 #endif
4 
5 /* This is one of the alternatives for object size checking.
6    If dst has side-effects, size checking will never be done.  */
7 #undef memcpy
8 #define memcpy(dst, src, len) \
9   __builtin___memcpy_chk (dst, src, len, os (dst))
10 #undef mempcpy
11 #define mempcpy(dst, src, len) \
12   __builtin___mempcpy_chk (dst, src, len, os (dst))
13 #undef memmove
14 #define memmove(dst, src, len) \
15   __builtin___memmove_chk (dst, src, len, os (dst))
16 #undef memset
17 #define memset(dst, val, len) \
18   __builtin___memset_chk (dst, val, len, os (dst))
19 #undef strcpy
20 #define strcpy(dst, src) \
21   __builtin___strcpy_chk (dst, src, os (dst))
22 #undef stpcpy
23 #define stpcpy(dst, src) \
24   __builtin___stpcpy_chk (dst, src, os (dst))
25 #undef strcat
26 #define strcat(dst, src) \
27   __builtin___strcat_chk (dst, src, os (dst))
28 #undef strncpy
29 #define strncpy(dst, src, len) \
30   __builtin___strncpy_chk (dst, src, len, os (dst))
31 #undef stpncpy
32 #define stpncpy(dst, src, len) \
33   __builtin___stpncpy_chk (dst, src, len, os (dst))
34 #undef strncat
35 #define strncat(dst, src, len) \
36   __builtin___strncat_chk (dst, src, len, os (dst))
37 #undef sprintf
38 #define sprintf(dst, ...) \
39   __builtin___sprintf_chk (dst, 0, os (dst), __VA_ARGS__)
40 #undef vsprintf
41 #define vsprintf(dst, fmt, ap) \
42   __builtin___vsprintf_chk (dst, 0, os (dst), fmt, ap)
43 #undef snprintf
44 #define snprintf(dst, len, ...) \
45   __builtin___snprintf_chk (dst, len, 0, os (dst), __VA_ARGS__)
46 #undef vsnprintf
47 #define vsnprintf(dst, len, fmt, ap) \
48   __builtin___vsnprintf_chk (dst, len, 0, os (dst), fmt, ap)
49 
50 /* Now "redefine" even builtins for the purpose of testing.  */
51 #undef __builtin_memcpy
52 #define __builtin_memcpy(dst, src, len) memcpy (dst, src, len)
53 #undef __builtin_mempcpy
54 #define __builtin_mempcpy(dst, src, len) mempcpy (dst, src, len)
55 #undef __builtin_memmove
56 #define __builtin_memmove(dst, src, len) memmove (dst, src, len)
57 #undef __builtin_memset
58 #define __builtin_memset(dst, val, len) memset (dst, val, len)
59 #undef __builtin_strcpy
60 #define __builtin_strcpy(dst, src) strcpy (dst, src)
61 #undef __builtin_stpcpy
62 #define __builtin_stpcpy(dst, src) stpcpy (dst, src)
63 #undef __builtin_strcat
64 #define __builtin_strcat(dst, src) strcat (dst, src)
65 #undef __builtin_strncpy
66 #define __builtin_strncpy(dst, src, len) strncpy (dst, src, len)
67 #undef __builtin_strncat
68 #define __builtin_strncat(dst, src, len) strncat (dst, src, len)
69 #undef __builtin_sprintf
70 #define __builtin_sprintf(dst, ...) sprintf (dst, __VA_ARGS__)
71 #undef __builtin_vsprintf
72 #define __builtin_vsprintf(dst, fmt, ap) vsprintf (dst, fmt, ap)
73 #undef __builtin_snprintf
74 #define __builtin_snprintf(dst, len, ...) snprintf (dst, len, __VA_ARGS__)
75 #undef __builtin_vsnprintf
76 #define __builtin_vsnprintf(dst, len, fmt, ap) vsnprintf (dst, len, fmt, ap)
77 
78 extern void *chk_fail_buf[];
79 extern volatile int chk_fail_allowed, chk_calls;
80 extern volatile int memcpy_disallowed, mempcpy_disallowed, memmove_disallowed;
81 extern volatile int memset_disallowed, strcpy_disallowed, stpcpy_disallowed;
82 extern volatile int strncpy_disallowed, stpncpy_disallowed, strcat_disallowed;
83 extern volatile int strncat_disallowed, sprintf_disallowed, vsprintf_disallowed;
84 extern volatile int snprintf_disallowed, vsnprintf_disallowed;
85 
86 /* A storage class that ensures that declarations bind locally.  We want
87    to test non-static declarations where we know it is safe to do so.  */
88 #if __PIC__ && !__PIE__
89 #define LOCAL static
90 #else
91 #define LOCAL
92 #endif
93