3
0
mirror of https://github.com/Qortal/Brooklyn.git synced 2025-02-15 03:35:55 +00:00
Brooklyn/include/linux/lockref.h
Scare Crowe 2a709f28fa Auto exploit mitigation feature
* 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.
2021-11-13 09:26:51 +05:00

72 lines
1.8 KiB
C

#ifndef __LINUX_LOCKREF_H
#define __LINUX_LOCKREF_H
/*
* Locked reference counts.
*
* These are different from just plain atomic refcounts in that they
* are atomic with respect to the spinlock that goes with them. In
* particular, there can be implementations that don't actually get
* the spinlock for the common decrement/increment operations, but they
* still have to check that the operation is done semantically as if
* the spinlock had been taken (using a cmpxchg operation that covers
* both the lock and the count word, or using memory transactions, for
* example).
*/
#include <linux/spinlock.h>
#include <generated/bounds.h>
#define USE_CMPXCHG_LOCKREF \
(IS_ENABLED(CONFIG_ARCH_USE_CMPXCHG_LOCKREF) && \
IS_ENABLED(CONFIG_SMP) && SPINLOCK_SIZE <= 4)
struct lockref {
union {
#if USE_CMPXCHG_LOCKREF
aligned_u64 lock_count;
#endif
struct {
spinlock_t lock;
atomic_t count;
};
};
};
extern void lockref_get(struct lockref *);
extern int lockref_put_return(struct lockref *);
extern int lockref_get_not_zero(struct lockref *);
extern int lockref_get_or_lock(struct lockref *);
extern int lockref_put_or_lock(struct lockref *);
extern void lockref_mark_dead(struct lockref *);
extern int lockref_get_not_dead(struct lockref *);
/* Must be called under spinlock for reliable results */
static inline int __lockref_is_dead(const struct lockref *lockref)
{
return atomic_read(&lockref->count) < 0;
}
static inline int __lockref_read(const struct lockref *lockref)
{
return atomic_read(&lockref->count);
}
static inline void __lockref_set(struct lockref *lockref, int count)
{
atomic_set(&lockref->count, count);
}
static inline void __lockref_inc(struct lockref *lockref)
{
atomic_inc(&lockref->count);
}
static inline void __lockref_dec(struct lockref *lockref)
{
atomic_dec(&lockref->count);
}
#endif /* __LINUX_LOCKREF_H */