Fri Apr 17 17:24:46 2020 UTC ()
Slightly reorder for clarity, and add header.


(maxv)
diff -r1.139 -r1.140 src/sys/lib/libkern/libkern.h

cvs diff -r1.139 -r1.140 src/sys/lib/libkern/libkern.h (expand / switch to unified diff)

--- src/sys/lib/libkern/libkern.h 2020/04/07 08:07:58 1.139
+++ src/sys/lib/libkern/libkern.h 2020/04/17 17:24:46 1.140
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: libkern.h,v 1.139 2020/04/07 08:07:58 skrll Exp $ */ 1/* $NetBSD: libkern.h,v 1.140 2020/04/17 17:24:46 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1992, 1993 4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -28,26 +28,27 @@ @@ -28,26 +28,27 @@
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 * 30 *
31 * @(#)libkern.h 8.2 (Berkeley) 8/5/94 31 * @(#)libkern.h 8.2 (Berkeley) 8/5/94
32 */ 32 */
33 33
34#ifndef _LIB_LIBKERN_LIBKERN_H_ 34#ifndef _LIB_LIBKERN_LIBKERN_H_
35#define _LIB_LIBKERN_LIBKERN_H_ 35#define _LIB_LIBKERN_LIBKERN_H_
36 36
37#ifdef _KERNEL_OPT 37#ifdef _KERNEL_OPT
38#include "opt_diagnostic.h" 38#include "opt_diagnostic.h"
39#include "opt_kasan.h" 39#include "opt_kasan.h"
40#include "opt_kcsan.h" 40#include "opt_kcsan.h"
 41#include "opt_kmsan.h"
41#endif 42#endif
42 43
43#include <sys/types.h> 44#include <sys/types.h>
44#include <sys/inttypes.h> 45#include <sys/inttypes.h>
45#include <sys/null.h> 46#include <sys/null.h>
46 47
47#ifndef LIBKERN_INLINE 48#ifndef LIBKERN_INLINE
48#define LIBKERN_INLINE static __inline 49#define LIBKERN_INLINE static __inline
49#define LIBKERN_BODY 50#define LIBKERN_BODY
50#endif 51#endif
51 52
52LIBKERN_INLINE int imax(int, int) __unused; 53LIBKERN_INLINE int imax(int, int) __unused;
53LIBKERN_INLINE int imin(int, int) __unused; 54LIBKERN_INLINE int imin(int, int) __unused;
@@ -350,27 +351,26 @@ tolower(int ch) @@ -350,27 +351,26 @@ tolower(int ch)
350#endif 351#endif
351 352
352#define container_of(PTR, TYPE, FIELD) \ 353#define container_of(PTR, TYPE, FIELD) \
353 ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \ 354 ((TYPE *)(((char *)(PTR)) - offsetof(TYPE, FIELD)) \
354 + __validate_container_of(PTR, TYPE, FIELD)) 355 + __validate_container_of(PTR, TYPE, FIELD))
355#define const_container_of(PTR, TYPE, FIELD) \ 356#define const_container_of(PTR, TYPE, FIELD) \
356 ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \ 357 ((const TYPE *)(((const char *)(PTR)) - offsetof(TYPE, FIELD)) \
357 + __validate_const_container_of(PTR, TYPE, FIELD)) 358 + __validate_const_container_of(PTR, TYPE, FIELD))
358 359
359/* Prototypes for which GCC built-ins exist. */ 360/* Prototypes for which GCC built-ins exist. */
360void *memcpy(void *, const void *, size_t); 361void *memcpy(void *, const void *, size_t);
361int memcmp(const void *, const void *, size_t); 362int memcmp(const void *, const void *, size_t);
362void *memset(void *, int, size_t); 363void *memset(void *, int, size_t);
363void *memmem(const void *, size_t, const void *, size_t); 
364#if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) 364#if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE)
365#if defined(_KERNEL) && defined(KASAN) 365#if defined(_KERNEL) && defined(KASAN)
366void *kasan_memcpy(void *, const void *, size_t); 366void *kasan_memcpy(void *, const void *, size_t);
367int kasan_memcmp(const void *, const void *, size_t); 367int kasan_memcmp(const void *, const void *, size_t);
368void *kasan_memset(void *, int, size_t); 368void *kasan_memset(void *, int, size_t);
369#define memcpy(d, s, l) kasan_memcpy(d, s, l) 369#define memcpy(d, s, l) kasan_memcpy(d, s, l)
370#define memcmp(a, b, l) kasan_memcmp(a, b, l) 370#define memcmp(a, b, l) kasan_memcmp(a, b, l)
371#define memset(d, v, l) kasan_memset(d, v, l) 371#define memset(d, v, l) kasan_memset(d, v, l)
372#elif defined(_KERNEL) && defined(KCSAN) 372#elif defined(_KERNEL) && defined(KCSAN)
373void *kcsan_memcpy(void *, const void *, size_t); 373void *kcsan_memcpy(void *, const void *, size_t);
374int kcsan_memcmp(const void *, const void *, size_t); 374int kcsan_memcmp(const void *, const void *, size_t);
375void *kcsan_memset(void *, int, size_t); 375void *kcsan_memset(void *, int, size_t);
376#define memcpy(d, s, l) kcsan_memcpy(d, s, l) 376#define memcpy(d, s, l) kcsan_memcpy(d, s, l)
@@ -379,32 +379,31 @@ void *kcsan_memset(void *, int, size_t); @@ -379,32 +379,31 @@ void *kcsan_memset(void *, int, size_t);
379#elif defined(_KERNEL) && defined(KMSAN) 379#elif defined(_KERNEL) && defined(KMSAN)
380void *kmsan_memcpy(void *, const void *, size_t); 380void *kmsan_memcpy(void *, const void *, size_t);
381int kmsan_memcmp(const void *, const void *, size_t); 381int kmsan_memcmp(const void *, const void *, size_t);
382void *kmsan_memset(void *, int, size_t); 382void *kmsan_memset(void *, int, size_t);
383#define memcpy(d, s, l) kmsan_memcpy(d, s, l) 383#define memcpy(d, s, l) kmsan_memcpy(d, s, l)
384#define memcmp(a, b, l) kmsan_memcmp(a, b, l) 384#define memcmp(a, b, l) kmsan_memcmp(a, b, l)
385#define memset(d, v, l) kmsan_memset(d, v, l) 385#define memset(d, v, l) kmsan_memset(d, v, l)
386#else 386#else
387#define memcpy(d, s, l) __builtin_memcpy(d, s, l) 387#define memcpy(d, s, l) __builtin_memcpy(d, s, l)
388#define memcmp(a, b, l) __builtin_memcmp(a, b, l) 388#define memcmp(a, b, l) __builtin_memcmp(a, b, l)
389#define memset(d, v, l) __builtin_memset(d, v, l) 389#define memset(d, v, l) __builtin_memset(d, v, l)
390#endif 390#endif
391#endif 391#endif
 392void *memmem(const void *, size_t, const void *, size_t);
