wc_port.h: for WOLFSSL_LINUXKM, gate kernel includes and libwolfssl-specific preprocessor directives on BUILDING_WOLFSSL, to avoid disrupting environment for builds of other kernel components.

This commit is contained in:
Daniel Pouzzner
2020-09-15 22:25:34 -05:00
parent 185994cb0b
commit da6a5566b6

View File

@ -59,12 +59,20 @@
#ifndef PACKAGE_NAME #ifndef PACKAGE_NAME
#error wc_port.h included before config.h #error wc_port.h included before config.h
#endif #endif
/* config.h is autogenerated without gating, and is subject to repeat inclusions, so gate it out here to keep autodetection masking intact: */ /* config.h is autogenerated without gating, and is subject to repeat
* inclusions, so gate it out here to keep autodetection masking
* intact:
*/
#undef HAVE_CONFIG_H #undef HAVE_CONFIG_H
#endif #endif
#ifdef BUILDING_WOLFSSL
_Pragma("GCC diagnostic push"); _Pragma("GCC diagnostic push");
/* Linux kernel header files generate profuse warnings unless these are masked out: */
/* we include all the needed kernel headers with these masked out. else
* there are profuse warnings.
*/
_Pragma("GCC diagnostic ignored \"-Wunused-parameter\""); _Pragma("GCC diagnostic ignored \"-Wunused-parameter\"");
_Pragma("GCC diagnostic ignored \"-Wpointer-arith\""); _Pragma("GCC diagnostic ignored \"-Wpointer-arith\"");
_Pragma("GCC diagnostic ignored \"-Wshadow\""); _Pragma("GCC diagnostic ignored \"-Wshadow\"");
@ -73,10 +81,7 @@
_Pragma("GCC diagnostic ignored \"-Wsign-compare\""); _Pragma("GCC diagnostic ignored \"-Wsign-compare\"");
_Pragma("GCC diagnostic ignored \"-Wpointer-sign\""); _Pragma("GCC diagnostic ignored \"-Wpointer-sign\"");
_Pragma("GCC diagnostic ignored \"-Wbad-function-cast\""); _Pragma("GCC diagnostic ignored \"-Wbad-function-cast\"");
/* these includes bring in all the needed kernel headers.
* they need to be included here while the incompatible warnings are disabled,
* and before undefining conflicting kernel macros afterward.
*/
#include <linux/kconfig.h> #include <linux/kconfig.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/version.h> #include <linux/version.h>
@ -98,12 +103,13 @@
#define RESTORE_VECTOR_REGISTERS() kernel_fpu_end() #define RESTORE_VECTOR_REGISTERS() kernel_fpu_end()
#elif defined(WOLFSSL_ARMASM) #elif defined(WOLFSSL_ARMASM)
#include <asm/fpsimd.h> #include <asm/fpsimd.h>
#define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); }) #define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); })
#define SAVE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); }) #define SAVE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); })
#else #else
#define SAVE_VECTOR_REGISTERS() ({}) #define SAVE_VECTOR_REGISTERS() ({})
#define RESTORE_VECTOR_REGISTERS() ({}) #define RESTORE_VECTOR_REGISTERS() ({})
#endif #endif
_Pragma("GCC diagnostic pop"); _Pragma("GCC diagnostic pop");
/* remove this multifariously conflicting macro, picked up from /* remove this multifariously conflicting macro, picked up from
@ -111,30 +117,50 @@
*/ */
#undef current #undef current
/* prevent gcc's mm_malloc.h from being included, since it unconditionally includes stdlib.h, which is kernel-incompatible: */ /* prevent gcc's mm_malloc.h from being included, since it unconditionally
* includes stdlib.h, which is kernel-incompatible.
*/
#define _MM_MALLOC_H_INCLUDED #define _MM_MALLOC_H_INCLUDED
#define malloc(x) kmalloc(x, GFP_KERNEL) #define malloc(x) kmalloc(x, GFP_KERNEL)
#define free(x) kfree(x) #define free(x) kfree(x)
#define realloc(x,y) krealloc(x, y, GFP_KERNEL) #define realloc(x,y) krealloc(x, y, GFP_KERNEL)
/* min() and max() in linux/kernel.h over-aggressively type-check, producing myriad spurious -Werrors throughout the codebase. */ /* min() and max() in linux/kernel.h over-aggressively type-check, producing
* myriad spurious -Werrors throughout the codebase.
*/
#undef min #undef min
#undef max #undef max
/* work around namespace conflict between wolfssl/internal.h (enum HandShakeType) and linux/key.h (extern int()). */ /* work around namespace conflict between wolfssl/internal.h (enum HandShakeType)
* and linux/key.h (extern int()).
*/
#define key_update wc_key_update #define key_update wc_key_update
#define lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args) #define lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
#define printf(...) lkm_printf(__VA_ARGS__) #define printf(...) lkm_printf(__VA_ARGS__)
#define XSNPRINTF snprintf /* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */
#endif /* BUILDING_WOLFSSL */
/* needed to suppress inclusion of stdio.h in wolfssl/wolfcrypt/types.h */
#define XSNPRINTF snprintf
/* the rigmarole around kstrtol() here is to accommodate its warn-unused-result attribute. */ /* the rigmarole around kstrtol() here is to accommodate its warn-unused-result attribute. */
#define XATOI(s) ({ long _xatoi_res = 0; int _xatoi_ret = kstrtol(s, 10, &_xatoi_res); if (_xatoi_ret != 0) { _xatoi_res = 0; } (int)_xatoi_res; }) #define XATOI(s) ({ \
long _xatoi_res = 0; \
int _xatoi_ret = kstrtol(s, 10, &_xatoi_res); \
if (_xatoi_ret != 0) { \
_xatoi_res = 0; \
} \
(int)_xatoi_res; \
})
#else /* ! WOLFSSL_LINUXKM */ #else /* ! WOLFSSL_LINUXKM */
#define SAVE_VECTOR_REGISTERS() ({}) #ifdef BUILDING_WOLFSSL
#define RESTORE_VECTOR_REGISTERS() ({}) #define SAVE_VECTOR_REGISTERS() ({})
#define RESTORE_VECTOR_REGISTERS() ({})
#endif
#endif /* WOLFSSL_LINUXKM */ #endif /* WOLFSSL_LINUXKM */
@ -757,6 +783,8 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
#elif defined(WOLFSSL_LINUXKM) #elif defined(WOLFSSL_LINUXKM)
#ifdef BUILDING_WOLFSSL
/* includes are all above, with incompatible warnings masked out. */ /* includes are all above, with incompatible warnings masked out. */
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0) #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
typedef __kernel_time_t time_t; typedef __kernel_time_t time_t;
@ -769,6 +797,8 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
#define XGMTIME(c, t) gmtime(c) #define XGMTIME(c, t) gmtime(c)
#define NO_TIMEVAL 1 #define NO_TIMEVAL 1
#endif /* BUILDING_WOLFSSL */
#else #else
/* default */ /* default */
/* uses complete <time.h> facility */ /* uses complete <time.h> facility */