#ifndef __LINUX_COMPILER_H #define __LINUX_COMPILER_H #ifndef __ASSEMBLY__ #ifdef __CHECKER__ # define __user __attribute__((noderef, address_space(1))) # define __kernel __attribute__((address_space(0))) # define __safe __attribute__((safe)) # define __force __attribute__((force)) # define __nocast __attribute__((nocast)) # define __iomem __attribute__((noderef, address_space(2))) # define __acquires(x) __attribute__((context(x,0,1))) # define __releases(x) __attribute__((context(x,1,0))) # define __acquire(x) __context__(x,1) # define __release(x) __context__(x,-1) # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) # define __percpu __attribute__((noderef, address_space(3))) #ifdef CONFIG_SPARSE_RCU_POINTER # define __rcu __attribute__((noderef, address_space(4))) #else # define __rcu #endif extern void __chk_user_ptr(const volatile void __user *); extern void __chk_io_ptr(const volatile void __iomem *); #else # define __user # define __kernel # define __safe # define __force # define __nocast # define __iomem # define __chk_user_ptr(x) (void)0 # define __chk_io_ptr(x) (void)0 # define __builtin_warning(x, y...) (1) # define __acquires(x) # define __releases(x) # define __acquire(x) (void)0 # define __release(x) (void)0 # define __cond_lock(x,c) (c) # define __percpu # define __rcu #endif #ifdef __KERNEL__ #ifdef __GNUC__ #include #endif #define notrace __attribute__((no_instrument_function)) #ifdef __INTEL_COMPILER # include #endif struct ftrace_branch_data { const char *func; const char *file; unsigned line; union { struct { unsigned long correct; unsigned long incorrect; }; struct { unsigned long miss; unsigned long hit; }; unsigned long miss_hit[2]; }; }; #if defined(CONFIG_TRACE_BRANCH_PROFILING) \ && !defined(DISABLE_BRANCH_PROFILING) && !defined(__CHECKER__) void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); #define likely_notrace(x) __builtin_expect(!!(x), 1) #define unlikely_notrace(x) __builtin_expect(!!(x), 0) #define __branch_check__(x, expect) ({ \ int ______r; \ static struct ftrace_branch_data \ __attribute__((__aligned__(4))) \ __attribute__((section("_ftrace_annotated_branch"))) \ ______f = { \ .func = __func__, \ .file = __FILE__, \ .line = __LINE__, \ }; \ ______r = likely_notrace(x); \ ftrace_likely_update(&______f, ______r, expect); \ ______r; \ }) /* * Using __builtin_constant_p(x) to ignore cases where the return * value is always the same. This idea is taken from a similar patch * written by Daniel Walker. */ # ifndef likely # define likely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 1)) # endif # ifndef unlikely # define unlikely(x) (__builtin_constant_p(x) ? !!(x) : __branch_check__(x, 0)) # endif #ifdef CONFIG_PROFILE_ALL_BRANCHES #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) ) #define __trace_if(cond) \ if (__builtin_constant_p((cond)) ? !!(cond) : \ ({ \ int ______r; \ static struct ftrace_branch_data \ __attribute__((__aligned__(4))) \ __attribute__((section("_ftrace_branch"))) \ ______f = { \ .func = __func__, \ .file = __FILE__, \ .line = __LINE__, \ }; \ ______r = !!(cond); \ ______f.miss_hit[______r]++; \ ______r; \ })) #endif #else # define likely(x) __builtin_expect(!!(x), 1) # define unlikely(x) __builtin_expect(!!(x), 0) #endif #ifndef barrier # define barrier() __memory_barrier() #endif #ifndef unreachable # define unreachable() do { } while (1) #endif #ifndef RELOC_HIDE # define RELOC_HIDE(ptr, off) \ ({ unsigned long __ptr; \ __ptr = (unsigned long) (ptr); \ (typeof(ptr)) (__ptr + (off)); }) #endif #endif #endif #ifdef __KERNEL__ #ifndef __deprecated # define __deprecated #endif #ifdef MODULE #define __deprecated_for_modules __deprecated #else #define __deprecated_for_modules #endif #ifndef __must_check #define __must_check #endif #ifndef CONFIG_ENABLE_MUST_CHECK #undef __must_check #define __must_check #endif #ifndef CONFIG_ENABLE_WARN_DEPRECATED #undef __deprecated #undef __deprecated_for_modules #define __deprecated #define __deprecated_for_modules #endif #ifndef __used # define __used #endif #ifndef __maybe_unused # define __maybe_unused #endif #ifndef __always_unused # define __always_unused #endif #ifndef noinline #define noinline #endif #define noinline_for_stack noinline #ifndef __always_inline #define __always_inline inline #endif #endif #ifndef __attribute_const__ # define __attribute_const__ #endif #ifndef __cold #define __cold #endif #ifndef __section # define __section(S) __attribute__ ((__section__(#S))) #endif #ifndef __same_type # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) #endif #ifndef __compiletime_object_size # define __compiletime_object_size(obj) -1 #endif #ifndef __compiletime_warning # define __compiletime_warning(message) #endif #ifndef __compiletime_error # define __compiletime_error(message) #endif #ifndef __linktime_error # define __linktime_error(message) #endif #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) #endif