ssp.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* $NetBSD: ssp.h,v 1.13 2015/09/03 20:43:47 plunky Exp $ */
  2. /*-
  3. * Copyright (c) 2006, 2011 The NetBSD Foundation, Inc.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to The NetBSD Foundation
  7. * by Christos Zoulas.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  20. * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  22. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  23. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  24. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  25. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  26. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _SSP_SSP_H_
  31. #define _SSP_SSP_H_
  32. #include <sys/cdefs.h>
  33. /* __ssp_real is used by the implementation in libc */
  34. #if __SSP_FORTIFY_LEVEL == 0
  35. #define __ssp_real_(fun) fun
  36. #else
  37. #define __ssp_real_(fun) __ssp_real_ ## fun
  38. #endif
  39. #define __ssp_real(fun) __ssp_real_(fun)
  40. #define __ssp_inline extern __inline__ __attribute__((__always_inline__, __gnu_inline__))
  41. #define __ssp_bos(ptr) __builtin_object_size(ptr, __SSP_FORTIFY_LEVEL > 1)
  42. #define __ssp_bos0(ptr) __builtin_object_size(ptr, 0)
  43. #define __ssp_check(buf, len, bos) \
  44. if (bos(buf) != (size_t)-1 && len > bos(buf)) \
  45. __chk_fail()
  46. #define __ssp_decl(rtype, fun, args) \
  47. rtype __ssp_real_(fun) args __asm__(__ASMNAME(#fun)); \
  48. __ssp_inline rtype fun args
  49. #define __ssp_redirect_raw(rtype, fun, args, call, cond, bos) \
  50. __ssp_decl(rtype, fun, args) \
  51. { \
  52. if (cond) \
  53. __ssp_check(__buf, __len, bos); \
  54. return __ssp_real_(fun) call; \
  55. }
  56. #define __ssp_redirect(rtype, fun, args, call) \
  57. __ssp_redirect_raw(rtype, fun, args, call, 1, __ssp_bos)
  58. #define __ssp_redirect0(rtype, fun, args, call) \
  59. __ssp_redirect_raw(rtype, fun, args, call, 1, __ssp_bos0)
  60. #define __ssp_overlap(a, b, l) \
  61. (((a) <= (b) && (b) < (a) + (l)) || ((b) <= (a) && (a) < (b) + (l)))
  62. __BEGIN_DECLS
  63. void __stack_chk_fail(void) __dead2;
  64. void __chk_fail(void) __dead2;
  65. __END_DECLS
  66. #endif /* _SSP_SSP_H_ */