xref: /illumos-gate/usr/src/uts/common/fs/smbclnt/netsmb/smb_osdep.h (revision ed093b41a93e8563e6e1e5dae0768dda2a7bcc27)
1 /*
2  * Copyright (c) 2001 - 2012 Apple Inc. All rights reserved.
3  *
4  * @APPLE_LICENSE_HEADER_START@
5  *
6  * This file contains Original Code and/or Modifications of Original Code
7  * as defined in and that are subject to the Apple Public Source License
8  * Version 2.0 (the 'License'). You may not use this file except in
9  * compliance with the License. Please obtain a copy of the License at
10  * http://www.opensource.apple.com/apsl/ and read it before using this
11  * file.
12  *
13  * The Original Code and all software distributed under the License are
14  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18  * Please see the License for the specific language governing rights and
19  * limitations under the License.
20  *
21  * @APPLE_LICENSE_HEADER_END@
22  */
23 
24 /*
25  * Code corresponding to smb_apple.h
26  */
27 
28 #ifndef _NETSMB_SMB_OSDEP_H_
29 #define	_NETSMB_SMB_OSDEP_H_
30 
31 #ifndef PRIVSYM
32 #define	PRIVSYM
33 #endif
34 
35 #ifndef min
36 #define	min(a, b)	(((a) < (b)) ? (a) : (b))
37 #endif
38 
39 #define	CAST_DOWN(type, addr)  (((type)((uintptr_t)(addr))))
40 #define	USER_ADDR_NULL  ((user_addr_t)0)
41 #define	CAST_USER_ADDR_T(a_ptr)   ((user_addr_t)(a_ptr))
42 
43 /*
44  * flags to (BSD) malloc
45  */
46 #define	M_WAITOK	0x0000
47 #define	M_NOWAIT	0x0001
48 #define	M_ZERO		0x0004		/* bzero the allocation */
49 
50 /* Iconv stuff */
51 
52 /*
53  * Some UTF Related stuff. Will be deleting this once compiled and using
54  * ienup's code.
55  */
56 /*
57  * UTF-8 encode/decode flags
58  */
59 #define	UTF_REVERSE_ENDIAN	0x01    /* reverse UCS-2 byte order */
60 #define	UTF_NO_NULL_TERM	0x02    /* do not add null termination */
61 #define	UTF_DECOMPOSED		0x04    /* generate fully decomposed UCS-2 */
62 #define	UTF_PRECOMPOSED		0x08    /* generate precomposed UCS-2 */
63 
64 /*
65  * These are actually included in sunddi.h. I am getting compilation
66  * errors right now. Adding the induvidual defines here again from sunddi.h
67  * Unicode encoding conversion functions and their macros.
68  */
69 #define	UCONV_IN_BIG_ENDIAN		0x0001
70 #define	UCONV_OUT_BIG_ENDIAN		0x0002
71 #define	UCONV_IN_SYSTEM_ENDIAN		0x0004
72 #define	UCONV_OUT_SYSTEM_ENDIAN		0x0008
73 #define	UCONV_IN_LITTLE_ENDIAN		0x0010
74 #define	UCONV_OUT_LITTLE_ENDIAN		0x0020
75 #define	UCONV_IGNORE_NULL		0x0040
76 #define	UCONV_IN_ACCEPT_BOM		0x0080
77 #define	UCONV_OUT_EMIT_BOM		0x0100
78 
79 extern int uconv_u8tou16(const uchar_t *, size_t *, uint16_t *, size_t *, int);
80 
81 /* Legacy type names for Solaris. */
82 typedef uint64_t u_int64_t;
83 typedef uint32_t u_int32_t;
84 typedef uint16_t u_int16_t;
85 typedef uint8_t u_int8_t;
86 
87 typedef const char *c_caddr_t;
88 typedef uint64_t	user_addr_t;
89 typedef ssize_t		user_ssize_t;
90 typedef size_t		user_size_t;
91 
92 #ifdef _FAKE_KERNEL
93 #define	ddi_get_cred()  CRED()
94 #endif
95 
96 /*
97  * Time related calls.
98  */
99 
100 /* BEGIN CSTYLED */
101 #define	timespeccmp(tvp, uvp, cmp)                                      \
102 	(((tvp)->tv_sec == (uvp)->tv_sec) ?                             \
103 	((tvp)->tv_nsec cmp (uvp)->tv_nsec) :				\
104 	((tvp)->tv_sec cmp (uvp)->tv_sec))
105 /* END CSTYLED */
106 
107 #define	timespecadd(vvp, uvp)						\
108 	{								\
109 		(vvp)->tv_sec += (uvp)->tv_sec;				\
110 		(vvp)->tv_nsec += (uvp)->tv_nsec;			\
111 		if ((vvp)->tv_nsec >= 1000000000) {			\
112 			(vvp)->tv_sec++;				\
113 			(vvp)->tv_nsec -= 1000000000;			\
114 		}							\
115 	}
116 
117 #define	timespecsub(vvp, uvp)                                           \
118 	{								\
119 		(vvp)->tv_sec -= (uvp)->tv_sec;				\
120 		(vvp)->tv_nsec -= (uvp)->tv_nsec;			\
121 		if ((vvp)->tv_nsec < 0) {				\
122 			(vvp)->tv_sec--;				\
123 			(vvp)->tv_nsec += 1000000000;			\
124 		}							\
125 	}
126 
127 #endif /* _NETSMB_SMB_OSDEP_H_ */
128