pie_redirect_table.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* pie_redirect_table.c -- module load/unload hooks for libwolfssl.ko
  2. *
  3. * Copyright (C) 2006-2024 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef __PIE__
  22. #error pie_redirect_table.c must be compiled -fPIE.
  23. #endif
  24. #ifdef HAVE_CONFIG_H
  25. #include <config.h>
  26. #endif
  27. #include <wolfssl/wolfcrypt/settings.h>
  28. #include <wolfssl/wolfcrypt/error-crypt.h>
  29. #include <wolfssl/ssl.h>
  30. /* compiling -fPIE results in references to the GOT or equivalent thereof, which remain after linking
  31. * even if all other symbols are resolved by the link. naturally there is no
  32. * GOT in the kernel, and the wolfssl Kbuild script explicitly checks that no
  33. * GOT relocations occur in the PIE objects, but we still need to include a
  34. * dummy value here, scoped to the module, to eliminate the otherwise unresolved
  35. * symbol.
  36. */
  37. #if defined(CONFIG_X86)
  38. extern void * const _GLOBAL_OFFSET_TABLE_;
  39. void * const _GLOBAL_OFFSET_TABLE_ = 0;
  40. #elif defined(CONFIG_MIPS)
  41. extern void * const _gp_disp;
  42. void * const _gp_disp = 0;
  43. #endif
  44. struct wolfssl_linuxkm_pie_redirect_table wolfssl_linuxkm_pie_redirect_table;
  45. const struct wolfssl_linuxkm_pie_redirect_table
  46. *wolfssl_linuxkm_get_pie_redirect_table(void) {
  47. return &wolfssl_linuxkm_pie_redirect_table;
  48. }
  49. /* placeholder implementations for missing functions. */
  50. #if defined(CONFIG_MIPS)
  51. #undef memcpy
  52. void *memcpy(void *dest, const void *src, size_t n) {
  53. char *dest_i = (char *)dest;
  54. char *dest_end = dest_i + n;
  55. char *src_i = (char *)src;
  56. while (dest_i < dest_end)
  57. *dest_i++ = *src_i++;
  58. return dest;
  59. }
  60. #undef memset
  61. void *memset(void *dest, int c, size_t n) {
  62. char *dest_i = (char *)dest;
  63. char *dest_end = dest_i + n;
  64. while (dest_i < dest_end)
  65. *dest_i++ = c;
  66. return dest;
  67. }
  68. #endif