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.126 retrieving revision 1.126.4.2 diff -u -p -r1.126 -r1.126.4.2 --- src/sys/lib/libkern/libkern.h 2017/12/09 00:51:52 1.126 +++ src/sys/lib/libkern/libkern.h 2020/04/08 14:08:52 1.126.4.2 @@ -1,4 +1,4 @@ -/* $NetBSD: libkern.h,v 1.126 2017/12/09 00:51:52 christos Exp $ */ +/* $NetBSD: libkern.h,v 1.126.4.2 2020/04/08 14:08:52 martin Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -36,6 +36,7 @@ #ifdef _KERNEL_OPT #include "opt_diagnostic.h" +#include "opt_kasan.h" #endif #include @@ -49,8 +50,8 @@ LIBKERN_INLINE int imax(int, int) __unused; LIBKERN_INLINE int imin(int, int) __unused; -LIBKERN_INLINE u_int max(u_int, u_int) __unused; -LIBKERN_INLINE u_int min(u_int, u_int) __unused; +LIBKERN_INLINE u_int uimax(u_int, u_int) __unused; +LIBKERN_INLINE u_int uimin(u_int, u_int) __unused; LIBKERN_INLINE long lmax(long, long) __unused; LIBKERN_INLINE long lmin(long, long) __unused; LIBKERN_INLINE u_long ulmax(u_long, u_long) __unused; @@ -97,12 +98,12 @@ lmin(long a, long b) return (a < b ? a : b); } LIBKERN_INLINE u_int -max(u_int a, u_int b) +uimax(u_int a, u_int b) { return (a > b ? a : b); } LIBKERN_INLINE u_int -min(u_int a, u_int b) +uimin(u_int a, u_int b) { return (a < b ? a : b); } @@ -354,24 +355,24 @@ tolower(int ch) ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \ + __validate_const_container_of(PTR, TYPE, FIELD)) -#define MTPRNG_RLEN 624 -struct mtprng_state { - unsigned int mt_idx; - uint32_t mt_elem[MTPRNG_RLEN]; - uint32_t mt_count; - uint32_t mt_sparse[3]; -}; - /* Prototypes for which GCC built-ins exist. */ void *memcpy(void *, const void *, size_t); int memcmp(const void *, const void *, size_t); void *memset(void *, int, size_t); +void *memmem(const void *, size_t, const void *, size_t); #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) +#if defined(_KERNEL) && defined(KASAN) +void *kasan_memset(void *, int, size_t); +int kasan_memcmp(const void *, const void *, size_t); +void *kasan_memcpy(void *, const void *, size_t); +#define memcpy(d, s, l) kasan_memcpy(d, s, l) +#define memcmp(a, b, l) kasan_memcmp(a, b, l) +#define memset(d, v, l) kasan_memset(d, v, l) +#else #define memcpy(d, s, l) __builtin_memcpy(d, s, l) #define memcmp(a, b, l) __builtin_memcmp(a, b, l) -#endif -#if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) #define memset(d, v, l) __builtin_memset(d, v, l) +#endif /* _KERNEL && KASAN */ #endif char *strcpy(char *, const char *); @@ -380,9 +381,18 @@ size_t strlen(const char *); size_t strnlen(const char *, size_t); char *strsep(char **, const char *); #if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) +#if defined(_KERNEL) && defined(KASAN) +char *kasan_strcpy(char *, const char *); +int kasan_strcmp(const char *, const char *); +size_t kasan_strlen(const char *); +#define strcpy(d, s) kasan_strcpy(d, s) +#define strcmp(a, b) kasan_strcmp(a, b) +#define strlen(a) kasan_strlen(a) +#else #define strcpy(d, s) __builtin_strcpy(d, s) #define strcmp(a, b) __builtin_strcmp(a, b) #define strlen(a) __builtin_strlen(a) +#endif /* _KERNEL && KASAN */ #endif /* Functions for which we always use built-ins. */ @@ -391,13 +401,29 @@ char *strsep(char **, const char *); #endif /* These exist in GCC 3.x, but we don't bother. */ +#if defined(_KERNEL) && defined(KASAN) +char *kasan_strcat(char *, const char *); +char *kasan_strchr(const char *, int); +char *kasan_strrchr(const char *, int); +#define strcat(d, s) kasan_strcat(d, s) +#define strchr(s, c) kasan_strchr(s, c) +#define strrchr(s, c) kasan_strrchr(s, c) +#elif defined(_KERNEL) && defined(KMSAN) +char *kmsan_strcat(char *, const char *); +char *kmsan_strchr(const char *, int); +char *kmsan_strrchr(const char *, int); +#define strcat(d, s) kmsan_strcat(d, s) +#define strchr(s, c) kmsan_strchr(s, c) +#define strrchr(s, c) kmsan_strrchr(s, c) +#else char *strcat(char *, const char *); +char *strchr(const char *, int); +char *strrchr(const char *, int); +#endif size_t strcspn(const char *, const char *); char *strncpy(char *, const char *, size_t); char *strncat(char *, const char *, size_t); int strncmp(const char *, const char *, size_t); -char *strchr(const char *, int); -char *strrchr(const char *, int); char *strstr(const char *, const char *); char *strpbrk(const char *, const char *); size_t strspn(const char *, const char *); @@ -429,10 +455,6 @@ char *setstate(char *); long random(void); void mi_vector_hash(const void * __restrict, size_t, uint32_t, uint32_t[3]); -void mtprng_init32(struct mtprng_state *, uint32_t); -void mtprng_initarray(struct mtprng_state *, const uint32_t *, size_t); -uint32_t mtprng_rawrandom(struct mtprng_state *); -uint32_t mtprng_random(struct mtprng_state *); int scanc(u_int, const u_char *, const u_char *, int); int skpc(int, size_t, u_char *); int strcasecmp(const char *, const char *); @@ -478,23 +500,4 @@ int strnvisx(char *, size_t, const char #define VIS_SAFE 0x20 #define VIS_TRIM 0x40 -#ifdef notyet -/* - * LZF hashtable/state size: on uncompressible data and on a system with - * a sufficiently large d-cache, a larger table produces a considerable - * speed benefit. On systems with small memory and caches, however... - */ -#if defined(__vax__) || defined(__m68k__) -#define LZF_HLOG 14 -#else -#define LZF_HLOG 15 -#endif -typedef const uint8_t *LZF_STATE[1 << LZF_HLOG]; - -unsigned int lzf_compress_r (const void *const, unsigned int, void *, - unsigned int, LZF_STATE); -unsigned int lzf_decompress (const void *const, unsigned int, void *, - unsigned int); -#endif - #endif /* !_LIB_LIBKERN_LIBKERN_H_ */