Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/lib/libkern/libkern.h,v rcsdiff: /ftp/cvs/cvsroot/src/sys/lib/libkern/libkern.h,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.116 retrieving revision 1.116.2.3 diff -u -p -r1.116 -r1.116.2.3 --- src/sys/lib/libkern/libkern.h 2014/11/20 16:25:16 1.116 +++ src/sys/lib/libkern/libkern.h 2015/09/22 12:06:07 1.116.2.3 @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.116 2014/11/20 16:25:16 christos Exp $ */ +/* $NetBSD: libkern.h,v 1.116.2.3 2015/09/22 12:06:07 skrll Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -34,6 +34,10 @@ #ifndef _LIB_LIBKERN_LIBKERN_H_ #define _LIB_LIBKERN_LIBKERN_H_ +#ifdef _KERNEL_OPT +#include "opt_diagnostic.h" +#endif + #include #include #include @@ -309,9 +313,43 @@ tolower(int ch) #endif #endif +/* + * Return the container of an embedded struct. Given x = &c->f, + * container_of(x, T, f) yields c, where T is the type of c. Example: + * + * struct foo { ... }; + * struct bar { + * int b_x; + * struct foo b_foo; + * ... + * }; + * + * struct bar b; + * struct foo *fp = b.b_foo; + * + * Now we can get at b from fp by: + * + * struct bar *bp = container_of(fp, struct bar, b_foo); + * + * The 0*sizeof((PTR) - ...) causes the compiler to warn if the type of + * *fp does not match the type of struct bar::b_foo. + * We skip the validation for coverity runs to avoid warnings. + */ +#ifdef __COVERITY__ +#define __validate_container_of(PTR, TYPE, FIELD) 0 +#else +#define __validate_container_of(PTR, TYPE, FIELD) \ + (0 * sizeof((PTR) - &((TYPE *)(((char *)(PTR)) - \ + offsetof(TYPE, FIELD)))->FIELD)) +#endif + +#define container_of(PTR, TYPE, FIELD) \ + ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \ + + __validate_container_of(PTR, TYPE, FIELD)) + #define MTPRNG_RLEN 624 struct mtprng_state { - unsigned int mt_idx; + unsigned int mt_idx; uint32_t mt_elem[MTPRNG_RLEN]; uint32_t mt_count; uint32_t mt_sparse[3]; @@ -399,16 +437,30 @@ long long strtoll(const char *, char **, unsigned long long strtoull(const char *, char **, int); intmax_t strtoimax(const char *, char **, int); uintmax_t strtoumax(const char *, char **, int); +intmax_t strtoi(const char * __restrict, char ** __restrict, int, intmax_t, + intmax_t, int *); +uintmax_t strtou(const char * __restrict, char ** __restrict, int, uintmax_t, + uintmax_t, int *); + int snprintb(char *, size_t, const char *, uint64_t); int snprintb_m(char *, size_t, const char *, uint64_t, size_t); int kheapsort(void *, size_t, size_t, int (*)(const void *, const void *), void *); uint32_t crc32(uint32_t, const uint8_t *, size_t); +#if __GNUC_PREREQ__(4, 5) \ + && (defined(__alpha_cix__) || defined(__mips_popcount)) +#define popcount __builtin_popcount +#define popcountl __builtin_popcountl +#define popcountll __builtin_popcountll +#define popcount32 __builtin_popcount +#define popcount64 __builtin_popcountll +#else unsigned int popcount(unsigned int) __constfunc; unsigned int popcountl(unsigned long) __constfunc; unsigned int popcountll(unsigned long long) __constfunc; unsigned int popcount32(uint32_t) __constfunc; unsigned int popcount64(uint64_t) __constfunc; +#endif void *explicit_memset(void *, int, size_t); int consttime_memequal(const void *, const void *, size_t);