392 393
393char *strcpy(char *, const char *); 394char *strcpy(char *, const char *);
394int strcmp(const char *, const char *); 395int strcmp(const char *, const char *);
395size_t strlen(const char *); 396size_t strlen(const char *);
396size_t strnlen(const char *, size_t); 
397char *strsep(char **, const char *); 
398#if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE) 397#if __GNUC_PREREQ__(2, 95) && !defined(_STANDALONE)
399#if defined(_KERNEL) && defined(KASAN) 398#if defined(_KERNEL) && defined(KASAN)
400char *kasan_strcpy(char *, const char *); 399char *kasan_strcpy(char *, const char *);
401int kasan_strcmp(const char *, const char *); 400int kasan_strcmp(const char *, const char *);
402size_t kasan_strlen(const char *); 401size_t kasan_strlen(const char *);
403#define strcpy(d, s) kasan_strcpy(d, s) 402#define strcpy(d, s) kasan_strcpy(d, s)
404#define strcmp(a, b) kasan_strcmp(a, b) 403#define strcmp(a, b) kasan_strcmp(a, b)
405#define strlen(a) kasan_strlen(a) 404#define strlen(a) kasan_strlen(a)
406#elif defined(_KERNEL) && defined(KCSAN) 405#elif defined(_KERNEL) && defined(KCSAN)
407char *kcsan_strcpy(char *, const char *); 406char *kcsan_strcpy(char *, const char *);
408int kcsan_strcmp(const char *, const char *); 407int kcsan_strcmp(const char *, const char *);
409size_t kcsan_strlen(const char *); 408size_t kcsan_strlen(const char *);
410#define strcpy(d, s) kcsan_strcpy(d, s) 409#define strcpy(d, s) kcsan_strcpy(d, s)
@@ -413,54 +412,52 @@ size_t kcsan_strlen(const char *); @@ -413,54 +412,52 @@ size_t kcsan_strlen(const char *);
413#elif defined(_KERNEL) && defined(KMSAN) 412#elif defined(_KERNEL) && defined(KMSAN)
414char *kmsan_strcpy(char *, const char *); 413char *kmsan_strcpy(char *, const char *);
415int kmsan_strcmp(const char *, const char *); 414int kmsan_strcmp(const char *, const char *);
416size_t kmsan_strlen(const char *); 415size_t kmsan_strlen(const char *);
417#define strcpy(d, s) kmsan_strcpy(d, s) 416#define strcpy(d, s) kmsan_strcpy(d, s)
418#define strcmp(a, b) kmsan_strcmp(a, b) 417#define strcmp(a, b) kmsan_strcmp(a, b)
419#define strlen(a) kmsan_strlen(a) 418#define strlen(a) kmsan_strlen(a)
420#else 419#else
421#define strcpy(d, s) __builtin_strcpy(d, s) 420#define strcpy(d, s) __builtin_strcpy(d, s)
422#define strcmp(a, b) __builtin_strcmp(a, b) 421#define strcmp(a, b) __builtin_strcmp(a, b)
423#define strlen(a) __builtin_strlen(a) 422#define strlen(a) __builtin_strlen(a)
424#endif 423#endif
425#endif 424#endif
 425size_t strnlen(const char *, size_t);
 426char *strsep(char **, const char *);
