xref: /titanic_51/usr/src/uts/common/sys/sysmacros.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #ifndef _SYS_SYSMACROS_H
32*7c478bd9Sstevel@tonic-gate #define	_SYS_SYSMACROS_H
33*7c478bd9Sstevel@tonic-gate 
34*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
39*7c478bd9Sstevel@tonic-gate extern "C" {
40*7c478bd9Sstevel@tonic-gate #endif
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /*
43*7c478bd9Sstevel@tonic-gate  * Some macros for units conversion
44*7c478bd9Sstevel@tonic-gate  */
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * Disk blocks (sectors) and bytes.
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate #define	dtob(DD)	((DD) << DEV_BSHIFT)
49*7c478bd9Sstevel@tonic-gate #define	btod(BB)	(((BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
50*7c478bd9Sstevel@tonic-gate #define	btodt(BB)	((BB) >> DEV_BSHIFT)
51*7c478bd9Sstevel@tonic-gate #define	lbtod(BB)	(((offset_t)(BB) + DEV_BSIZE - 1) >> DEV_BSHIFT)
52*7c478bd9Sstevel@tonic-gate 
53*7c478bd9Sstevel@tonic-gate /* common macros */
54*7c478bd9Sstevel@tonic-gate #ifndef MIN
55*7c478bd9Sstevel@tonic-gate #define	MIN(a, b)	((a) < (b) ? (a) : (b))
56*7c478bd9Sstevel@tonic-gate #endif
57*7c478bd9Sstevel@tonic-gate #ifndef MAX
58*7c478bd9Sstevel@tonic-gate #define	MAX(a, b)	((a) < (b) ? (b) : (a))
59*7c478bd9Sstevel@tonic-gate #endif
60*7c478bd9Sstevel@tonic-gate #ifndef ABS
61*7c478bd9Sstevel@tonic-gate #define	ABS(a)		((a) < 0 ? -(a) : (a))
62*7c478bd9Sstevel@tonic-gate #endif
63*7c478bd9Sstevel@tonic-gate 
64*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate  * Convert a single byte to/from binary-coded decimal (BCD).
68*7c478bd9Sstevel@tonic-gate  */
69*7c478bd9Sstevel@tonic-gate extern unsigned char byte_to_bcd[256];
70*7c478bd9Sstevel@tonic-gate extern unsigned char bcd_to_byte[256];
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate #define	BYTE_TO_BCD(x)	byte_to_bcd[(x) & 0xff]
73*7c478bd9Sstevel@tonic-gate #define	BCD_TO_BYTE(x)	bcd_to_byte[(x) & 0xff]
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
76*7c478bd9Sstevel@tonic-gate 
77*7c478bd9Sstevel@tonic-gate /*
78*7c478bd9Sstevel@tonic-gate  * WARNING: The device number macros defined here should not be used by device
79*7c478bd9Sstevel@tonic-gate  * drivers or user software. Device drivers should use the device functions
80*7c478bd9Sstevel@tonic-gate  * defined in the DDI/DKI interface (see also ddi.h). Application software
81*7c478bd9Sstevel@tonic-gate  * should make use of the library routines available in makedev(3). A set of
82*7c478bd9Sstevel@tonic-gate  * new device macros are provided to operate on the expanded device number
83*7c478bd9Sstevel@tonic-gate  * format supported in SVR4. Macro versions of the DDI device functions are
84*7c478bd9Sstevel@tonic-gate  * provided for use by kernel proper routines only. Macro routines bmajor(),
85*7c478bd9Sstevel@tonic-gate  * major(), minor(), emajor(), eminor(), and makedev() will be removed or
86*7c478bd9Sstevel@tonic-gate  * their definitions changed at the next major release following SVR4.
87*7c478bd9Sstevel@tonic-gate  */
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate #define	O_BITSMAJOR	7	/* # of SVR3 major device bits */
90*7c478bd9Sstevel@tonic-gate #define	O_BITSMINOR	8	/* # of SVR3 minor device bits */
91*7c478bd9Sstevel@tonic-gate #define	O_MAXMAJ	0x7f	/* SVR3 max major value */
92*7c478bd9Sstevel@tonic-gate #define	O_MAXMIN	0xff	/* SVR3 max minor value */
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR32	14	/* # of SVR4 major device bits */
96*7c478bd9Sstevel@tonic-gate #define	L_BITSMINOR32	18	/* # of SVR4 minor device bits */
97*7c478bd9Sstevel@tonic-gate #define	L_MAXMAJ32	0x3fff	/* SVR4 max major value */
98*7c478bd9Sstevel@tonic-gate #define	L_MAXMIN32	0x3ffff	/* MAX minor for 3b2 software drivers. */
99*7c478bd9Sstevel@tonic-gate 				/* For 3b2 hardware devices the minor is */
100*7c478bd9Sstevel@tonic-gate 				/* restricted to 256 (0-255) */
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate #ifdef _LP64
103*7c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR	32	/* # of major device bits in 64-bit Solaris */
104*7c478bd9Sstevel@tonic-gate #define	L_BITSMINOR	32	/* # of minor device bits in 64-bit Solaris */
105*7c478bd9Sstevel@tonic-gate #define	L_MAXMAJ	0xfffffffful	/* max major value */
106*7c478bd9Sstevel@tonic-gate #define	L_MAXMIN	0xfffffffful	/* max minor value */
107*7c478bd9Sstevel@tonic-gate #else
108*7c478bd9Sstevel@tonic-gate #define	L_BITSMAJOR	L_BITSMAJOR32
109*7c478bd9Sstevel@tonic-gate #define	L_BITSMINOR	L_BITSMINOR32
110*7c478bd9Sstevel@tonic-gate #define	L_MAXMAJ	L_MAXMAJ32
111*7c478bd9Sstevel@tonic-gate #define	L_MAXMIN	L_MAXMIN32
112*7c478bd9Sstevel@tonic-gate #endif
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /* major part of a device internal to the kernel */
117*7c478bd9Sstevel@tonic-gate 
118*7c478bd9Sstevel@tonic-gate #define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
119*7c478bd9Sstevel@tonic-gate #define	bmajor(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate /* get internal major part of expanded device number */
122*7c478bd9Sstevel@tonic-gate 
123*7c478bd9Sstevel@tonic-gate #define	getmajor(x)	(major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate /* minor part of a device internal to the kernel */
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate #define	minor(x)	(minor_t)((x) & O_MAXMIN)
128*7c478bd9Sstevel@tonic-gate 
129*7c478bd9Sstevel@tonic-gate /* get internal minor part of expanded device number */
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate #define	getminor(x)	(minor_t)((x) & L_MAXMIN)
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate #else
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate /* major part of a device external from the kernel (same as emajor below) */
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate #define	major(x)	(major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate /* minor part of a device external from the kernel  (same as eminor below) */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate #define	minor(x)	(minor_t)((x) & O_MAXMIN)
142*7c478bd9Sstevel@tonic-gate 
143*7c478bd9Sstevel@tonic-gate #endif	/* _KERNEL */
144*7c478bd9Sstevel@tonic-gate 
145*7c478bd9Sstevel@tonic-gate /* create old device number */
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate #define	makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN))
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate /* make an new device number */
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate #define	makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate /*
155*7c478bd9Sstevel@tonic-gate  * emajor() allows kernel/driver code to print external major numbers
156*7c478bd9Sstevel@tonic-gate  * eminor() allows kernel/driver code to print external minor numbers
157*7c478bd9Sstevel@tonic-gate  */
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate #define	emajor(x) \
160*7c478bd9Sstevel@tonic-gate 	(major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \
161*7c478bd9Sstevel@tonic-gate 	    NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ)
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate #define	eminor(x) \
164*7c478bd9Sstevel@tonic-gate 	(minor_t)((x) & O_MAXMIN)
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate /*
167*7c478bd9Sstevel@tonic-gate  * get external major and minor device
168*7c478bd9Sstevel@tonic-gate  * components from expanded device number
169*7c478bd9Sstevel@tonic-gate  */
170*7c478bd9Sstevel@tonic-gate #define	getemajor(x)	(major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
171*7c478bd9Sstevel@tonic-gate 			    NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
172*7c478bd9Sstevel@tonic-gate #define	geteminor(x)	(minor_t)((x) & L_MAXMIN)
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate /*
175*7c478bd9Sstevel@tonic-gate  * These are versions of the kernel routines for compressing and
176*7c478bd9Sstevel@tonic-gate  * expanding long device numbers that don't return errors.
177*7c478bd9Sstevel@tonic-gate  */
178*7c478bd9Sstevel@tonic-gate #if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate #define	DEVCMPL(x)	(x)
181*7c478bd9Sstevel@tonic-gate #define	DEVEXPL(x)	(x)
182*7c478bd9Sstevel@tonic-gate 
183*7c478bd9Sstevel@tonic-gate #else
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate #define	DEVCMPL(x)	\
186*7c478bd9Sstevel@tonic-gate 	(dev32_t)((((x) >> L_BITSMINOR) > L_MAXMAJ32 || \
187*7c478bd9Sstevel@tonic-gate 	    ((x) & L_MAXMIN) > L_MAXMIN32) ? NODEV32 : \
188*7c478bd9Sstevel@tonic-gate 	    ((((x) >> L_BITSMINOR) << L_BITSMINOR32) | ((x) & L_MAXMIN32)))
189*7c478bd9Sstevel@tonic-gate 
190*7c478bd9Sstevel@tonic-gate #define	DEVEXPL(x)	\
191*7c478bd9Sstevel@tonic-gate 	(((x) == NODEV32) ? NODEV : \
192*7c478bd9Sstevel@tonic-gate 	makedevice(((x) >> L_BITSMINOR32) & L_MAXMAJ32, (x) & L_MAXMIN32))
193*7c478bd9Sstevel@tonic-gate 
194*7c478bd9Sstevel@tonic-gate #endif /* L_BITSMAJOR32 ... */
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate /* convert to old (SVR3.2) dev format */
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate #define	cmpdev(x) \
199*7c478bd9Sstevel@tonic-gate 	(o_dev_t)((((x) >> L_BITSMINOR) > O_MAXMAJ || \
200*7c478bd9Sstevel@tonic-gate 	    ((x) & L_MAXMIN) > O_MAXMIN) ? NODEV : \
201*7c478bd9Sstevel@tonic-gate 	    ((((x) >> L_BITSMINOR) << O_BITSMINOR) | ((x) & O_MAXMIN)))
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate /* convert to new (SVR4) dev format */
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate #define	expdev(x) \
206*7c478bd9Sstevel@tonic-gate 	(dev_t)(((dev_t)(((x) >> O_BITSMINOR) & O_MAXMAJ) << L_BITSMINOR) | \
207*7c478bd9Sstevel@tonic-gate 	    ((x) & O_MAXMIN))
208*7c478bd9Sstevel@tonic-gate 
209*7c478bd9Sstevel@tonic-gate /*
210*7c478bd9Sstevel@tonic-gate  * Macro for checking power of 2 address alignment.
211*7c478bd9Sstevel@tonic-gate  */
212*7c478bd9Sstevel@tonic-gate #define	IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate /*
215*7c478bd9Sstevel@tonic-gate  * Macros for counting and rounding.
216*7c478bd9Sstevel@tonic-gate  */
217*7c478bd9Sstevel@tonic-gate #define	howmany(x, y)	(((x)+((y)-1))/(y))
218*7c478bd9Sstevel@tonic-gate #define	roundup(x, y)	((((x)+((y)-1))/(y))*(y))
219*7c478bd9Sstevel@tonic-gate 
220*7c478bd9Sstevel@tonic-gate /*
221*7c478bd9Sstevel@tonic-gate  * Macro to determine if value is a power of 2
222*7c478bd9Sstevel@tonic-gate  */
223*7c478bd9Sstevel@tonic-gate #define	ISP2(x)		(((x) & ((x) - 1)) == 0)
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate /*
226*7c478bd9Sstevel@tonic-gate  * Macros for various sorts of alignment and rounding when the alignment
227*7c478bd9Sstevel@tonic-gate  * is known to be a power of 2.
228*7c478bd9Sstevel@tonic-gate  */
229*7c478bd9Sstevel@tonic-gate #define	P2ALIGN(x, align)		((x) & -(align))
230*7c478bd9Sstevel@tonic-gate #define	P2PHASE(x, align)		((x) & ((align) - 1))
231*7c478bd9Sstevel@tonic-gate #define	P2NPHASE(x, align)		(-(x) & ((align) - 1))
232*7c478bd9Sstevel@tonic-gate #define	P2ROUNDUP(x, align)		(-(-(x) & -(align)))
233*7c478bd9Sstevel@tonic-gate #define	P2END(x, align)			(-(~(x) & -(align)))
234*7c478bd9Sstevel@tonic-gate #define	P2PHASEUP(x, align, phase)	((phase) - (((phase) - (x)) & -(align)))
235*7c478bd9Sstevel@tonic-gate #define	P2CROSS(x, y, align)		(((x) ^ (y)) > (align) - 1)
236*7c478bd9Sstevel@tonic-gate /*
237*7c478bd9Sstevel@tonic-gate  * Determine whether two numbers have the same high-order bit.
238*7c478bd9Sstevel@tonic-gate  */
239*7c478bd9Sstevel@tonic-gate #define	P2SAMEHIGHBIT(x, y)		(((x) ^ (y)) < ((x) & (y)))
240*7c478bd9Sstevel@tonic-gate 
241*7c478bd9Sstevel@tonic-gate /*
242*7c478bd9Sstevel@tonic-gate  * Typed version of the P2* macros.  These macros should be used to ensure
243*7c478bd9Sstevel@tonic-gate  * that the result is correctly calculated based on the data type of (x),
244*7c478bd9Sstevel@tonic-gate  * which is passed in as the last argument, regardless of the data
245*7c478bd9Sstevel@tonic-gate  * type of the alignment.  For example, if (x) is of type uint64_t,
246*7c478bd9Sstevel@tonic-gate  * and we want to round it up to a page boundary using "PAGESIZE" as
247*7c478bd9Sstevel@tonic-gate  * the alignment, we can do either
248*7c478bd9Sstevel@tonic-gate  *	P2ROUNDUP(x, (uint64_t)PAGESIZE)
249*7c478bd9Sstevel@tonic-gate  * or
250*7c478bd9Sstevel@tonic-gate  *	P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
251*7c478bd9Sstevel@tonic-gate  */
252*7c478bd9Sstevel@tonic-gate #define	P2ALIGN_TYPED(x, align, type)	\
253*7c478bd9Sstevel@tonic-gate 	((type)(x) & -(type)(align))
254*7c478bd9Sstevel@tonic-gate #define	P2PHASE_TYPED(x, align, type)	\
255*7c478bd9Sstevel@tonic-gate 	((type)(x) & ((type)(align) - 1))
256*7c478bd9Sstevel@tonic-gate #define	P2NPHASE_TYPED(x, align, type)	\
257*7c478bd9Sstevel@tonic-gate 	(-(type)(x) & ((type)(align) - 1))
258*7c478bd9Sstevel@tonic-gate #define	P2ROUNDUP_TYPED(x, align, type)	\
259*7c478bd9Sstevel@tonic-gate 	(-(-(type)(x) & -(type)(align)))
260*7c478bd9Sstevel@tonic-gate #define	P2END_TYPED(x, align, type)	\
261*7c478bd9Sstevel@tonic-gate 	(-(~(type)(x) & -(type)(align)))
262*7c478bd9Sstevel@tonic-gate #define	P2PHASEUP_TYPED(x, align, phase, type)	\
263*7c478bd9Sstevel@tonic-gate 	((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
264*7c478bd9Sstevel@tonic-gate #define	P2CROSS_TYPED(x, y, align, type)	\
265*7c478bd9Sstevel@tonic-gate 	(((type)(x) ^ (type)(y)) > (type)(align) - 1)
266*7c478bd9Sstevel@tonic-gate #define	P2SAMEHIGHBIT_TYPED(x, y, type) \
267*7c478bd9Sstevel@tonic-gate 	(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate /*
270*7c478bd9Sstevel@tonic-gate  * Macros to atomically increment/decrement a variable.  mutex and var
271*7c478bd9Sstevel@tonic-gate  * must be pointers.
272*7c478bd9Sstevel@tonic-gate  */
273*7c478bd9Sstevel@tonic-gate #define	INCR_COUNT(var, mutex) mutex_enter(mutex), (*(var))++, mutex_exit(mutex)
274*7c478bd9Sstevel@tonic-gate #define	DECR_COUNT(var, mutex) mutex_enter(mutex), (*(var))--, mutex_exit(mutex)
275*7c478bd9Sstevel@tonic-gate 
276*7c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_KMEMUSER) && !defined(offsetof)
277*7c478bd9Sstevel@tonic-gate 
278*7c478bd9Sstevel@tonic-gate /* avoid any possibility of clashing with <stddef.h> version */
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate #define	offsetof(s, m)	((size_t)(&(((s *)0)->m)))
281*7c478bd9Sstevel@tonic-gate #endif
282*7c478bd9Sstevel@tonic-gate 
283*7c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
284*7c478bd9Sstevel@tonic-gate }
285*7c478bd9Sstevel@tonic-gate #endif
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate #endif	/* _SYS_SYSMACROS_H */
288