Changeset View
Standalone View
sys/compat/linuxkpi/common/include/linux/kernel.h
Show First 20 Lines • Show All 587 Lines • ▼ Show 20 Lines | #define type_min(datatype) ( \ | ||||
(sizeof(datatype) >= 4) ? (is_signed(datatype) ? INT32_MIN : 0) : \ | (sizeof(datatype) >= 4) ? (is_signed(datatype) ? INT32_MIN : 0) : \ | ||||
(sizeof(datatype) >= 2) ? (is_signed(datatype) ? INT16_MIN : 0) : \ | (sizeof(datatype) >= 2) ? (is_signed(datatype) ? INT16_MIN : 0) : \ | ||||
(is_signed(datatype) ? INT8_MIN : 0) \ | (is_signed(datatype) ? INT8_MIN : 0) \ | ||||
) | ) | ||||
#define TAINT_WARN 0 | #define TAINT_WARN 0 | ||||
#define test_taint(x) (0) | #define test_taint(x) (0) | ||||
/* | |||||
* Checking if an option is defined would be easy if we could do CPP inside CPP. | |||||
* The defined case whether -Dxxx or -Dxxx=1 are easy to deal with. In either | |||||
* case the defined value is "1". A more general -Dxxx=<c> case will require | |||||
* more effort to deal with all possible "true" values. Hope we do not have | |||||
* to do this as well. | |||||
* The real problem is the undefined case. To avoid this problem we do the | |||||
* concat/varargs trick: "yyy" ## xxx can make two arguments if xxx is "1" | |||||
* by having a #define for yyy_1 which is "ignore,". | |||||
* Otherwise we will just get "yyy". | |||||
* Need to be careful about variable substitutions in macros though. | |||||
* This way we make a (true, false) problem a (don't care, true, false) or a | |||||
* (don't care true, false). Then we can use a variadic macro to only select | |||||
* the always well known and defined argument #2. And that seems to be | |||||
* exactly what we need. Use 1 for true and 0 for false to also allow | |||||
* #if IS_*() checks pre-compiler checks which do not like #if true. | |||||
hselasky: Hi Bjoern,
Can you generalize these macros like this instead?
```
#define YES(...)… | |||||
Done Inline ActionsThis is not going to work; you need an intermediate as otherwise you end up with PASS(EVAL(___XAB_CONFIG_FOO)) (and an extra _ in your example above): #define IS_BULTIN(_x) PASS(EVAL(__XAB_##_x)) becomes: #define _IS_XAB(_x) PASS(EVAL(___XAB_##_x)) #define IS_BUILTIN(_x) _IS_XAB(_x) #define IS_MODULE(_x) _IS_XAB(_x ## _MODULE) I'll be happy to use whatever name for _IS_XAB(_x_ ... __IS_ZERO_ONE(_x)? I think otherwise we might be good for as long as the input values will indeed always be 0 and 1. Let's hope the format doesn't change. That said do we also need to use an `__enabled_` prefix as well then? Will make our Makefiles ugly ... I haven't seen the Linux files only just read an online article about how these options are generated and expanded. bz: This is not going to work; you need an intermediate as otherwise you end up with PASS(EVAL… | |||||
Done Inline ActionsIt doesn't actually work. In the undefined case EVAL() will be presented a "_XAB_CONFIG_FOO" and become (0 _XAB_CONFIG_FOO(+1)) and fail compiling. I'll keep pondering this a bit more over the next hour .. do you have some more input? I believe for the same reason the IS_MODULE() case will also not work in my version though I haven't tested that yet. bz: It doesn't actually work.
In the undefined case EVAL() will be presented a "_XAB_CONFIG_FOO"… | |||||
Done Inline ActionsIgnore the IS_MODULE() case; that will work as it'll end with false as wall in the undefined case. bz: Ignore the IS_MODULE() case; that will work as it'll end with false as wall in the undefined… | |||||
Not Done Inline Actions
Yes, I miscounted the number if "_" characters in those macros. Glad you figured it out.
Do you need the _IS_XAB() macro. Can't you just expand it where you use it?
It will be easy to fix if the values are y/n/m instead.
Haven't seen this in use during my experiences with the Linux kernel. --HPS hselasky: > and an extra _ in your example above
Yes, I miscounted the number if "_" characters in those… | |||||
*/ | |||||
#define ___XAB_1 dontcare, | |||||
#define ___IS_XAB(_ignore, _x, ...) (_x) | |||||
#define __IS_XAB(_x) ___IS_XAB(_x 1, 0) | |||||
#define _IS_XAB(_x) __IS_XAB(__CONCAT(___XAB_, _x)) | |||||
/* This is if CONFIG_ccc=y. */ | |||||
#define IS_BUILTIN(_x) _IS_XAB(_x) | |||||
/* This is if CONFIG_ccc=m. */ | |||||
#define IS_MODULE(_x) _IS_XAB(_x ## _MODULE) | |||||
/* This is if CONFIG_ccc is compiled in(=y) or a module(=m). */ | |||||
#define IS_ENABLED(_x) (IS_BUILTIN(_x) || IS_MODULE(_x)) | |||||
/* | |||||
* This is weird case. If the CONFIG_ccc is builtin (=y) this returns true; | |||||
* or if the CONFIG_ccc is a module (=m) and the caller is built as a module | |||||
* (-DMODULE defined) this returns true, but if the callers is not a module | |||||
* (-DMODULE not defined, which means caller is BUILTIN) then it returns | |||||
* false. In other words, a module can reach the kernel, a module can reach | |||||
* a module, but the kernel cannot reach a module, and code never compiled | |||||
* cannot be reached either. | |||||
* XXX -- I'd hope the module-to-module case would be handled by a proper | |||||
* module dependency definition (MODULE_DEPEND() in FreeBSD). | |||||
*/ | |||||
#define IS_REACHABLE(_x) (IS_BUILTIN(_x) || \ | |||||
(IS_MODULE(_x) && IS_BUILTIN(MODULE))) | |||||
#endif /* _LINUX_KERNEL_H_ */ | #endif /* _LINUX_KERNEL_H_ */ |
Hi Bjoern,
Can you generalize these macros like this instead?