mirror of
https://github.com/Qortal/Brooklyn.git
synced 2025-02-21 22:55:53 +00:00
* 0day explit mitigation * Memory corruption prevention * Privilege escalation prevention * Buffer over flow prevention * File System corruption defense * Thread escape prevention This may very well be the most intensive inclusion to BrooklynR. This will not be part of an x86 suite nor it will be released as tool kit. The security core toolkit will remain part of kernel base.
46 lines
1.5 KiB
C
46 lines
1.5 KiB
C
#ifndef _LINUX_AVERAGE_H
|
|
#define _LINUX_AVERAGE_H
|
|
|
|
/* Exponentially weighted moving average (EWMA) */
|
|
|
|
#define DECLARE_EWMA(name, _factor, _weight) \
|
|
struct ewma_##name { \
|
|
unsigned long internal; \
|
|
}; \
|
|
static inline void ewma_##name##_init(struct ewma_##name *e) \
|
|
{ \
|
|
BUILD_BUG_ON(!__builtin_constant_p(_factor)); \
|
|
BUILD_BUG_ON(!__builtin_constant_p(_weight)); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \
|
|
e->internal = 0; \
|
|
} \
|
|
static inline unsigned long \
|
|
ewma_##name##_read(struct ewma_##name *e) \
|
|
{ \
|
|
BUILD_BUG_ON(!__builtin_constant_p(_factor)); \
|
|
BUILD_BUG_ON(!__builtin_constant_p(_weight)); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \
|
|
return e->internal >> ilog2(_factor); \
|
|
} \
|
|
static inline void ewma_##name##_add(struct ewma_##name *e, \
|
|
unsigned long val) \
|
|
{ \
|
|
unsigned long internal = ACCESS_ONCE(e->internal); \
|
|
unsigned long weight = ilog2(_weight); \
|
|
unsigned long factor = ilog2(_factor); \
|
|
\
|
|
BUILD_BUG_ON(!__builtin_constant_p(_factor)); \
|
|
BUILD_BUG_ON(!__builtin_constant_p(_weight)); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_factor); \
|
|
BUILD_BUG_ON_NOT_POWER_OF_2(_weight); \
|
|
\
|
|
ACCESS_ONCE_RW(e->internal) = internal ? \
|
|
(((internal << weight) - internal) + \
|
|
(val << factor)) >> weight : \
|
|
(val << factor); \
|
|
}
|
|
|
|
#endif /* _LINUX_AVERAGE_H */
|