1 /* pie_redirect_table.c -- module load/unload hooks for libwolfssl.ko
2 *
3 * Copyright (C) 2006-2021 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
22 #ifndef __PIE__
23 #error pie_redirect_table.c must be compiled -fPIE.
24 #endif
25
26 #ifdef HAVE_CONFIG_H
27 #include <config.h>
28 #endif
29
30 #include <wolfssl/wolfcrypt/settings.h>
31 #include <wolfssl/wolfcrypt/error-crypt.h>
32 #include <wolfssl/ssl.h>
33
34 /* compiling -fPIE results in references to the GOT or equivalent thereof, which remain after linking
35 * even if all other symbols are resolved by the link. naturally there is no
36 * GOT in the kernel, and the wolfssl Kbuild script explicitly checks that no
37 * GOT relocations occur in the PIE objects, but we still need to include a
38 * dummy value here, scoped to the module, to eliminate the otherwise unresolved
39 * symbol.
40 */
41 #if defined(CONFIG_X86)
42 extern void * const _GLOBAL_OFFSET_TABLE_;
43 void * const _GLOBAL_OFFSET_TABLE_ = 0;
44 #elif defined(CONFIG_MIPS)
45 extern void * const _gp_disp;
46 void * const _gp_disp = 0;
47 #endif
48
49 struct wolfssl_linuxkm_pie_redirect_table wolfssl_linuxkm_pie_redirect_table;
50
51 const struct wolfssl_linuxkm_pie_redirect_table
wolfssl_linuxkm_get_pie_redirect_table(void)52 *wolfssl_linuxkm_get_pie_redirect_table(void) {
53 return &wolfssl_linuxkm_pie_redirect_table;
54 }
55
56 /* placeholder implementations for missing functions. */
57 #if defined(CONFIG_MIPS)
58 #undef memcpy
memcpy(void * dest,const void * src,size_t n)59 void *memcpy(void *dest, const void *src, size_t n) {
60 char *dest_i = (char *)dest;
61 char *dest_end = dest_i + n;
62 char *src_i = (char *)src;
63 while (dest_i < dest_end)
64 *dest_i++ = *src_i++;
65 return dest;
66 }
67
68 #undef memset
memset(void * dest,int c,size_t n)69 void *memset(void *dest, int c, size_t n) {
70 char *dest_i = (char *)dest;
71 char *dest_end = dest_i + n;
72 while (dest_i < dest_end)
73 *dest_i++ = c;
74 return dest;
75 }
76 #endif
77