forked from wolfSSL/wolfssl
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:
@ -59,12 +59,20 @@
|
||||
#ifndef PACKAGE_NAME
|
||||
#error wc_port.h included before config.h
|
||||
#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
|
||||
#endif
|
||||
|
||||
#ifdef BUILDING_WOLFSSL
|
||||
|
||||
_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 \"-Wpointer-arith\"");
|
||||
_Pragma("GCC diagnostic ignored \"-Wshadow\"");
|
||||
@ -73,10 +81,7 @@
|
||||
_Pragma("GCC diagnostic ignored \"-Wsign-compare\"");
|
||||
_Pragma("GCC diagnostic ignored \"-Wpointer-sign\"");
|
||||
_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/kernel.h>
|
||||
#include <linux/version.h>
|
||||
@ -98,12 +103,13 @@
|
||||
#define RESTORE_VECTOR_REGISTERS() kernel_fpu_end()
|
||||
#elif defined(WOLFSSL_ARMASM)
|
||||
#include <asm/fpsimd.h>
|
||||
#define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); })
|
||||
#define SAVE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); })
|
||||
#define SAVE_VECTOR_REGISTERS() ({ preempt_disable(); fpsimd_preserve_current_state(); })
|
||||
#define SAVE_VECTOR_REGISTERS() ({ fpsimd_restore_current_state(); preempt_enable(); })
|
||||
#else
|
||||
#define SAVE_VECTOR_REGISTERS() ({})
|
||||
#define RESTORE_VECTOR_REGISTERS() ({})
|
||||
#endif
|
||||
|
||||
_Pragma("GCC diagnostic pop");
|
||||
|
||||
/* remove this multifariously conflicting macro, picked up from
|
||||
@ -111,30 +117,50 @@
|
||||
*/
|
||||
#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 malloc(x) kmalloc(x, GFP_KERNEL)
|
||||
#define free(x) kfree(x)
|
||||
#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 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 lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## 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. */
|
||||
#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 */
|
||||
|
||||
#define SAVE_VECTOR_REGISTERS() ({})
|
||||
#define RESTORE_VECTOR_REGISTERS() ({})
|
||||
#ifdef BUILDING_WOLFSSL
|
||||
#define SAVE_VECTOR_REGISTERS() ({})
|
||||
#define RESTORE_VECTOR_REGISTERS() ({})
|
||||
#endif
|
||||
|
||||
#endif /* WOLFSSL_LINUXKM */
|
||||
|
||||
@ -757,6 +783,8 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
||||
|
||||
|
||||
#elif defined(WOLFSSL_LINUXKM)
|
||||
#ifdef BUILDING_WOLFSSL
|
||||
|
||||
/* includes are all above, with incompatible warnings masked out. */
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
|
||||
typedef __kernel_time_t time_t;
|
||||
@ -769,6 +797,8 @@ WOLFSSL_API int wolfCrypt_Cleanup(void);
|
||||
#define XGMTIME(c, t) gmtime(c)
|
||||
#define NO_TIMEVAL 1
|
||||
|
||||
#endif /* BUILDING_WOLFSSL */
|
||||
|
||||
#else
|
||||
/* default */
|
||||
/* uses complete <time.h> facility */
|
||||
|
Reference in New Issue
Block a user