1*8329232eSGordon Ross /*
2*8329232eSGordon Ross  * Copyright (c) 2001 - 2012 Apple Inc. All rights reserved.
3*8329232eSGordon Ross  *
4*8329232eSGordon Ross  * @APPLE_LICENSE_HEADER_START@
5*8329232eSGordon Ross  *
6*8329232eSGordon Ross  * This file contains Original Code and/or Modifications of Original Code
7*8329232eSGordon Ross  * as defined in and that are subject to the Apple Public Source License
8*8329232eSGordon Ross  * Version 2.0 (the 'License'). You may not use this file except in
9*8329232eSGordon Ross  * compliance with the License. Please obtain a copy of the License at
10*8329232eSGordon Ross  * http://www.opensource.apple.com/apsl/ and read it before using this
11*8329232eSGordon Ross  * file.
12*8329232eSGordon Ross  *
13*8329232eSGordon Ross  * The Original Code and all software distributed under the License are
14*8329232eSGordon Ross  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15*8329232eSGordon Ross  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16*8329232eSGordon Ross  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17*8329232eSGordon Ross  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18*8329232eSGordon Ross  * Please see the License for the specific language governing rights and
19*8329232eSGordon Ross  * limitations under the License.
20*8329232eSGordon Ross  *
21*8329232eSGordon Ross  * @APPLE_LICENSE_HEADER_END@
22*8329232eSGordon Ross  */
234bff34e3Sthurlow 
244bff34e3Sthurlow /*
254bff34e3Sthurlow  * Code corresponding to smb_apple.h
264bff34e3Sthurlow  */
274bff34e3Sthurlow 
284bff34e3Sthurlow #ifndef _NETSMB_SMB_OSDEP_H_
294bff34e3Sthurlow #define	_NETSMB_SMB_OSDEP_H_
304bff34e3Sthurlow 
314bff34e3Sthurlow #ifndef PRIVSYM
32*8329232eSGordon Ross #define	PRIVSYM
334bff34e3Sthurlow #endif
344bff34e3Sthurlow 
354bff34e3Sthurlow #ifndef min
364bff34e3Sthurlow #define	min(a, b)	(((a) < (b)) ? (a) : (b))
374bff34e3Sthurlow #endif
384bff34e3Sthurlow 
394bff34e3Sthurlow #define	CAST_DOWN(type, addr)  (((type)((uintptr_t)(addr))))
404bff34e3Sthurlow #define	USER_ADDR_NULL  ((user_addr_t)0)
414bff34e3Sthurlow #define	CAST_USER_ADDR_T(a_ptr)   ((user_addr_t)(a_ptr))
424bff34e3Sthurlow 
434bff34e3Sthurlow /*
444bff34e3Sthurlow  * flags to (BSD) malloc
454bff34e3Sthurlow  */
464bff34e3Sthurlow #define	M_WAITOK	0x0000
474bff34e3Sthurlow #define	M_NOWAIT	0x0001
484bff34e3Sthurlow #define	M_ZERO		0x0004		/* bzero the allocation */
494bff34e3Sthurlow 
504bff34e3Sthurlow /* Iconv stuff */
514bff34e3Sthurlow 
524bff34e3Sthurlow /*
534bff34e3Sthurlow  * Some UTF Related stuff. Will be deleting this once compiled and using
544bff34e3Sthurlow  * ienup's code.
554bff34e3Sthurlow  */
564bff34e3Sthurlow /*
574bff34e3Sthurlow  * UTF-8 encode/decode flags
584bff34e3Sthurlow  */
594bff34e3Sthurlow #define	UTF_REVERSE_ENDIAN	0x01    /* reverse UCS-2 byte order */
604bff34e3Sthurlow #define	UTF_NO_NULL_TERM	0x02    /* do not add null termination */
614bff34e3Sthurlow #define	UTF_DECOMPOSED		0x04    /* generate fully decomposed UCS-2 */
624bff34e3Sthurlow #define	UTF_PRECOMPOSED		0x08    /* generate precomposed UCS-2 */
634bff34e3Sthurlow 
644bff34e3Sthurlow /*
654bff34e3Sthurlow  * These are actually included in sunddi.h. I am getting compilation
664bff34e3Sthurlow  * errors right now. Adding the induvidual defines here again from sunddi.h
674bff34e3Sthurlow  * Unicode encoding conversion functions and their macros.
684bff34e3Sthurlow  */
694bff34e3Sthurlow #define	UCONV_IN_BIG_ENDIAN		0x0001
704bff34e3Sthurlow #define	UCONV_OUT_BIG_ENDIAN		0x0002
714bff34e3Sthurlow #define	UCONV_IN_SYSTEM_ENDIAN		0x0004
724bff34e3Sthurlow #define	UCONV_OUT_SYSTEM_ENDIAN		0x0008
734bff34e3Sthurlow #define	UCONV_IN_LITTLE_ENDIAN		0x0010
744bff34e3Sthurlow #define	UCONV_OUT_LITTLE_ENDIAN		0x0020
754bff34e3Sthurlow #define	UCONV_IGNORE_NULL		0x0040
764bff34e3Sthurlow #define	UCONV_IN_ACCEPT_BOM		0x0080
774bff34e3Sthurlow #define	UCONV_OUT_EMIT_BOM		0x0100
784bff34e3Sthurlow 
794bff34e3Sthurlow extern int uconv_u8tou16(const uchar_t *, size_t *, uint16_t *, size_t *, int);
804bff34e3Sthurlow 
814bff34e3Sthurlow /* Legacy type names for Solaris. */
824bff34e3Sthurlow typedef uint64_t u_int64_t;
834bff34e3Sthurlow typedef uint32_t u_int32_t;
844bff34e3Sthurlow typedef uint16_t u_int16_t;
854bff34e3Sthurlow typedef uint8_t u_int8_t;
864bff34e3Sthurlow 
87*8329232eSGordon Ross typedef const char *c_caddr_t;
88*8329232eSGordon Ross typedef uint64_t	user_addr_t;
89*8329232eSGordon Ross typedef ssize_t		user_ssize_t;
90*8329232eSGordon Ross typedef size_t		user_size_t;
91*8329232eSGordon Ross 
92*8329232eSGordon Ross #ifdef _FAKE_KERNEL
93*8329232eSGordon Ross #define	ddi_get_cred()  CRED()
94*8329232eSGordon Ross #endif
954bff34e3Sthurlow 
964bff34e3Sthurlow /*
974bff34e3Sthurlow  * Time related calls.
984bff34e3Sthurlow  */
994bff34e3Sthurlow 
1004bff34e3Sthurlow /* BEGIN CSTYLED */
1014bff34e3Sthurlow #define	timespeccmp(tvp, uvp, cmp)                                      \
1024bff34e3Sthurlow 	(((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
103*8329232eSGordon Ross 	((tvp)->tv_nsec cmp (uvp)->tv_nsec) :				\
1044bff34e3Sthurlow 	((tvp)->tv_sec cmp (uvp)->tv_sec))
1054bff34e3Sthurlow /* END CSTYLED */
1064bff34e3Sthurlow 
1074bff34e3Sthurlow #define	timespecadd(vvp, uvp)						\
1084bff34e3Sthurlow 	{								\
1094bff34e3Sthurlow 		(vvp)->tv_sec += (uvp)->tv_sec;				\
1104bff34e3Sthurlow 		(vvp)->tv_nsec += (uvp)->tv_nsec;			\
1114bff34e3Sthurlow 		if ((vvp)->tv_nsec >= 1000000000) {			\
1124bff34e3Sthurlow 			(vvp)->tv_sec++;				\
1134bff34e3Sthurlow 			(vvp)->tv_nsec -= 1000000000;			\
1144bff34e3Sthurlow 		}							\
1154bff34e3Sthurlow 	}
1164bff34e3Sthurlow 
1174bff34e3Sthurlow #define	timespecsub(vvp, uvp)                                           \
1184bff34e3Sthurlow 	{								\
1194bff34e3Sthurlow 		(vvp)->tv_sec -= (uvp)->tv_sec;				\
1204bff34e3Sthurlow 		(vvp)->tv_nsec -= (uvp)->tv_nsec;			\
1214bff34e3Sthurlow 		if ((vvp)->tv_nsec < 0) {				\
1224bff34e3Sthurlow 			(vvp)->tv_sec--;				\
1234bff34e3Sthurlow 			(vvp)->tv_nsec += 1000000000;			\
1244bff34e3Sthurlow 		}							\
1254bff34e3Sthurlow 	}
1264bff34e3Sthurlow 
1274bff34e3Sthurlow #endif /* _NETSMB_SMB_OSDEP_H_ */
128