Sun Mar 14 02:53:57 2021 UTC ()
Comment on CTASSERT() in COND_SET_STRUCT(); this is a sanity check to
avoid hashing/assigning large structure. Upper-bound is arbitrary, but
be carefully for performance penalty if bumping.

Thanks christos for discussion.


(rin)
diff -r1.299 -r1.300 src/sys/sys/systm.h

cvs diff -r1.299 -r1.300 src/sys/sys/systm.h (expand / switch to unified diff)

--- src/sys/sys/systm.h 2021/03/10 13:27:51 1.299
+++ src/sys/sys/systm.h 2021/03/14 02:53:57 1.300
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: systm.h,v 1.299 2021/03/10 13:27:51 simonb Exp $ */ 1/* $NetBSD: systm.h,v 1.300 2021/03/14 02:53:57 rin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1982, 1988, 1991, 1993 4 * Copyright (c) 1982, 1988, 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc. 6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed 7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph 8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc. 10 * the permission of UNIX System Laboratories, Inc.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -182,26 +182,31 @@ int enoioctl(void); @@ -182,26 +182,31 @@ int enoioctl(void);
182int enxio(void); 182int enxio(void);
183int eopnotsupp(void); 183int eopnotsupp(void);
184 184
185enum hashtype { 185enum hashtype {
186 HASH_LIST, 186 HASH_LIST,
187 HASH_SLIST, 187 HASH_SLIST,
188 HASH_TAILQ, 188 HASH_TAILQ,
189 HASH_PSLIST 189 HASH_PSLIST
190}; 190};
191 191
192#ifdef _KERNEL 192#ifdef _KERNEL
193#define COND_SET_STRUCT(dst, src, allow) \ 193#define COND_SET_STRUCT(dst, src, allow) \
194 do { \ 194 do { \
 195 /* \
 196 * Make sure we don't end up hashing/assigning large \
 197 * structure for performance. Upper-bound is arbitrary, \
 198 * but consider before bumping. \
 199 */ \
195 CTASSERT(sizeof(src) < 32); \ 200 CTASSERT(sizeof(src) < 32); \
196 if (allow) \ 201 if (allow) \
197 dst = src; \ 202 dst = src; \
198 else \ 203 else \
199 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \ 204 hash_value(&dst, sizeof(dst), &src, sizeof(src)); \
200 } while (/*CONSTCOND*/0) 205 } while (/*CONSTCOND*/0)
201 206
202#define COND_SET_CPTR(dst, src, allow) \ 207#define COND_SET_CPTR(dst, src, allow) \
203 do { \ 208 do { \
204 if (allow) \ 209 if (allow) \
205 dst = src; \ 210 dst = src; \
206 else { \ 211 else { \
207 void *__v; \ 212 void *__v; \