summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/bio.h12
-rw-r--r--include/linux/bitmap.h46
-rw-r--r--include/linux/blk_types.h1
-rw-r--r--include/linux/blkdev.h2
-rw-r--r--include/linux/kernel.h2
-rw-r--r--include/linux/kmemleak.h4
-rw-r--r--include/linux/mempool.h7
-rw-r--r--include/linux/mm.h8
-rw-r--r--include/linux/percpu-rwsem.h8
-rw-r--r--include/linux/preempt.h5
-rw-r--r--include/linux/printk.h24
-rw-r--r--include/linux/rwsem.h54
-rw-r--r--include/linux/sched/mm.h2
-rw-r--r--include/linux/sort.h1
-rw-r--r--include/linux/spinlock.h2
-rw-r--r--include/linux/types.h6
16 files changed, 157 insertions, 27 deletions
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 21825c74..6528fe19 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -239,6 +239,12 @@ struct bio *bio_alloc_bioset(struct block_device *, unsigned,
extern void bio_put(struct bio *);
int bio_add_page(struct bio *, struct page *, unsigned, unsigned);
+void bio_add_virt_nofail(struct bio *, void *, unsigned);
+
+static inline void bio_add_vmalloc(struct bio *bio, void *vaddr, unsigned len)
+{
+ bio_add_virt_nofail(bio, vaddr, len);
+}
struct bio *bio_alloc_clone(struct block_device *, struct bio *,
gfp_t, struct bio_set *);
@@ -278,7 +284,7 @@ do { \
(dst)->bi_bdev = (src)->bi_bdev; \
} while (0)
-static inline char *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
+static inline void *bvec_kmap_irq(struct bio_vec *bvec, unsigned long *flags)
{
return page_address(bvec->bv_page) + bvec->bv_offset;
}
@@ -288,14 +294,14 @@ static inline void bvec_kunmap_irq(char *buffer, unsigned long *flags)
*flags = 0;
}
-static inline char *bvec_kmap_local(struct bio_vec *bvec)
+static inline void *bvec_kmap_local(struct bio_vec *bvec)
{
return page_address(bvec->bv_page) + bvec->bv_offset;
}
static inline void bvec_kunmap_local(char *buffer) {}
-static inline char *__bio_kmap_irq(struct bio *bio, struct bvec_iter iter,
+static inline void *__bio_kmap_irq(struct bio *bio, struct bvec_iter iter,
unsigned long *flags)
{
return bvec_kmap_irq(&bio_iter_iovec(bio, iter), flags);
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index c5592a5a..54a8d52a 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -2,6 +2,7 @@
#define _PERF_BITOPS_H
#include <string.h>
+#include <linux/bits.h>
#include <linux/bitops.h>
#include <linux/kernel.h>
#include <stdlib.h>
@@ -34,7 +35,7 @@ static inline int __bitmap_weight(const unsigned long *bitmap, int bits)
w += hweight_long(bitmap[k] & BITMAP_LAST_WORD_MASK(bits));
return w;
-}
+}
static inline int __bitmap_and(unsigned long *dst, const unsigned long *bitmap1,
const unsigned long *bitmap2, unsigned int bits)
@@ -156,6 +157,49 @@ static inline unsigned long find_next_zero_bit(const unsigned long *addr, unsign
return _find_next_bit(addr, size, offset, ~0UL);
}
+#define FIND_NEXT_BIT(FETCH, MUNGE, size, start) \
+({ \
+ unsigned long mask, idx, tmp, sz = (size), __start = (start); \
+ \
+ if (unlikely(__start >= sz)) \
+ goto out; \
+ \
+ mask = MUNGE(BITMAP_FIRST_WORD_MASK(__start)); \
+ idx = __start / BITS_PER_LONG; \
+ \
+ for (tmp = (FETCH) & mask; !tmp; tmp = (FETCH)) { \
+ if ((idx + 1) * BITS_PER_LONG >= sz) \
+ goto out; \
+ idx++; \
+ } \
+ \
+ sz = min(idx * BITS_PER_LONG + __ffs(MUNGE(tmp)), sz); \
+out: \
+ sz; \
+})
+static inline unsigned long _find_next_andnot_bit(const unsigned long *addr1, const unsigned long *addr2,
+ unsigned long nbits, unsigned long start)
+{
+ return FIND_NEXT_BIT(addr1[idx] & ~addr2[idx], /* nop */, nbits, start);
+}
+
+static inline unsigned long find_next_andnot_bit(const unsigned long *addr1,
+ const unsigned long *addr2, unsigned long size,
+ unsigned long offset)
+{
+ if (small_const_nbits(size)) {
+ unsigned long val;
+
+ if (unlikely(offset >= size))
+ return size;
+
+ val = *addr1 & ~*addr2 & __GENMASK(size - 1, offset);
+ return val ? __ffs(val) : size;
+ }
+
+ return _find_next_andnot_bit(addr1, addr2, size, offset);
+}
+
#define find_first_bit(addr, size) find_next_bit((addr), (size), 0)
#define find_first_zero_bit(addr, size) find_next_zero_bit((addr), (size), 0)
diff --git a/include/linux/blk_types.h b/include/linux/blk_types.h
index 72056043..b4495886 100644
--- a/include/linux/blk_types.h
+++ b/include/linux/blk_types.h
@@ -265,6 +265,7 @@ static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
#define REQ_FUA (1ULL << __REQ_FUA)
#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
+#define REQ_IDLE (1ULL << __REQ_IDLE)
#define RW_MASK REQ_OP_WRITE
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 7c2ec1b2..7cf1a833 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -87,7 +87,7 @@ struct super_block {
};
static inline void evict_inodes(struct super_block *sb) {}
-static inline int sync_filesystem(struct super_block *) { return 0; }
+static inline int sync_filesystem(struct super_block *sb) { return 0; }
/*
* File types
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 6eb8c8a0..efa73385 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -254,8 +254,6 @@ struct qstr {
#define POISON_FREE 0x6b
-static inline void dump_stack(void) {}
-
#define unsafe_memcpy(dst, src, bytes, justification) \
memcpy(dst, src, bytes)
diff --git a/include/linux/kmemleak.h b/include/linux/kmemleak.h
index 93a73c07..fbd424b2 100644
--- a/include/linux/kmemleak.h
+++ b/include/linux/kmemleak.h
@@ -28,6 +28,7 @@ extern void kmemleak_update_trace(const void *ptr) __ref;
extern void kmemleak_not_leak(const void *ptr) __ref;
extern void kmemleak_transient_leak(const void *ptr) __ref;
extern void kmemleak_ignore(const void *ptr) __ref;
+extern void kmemleak_ignore_percpu(const void __percpu *ptr) __ref;
extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
extern void kmemleak_no_scan(const void *ptr) __ref;
extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
@@ -97,6 +98,9 @@ static inline void kmemleak_not_leak(const void *ptr)
static inline void kmemleak_transient_leak(const void *ptr)
{
}
+static inline void kmemleak_ignore_percpu(const void __percpu *ptr)
+{
+}
static inline void kmemleak_ignore(const void *ptr)
{
}
diff --git a/include/linux/mempool.h b/include/linux/mempool.h
index 37325170..83875b85 100644
--- a/include/linux/mempool.h
+++ b/include/linux/mempool.h
@@ -9,6 +9,8 @@
#include <linux/compiler.h>
#include <linux/slab.h>
+#define alloc_hooks(_do, ...) _do
+
struct kmem_cache;
typedef void * (mempool_alloc_t)(gfp_t gfp_mask, void *pool_data);
@@ -46,7 +48,10 @@ extern mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn,
extern int mempool_resize(mempool_t *pool, int new_min_nr);
extern void mempool_destroy(mempool_t *pool);
-extern void *mempool_alloc(mempool_t *pool, gfp_t gfp_mask) __malloc;
+extern void *mempool_alloc_noprof(mempool_t *pool, gfp_t gfp_mask) __malloc;
+#define mempool_alloc(...) \
+ alloc_hooks(mempool_alloc_noprof(__VA_ARGS__))
+
extern void mempool_free(void *element, mempool_t *pool);
/*
diff --git a/include/linux/mm.h b/include/linux/mm.h
index d0fad5ab..cbcc86e6 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -23,11 +23,15 @@ struct sysinfo {
__u32 mem_unit; /* Memory unit size in bytes */
};
-
-
static inline void si_meminfo(struct sysinfo *val)
{
BUG_ON(syscall(SYS_sysinfo, val));
}
+extern unsigned long _totalram_pages;
+static inline unsigned long totalram_pages(void)
+{
+ return _totalram_pages;
+}
+
#endif /* _TOOLS_LINUX_MM_H */
diff --git a/include/linux/percpu-rwsem.h b/include/linux/percpu-rwsem.h
index 153251c0..20fa19a0 100644
--- a/include/linux/percpu-rwsem.h
+++ b/include/linux/percpu-rwsem.h
@@ -4,6 +4,7 @@
#define _LINUX_PERCPU_RWSEM_H
#include <pthread.h>
+#include <linux/cleanup.h>
#include <linux/preempt.h>
struct percpu_rw_semaphore {
@@ -55,4 +56,11 @@ static inline int percpu_init_rwsem(struct percpu_rw_semaphore *sem)
#define percpu_rwsem_assert_held(sem) do {} while (0)
+DEFINE_GUARD(percpu_read, struct percpu_rw_semaphore *,
+ percpu_down_read(_T), percpu_up_read(_T))
+DEFINE_GUARD_COND(percpu_read, _try, percpu_down_read_trylock(_T))
+
+DEFINE_GUARD(percpu_write, struct percpu_rw_semaphore *,
+ percpu_down_write(_T), percpu_up_write(_T))
+
#endif
diff --git a/include/linux/preempt.h b/include/linux/preempt.h
index dbc7c24d..534932f6 100644
--- a/include/linux/preempt.h
+++ b/include/linux/preempt.h
@@ -1,6 +1,8 @@
#ifndef __LINUX_PREEMPT_H
#define __LINUX_PREEMPT_H
+#include <linux/cleanup.h>
+
extern void preempt_disable(void);
extern void preempt_enable(void);
@@ -13,4 +15,7 @@ extern void preempt_enable(void);
#define preempt_enable_notrace() preempt_enable()
#define preemptible() 0
+DEFINE_LOCK_GUARD_0(preempt, preempt_disable(), preempt_enable())
+DEFINE_LOCK_GUARD_0(preempt_notrace, preempt_disable_notrace(), preempt_enable_notrace())
+
#endif /* __LINUX_PREEMPT_H */
diff --git a/include/linux/printk.h b/include/linux/printk.h
index cdafb9af..31ff7b65 100644
--- a/include/linux/printk.h
+++ b/include/linux/printk.h
@@ -9,14 +9,15 @@
#include <stdarg.h>
#include <stdio.h>
-#define KERN_EMERG ""
-#define KERN_ALERT ""
-#define KERN_CRIT ""
-#define KERN_ERR ""
-#define KERN_WARNING ""
-#define KERN_NOTICE ""
-#define KERN_INFO ""
-#define KERN_DEBUG ""
+#define KERN_EMERG KERN_SOH "0" /* system is unusable */
+#define KERN_ALERT KERN_SOH "1" /* action must be taken immediately */
+#define KERN_CRIT KERN_SOH "2" /* critical conditions */
+#define KERN_ERR KERN_SOH "3" /* error conditions */
+#define KERN_WARNING KERN_SOH "4" /* warning conditions */
+#define KERN_NOTICE KERN_SOH "5" /* normal but significant condition */
+#define KERN_INFO KERN_SOH "6" /* informational */
+#define KERN_DEBUG KERN_SOH "7" /* debug-level messages */
+
#define KERN_DEFAULT ""
#define KERN_CONT ""
#define KERN_SOH "\001"
@@ -46,8 +47,8 @@ static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
return i;
}
-#define printk(...) printf(__VA_ARGS__)
-#define vprintk(...) vprintf(__VA_ARGS__)
+void vprintk(const char *fmt, va_list args);
+void printk(const char *fmt, ...);
#define no_printk(fmt, ...) \
({ \
@@ -204,4 +205,7 @@ static inline int scnprintf(char * buf, size_t size, const char * fmt, ...)
#define pr_devel_ratelimited(fmt, ...) \
no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
#endif
+
+void dump_stack(void);
+
#endif /* __TOOLS_LINUX_PRINTK_H */
diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h
index f851d6a2..4dd30b71 100644
--- a/include/linux/rwsem.h
+++ b/include/linux/rwsem.h
@@ -2,6 +2,7 @@
#define __TOOLS_LINUX_RWSEM_H
#include <pthread.h>
+#include <linux/cleanup.h>
struct rw_semaphore {
pthread_rwlock_t lock;
@@ -18,12 +19,53 @@ static inline void init_rwsem(struct rw_semaphore *lock)
pthread_rwlock_init(&lock->lock, NULL);
}
-#define down_read(l) pthread_rwlock_rdlock(&(l)->lock)
-#define down_read_killable(l) (pthread_rwlock_rdlock(&(l)->lock), 0)
-#define down_read_trylock(l) (!pthread_rwlock_tryrdlock(&(l)->lock))
-#define up_read(l) pthread_rwlock_unlock(&(l)->lock)
+static inline void down_read(struct rw_semaphore *sem)
+{
+ pthread_rwlock_rdlock(&sem->lock);
+}
+
+static inline int down_read_trylock(struct rw_semaphore *sem)
+{
+ return !pthread_rwlock_tryrdlock(&sem->lock);
+}
+
+static inline int down_read_interruptible(struct rw_semaphore *sem)
+{
+ pthread_rwlock_rdlock(&sem->lock);
+ return 0;
+}
+
+static inline int down_read_killable(struct rw_semaphore *sem)
+{
+ pthread_rwlock_rdlock(&sem->lock);
+ return 0;
+}
+
+static inline void up_read(struct rw_semaphore *sem)
+{
+ pthread_rwlock_unlock(&sem->lock);
+}
+
+static inline void down_write(struct rw_semaphore *sem)
+{
+ pthread_rwlock_wrlock(&sem->lock);
+}
+
+static inline int down_write_trylock(struct rw_semaphore *sem)
+{
+ return !pthread_rwlock_trywrlock(&sem->lock);
+}
+
+static inline void up_write(struct rw_semaphore *sem)
+{
+ pthread_rwlock_unlock(&sem->lock);
+}
+
+DEFINE_GUARD(rwsem_read, struct rw_semaphore *, down_read(_T), up_read(_T))
+DEFINE_GUARD_COND(rwsem_read, _try, down_read_trylock(_T))
+DEFINE_GUARD_COND(rwsem_read, _intr, down_read_interruptible(_T) == 0)
-#define down_write(l) pthread_rwlock_wrlock(&(l)->lock)
-#define up_write(l) pthread_rwlock_unlock(&(l)->lock)
+DEFINE_GUARD(rwsem_write, struct rw_semaphore *, down_write(_T), up_write(_T))
+DEFINE_GUARD_COND(rwsem_write, _try, down_write_trylock(_T))
#endif /* __TOOLS_LINUX_RWSEM_H */
diff --git a/include/linux/sched/mm.h b/include/linux/sched/mm.h
index 34045ce0..2cbe0784 100644
--- a/include/linux/sched/mm.h
+++ b/include/linux/sched/mm.h
@@ -1,6 +1,8 @@
#ifndef _LINUX_SCHED_MM_H
#define _LINUX_SCHED_MM_H
+#include <linux/mm.h>
+
#define PF_MEMALLOC 0x00000800 /* Allocating memory */
#define PF_MEMALLOC_NOFS 0x00040000 /* All allocation requests will inherit GFP_NOFS */
diff --git a/include/linux/sort.h b/include/linux/sort.h
index d8a86590..4f45c7dc 100644
--- a/include/linux/sort.h
+++ b/include/linux/sort.h
@@ -27,5 +27,6 @@ static inline void sort(void *base, size_t num, size_t size,
}
#define sort_nonatomic(...) sort(__VA_ARGS__)
+#define sort_r_nonatomic(...) sort_r(__VA_ARGS__)
#endif
diff --git a/include/linux/spinlock.h b/include/linux/spinlock.h
index 5c83c766..20cb1756 100644
--- a/include/linux/spinlock.h
+++ b/include/linux/spinlock.h
@@ -42,11 +42,11 @@ DEFINE_LOCK_GUARD_1(spinlock, spinlock_t,
spin_unlock(_T->lock))
DEFINE_LOCK_GUARD_1_COND(spinlock, _try, spin_trylock(_T->lock))
-#if 0
DEFINE_LOCK_GUARD_1(spinlock_irq, spinlock_t,
spin_lock_irq(_T->lock),
spin_unlock_irq(_T->lock))
+#if 0
DEFINE_LOCK_GUARD_1_COND(spinlock_irq, _try,
spin_trylock_irq(_T->lock))
diff --git a/include/linux/types.h b/include/linux/types.h
index 5ee5ebc6..a1473592 100644
--- a/include/linux/types.h
+++ b/include/linux/types.h
@@ -53,6 +53,12 @@ typedef __s16 s16;
typedef __u8 u8;
typedef __s8 s8;
+typedef unsigned char unchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+typedef unsigned long long ullong;
+
#ifdef __CHECKER__
#define __bitwise__ __attribute__((bitwise))
#else