mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-09 17:00:50 +02:00
linuxkm/x86_vector_register_glue.c, linuxkm/linuxkm_wc_port.h, wolfssl/wolfcrypt/memory.h: add WC_SVR_FLAG_FUZZ, implement support for DEBUG_VECTOR_REGISTER_ACCESS_FUZZING directly in the save/restore implementations, and properly reflect existing save state there and in the _FUZZING variants of SAVE_VECTOR_REGISTERS2().
This commit is contained in:
@@ -192,6 +192,7 @@
|
||||
enum wc_svr_flags {
|
||||
WC_SVR_FLAG_NONE = 0,
|
||||
WC_SVR_FLAG_INHIBIT = 1,
|
||||
WC_SVR_FLAG_FUZZ
|
||||
};
|
||||
|
||||
#if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \
|
||||
@@ -705,11 +706,7 @@
|
||||
#endif
|
||||
#endif
|
||||
#ifndef CAN_SAVE_VECTOR_REGISTERS
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
|
||||
#define CAN_SAVE_VECTOR_REGISTERS() (wc_can_save_vector_registers_x86() && (SAVE_VECTOR_REGISTERS2_fuzzer() == 0))
|
||||
#else
|
||||
#define CAN_SAVE_VECTOR_REGISTERS() wc_can_save_vector_registers_x86()
|
||||
#endif
|
||||
#define CAN_SAVE_VECTOR_REGISTERS() wc_can_save_vector_registers_x86()
|
||||
#endif
|
||||
#ifndef SAVE_VECTOR_REGISTERS
|
||||
#define SAVE_VECTOR_REGISTERS(fail_clause) { \
|
||||
@@ -721,12 +718,7 @@
|
||||
#endif
|
||||
#ifndef SAVE_VECTOR_REGISTERS2
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
|
||||
#define SAVE_VECTOR_REGISTERS2() ({ \
|
||||
int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); \
|
||||
(_fuzzer_ret == 0) ? \
|
||||
wc_save_vector_registers_x86(WC_SVR_FLAG_NONE) : \
|
||||
_fuzzer_ret; \
|
||||
})
|
||||
#define SAVE_VECTOR_REGISTERS2() wc_save_vector_registers_x86(WC_SVR_FLAG_FUZZ)
|
||||
#else
|
||||
#define SAVE_VECTOR_REGISTERS2() wc_save_vector_registers_x86(WC_SVR_FLAG_NONE)
|
||||
#endif
|
||||
|
||||
@@ -323,6 +323,11 @@ WARN_UNUSED_RESULT int wc_can_save_vector_registers_x86(void)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
|
||||
if (SAVE_VECTOR_REGISTERS2_fuzzer() != 0)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
if ((preempt_count() == 0) || may_use_simd())
|
||||
return 1;
|
||||
else
|
||||
@@ -423,6 +428,14 @@ WARN_UNUSED_RESULT int wc_save_vector_registers_x86(enum wc_svr_flags flags)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
|
||||
if (flags & WC_SVR_FLAG_FUZZ) {
|
||||
int ret = SAVE_VECTOR_REGISTERS2_fuzzer();
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((preempt_count() == 0) || may_use_simd()) {
|
||||
/* fpregs_lock() calls either local_bh_disable() or preempt_disable()
|
||||
* depending on CONFIG_PREEMPT_RT -- we call both, explicitly.
|
||||
|
||||
@@ -356,9 +356,6 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag,
|
||||
#ifndef WC_DEBUG_VECTOR_REGISTERS_FUZZING_SEED
|
||||
#define WC_DEBUG_VECTOR_REGISTERS_FUZZING_SEED 0
|
||||
#endif
|
||||
#ifndef CAN_SAVE_VECTOR_REGISTERS
|
||||
#define CAN_SAVE_VECTOR_REGISTERS() (SAVE_VECTOR_REGISTERS2_fuzzer() == 0)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS
|
||||
@@ -420,15 +417,26 @@ WOLFSSL_LOCAL int wc_debug_CipherLifecycleFree(void **CipherLifecycleTag,
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING
|
||||
|
||||
#ifndef CAN_SAVE_VECTOR_REGISTERS
|
||||
#define CAN_SAVE_VECTOR_REGISTERS() \
|
||||
((wc_svr_count > 0) ? 1 : \
|
||||
SAVE_VECTOR_REGISTERS2_fuzzer() == 0)
|
||||
#endif
|
||||
|
||||
#define SAVE_VECTOR_REGISTERS2(...) ({ \
|
||||
int _svr2_val = SAVE_VECTOR_REGISTERS2_fuzzer(); \
|
||||
int _svr2_val; \
|
||||
if (wc_svr_count > 0) \
|
||||
_svr2_val = 0; \
|
||||
else \
|
||||
_svr2_val = SAVE_VECTOR_REGISTERS2_fuzzer(); \
|
||||
if (_svr2_val == 0) { \
|
||||
++wc_svr_count; \
|
||||
if (wc_svr_count > 5) { \
|
||||
fprintf(stderr, \
|
||||
("%s() %s @ L %d : incr : " \
|
||||
"wc_svr_count %d (last op %s L %d)\n"), \
|
||||
__FUNCTION__, \
|
||||
__func__, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
wc_svr_count, \
|
||||
|
||||
Reference in New Issue
Block a user