426 427
427/* Functions for which we always use built-ins. */ 428/* Functions for which we always use built-ins. */
428#ifdef __GNUC__ 429#ifdef __GNUC__
429#define alloca(s) __builtin_alloca(s) 430#define alloca(s) __builtin_alloca(s)
430#endif 431#endif
431 432
 433/* These exist in GCC 3.x, but we don't bother. */
432char *strcat(char *, const char *); 434char *strcat(char *, const char *);
433char *strchr(const char *, int); 435char *strchr(const char *, int);
434char *strrchr(const char *, int); 436char *strrchr(const char *, int);
435/* These exist in GCC 3.x, but we don't bother. */ 
436#if defined(_KERNEL) && defined(KASAN) 437#if defined(_KERNEL) && defined(KASAN)
437char *kasan_strcat(char *, const char *); 438char *kasan_strcat(char *, const char *);
438char *kasan_strchr(const char *, int); 439char *kasan_strchr(const char *, int);
439char *kasan_strrchr(const char *, int); 440char *kasan_strrchr(const char *, int);
440#define strcat(d, s) kasan_strcat(d, s) 441#define strcat(d, s) kasan_strcat(d, s)
441#define strchr(s, c) kasan_strchr(s, c) 442#define strchr(s, c) kasan_strchr(s, c)
442#define strrchr(s, c) kasan_strrchr(s, c) 443#define strrchr(s, c) kasan_strrchr(s, c)
443#elif defined(_KERNEL) && defined(KMSAN) 444#elif defined(_KERNEL) && defined(KMSAN)
444char *kmsan_strcat(char *, const char *); 445char *kmsan_strcat(char *, const char *);
445char *kmsan_strchr(const char *, int); 446char *kmsan_strchr(const char *, int);
446char *kmsan_strrchr(const char *, int); 447char *kmsan_strrchr(const char *, int);
447#define strcat(d, s) kmsan_strcat(d, s) 448#define strcat(d, s) kmsan_strcat(d, s)
448#define strchr(s, c) kmsan_strchr(s, c) 449#define strchr(s, c) kmsan_strchr(s, c)
449#define strrchr(s, c) kmsan_strrchr(s, c) 450#define strrchr(s, c) kmsan_strrchr(s, c)
450#else 
451char *strcat(char *, const char *); 
452char *strchr(const char *, int); 
453char *strrchr(const char *, int); 
454#endif 451#endif
455size_t strcspn(const char *, const char *); 452size_t strcspn(const char *, const char *);
456char *strncpy(char *, const char *, size_t); 453char *strncpy(char *, const char *, size_t);
457char *strncat(char *, const char *, size_t); 454char *strncat(char *, const char *, size_t);
458int strncmp(const char *, const char *, size_t); 455int strncmp(const char *, const char *, size_t);
459char *strstr(const char *, const char *); 456char *strstr(const char *, const char *);
460char *strpbrk(const char *, const char *); 457char *strpbrk(const char *, const char *);
461size_t strspn(const char *, const char *); 458size_t strspn(const char *, const char *);
462 459
463/* 460/*
464 * ffs is an instruction on vax. 461 * ffs is an instruction on vax.
465 */ 462 */
466int ffs(int); 463int ffs(int);