1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22 /*	  All Rights Reserved	*/
23 
24 /*
25  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  *
28  * Copyright (c) 2016 by Delphix. All rights reserved.
29  * Copyright 2017 Nexenta Systems, Inc.  All rights reserved.
30  * Copyright 2022 Garrett D'Amore
31  */
32 
33 #include <sys/types.h>
34 #include <sys/param.h>
35 
36 #include <sys/atomic.h>
37 #include <sys/stream.h>
38 #include <sys/strsubr.h>
39 #include <sys/cmn_err.h>
40 
41 #include <sys/strft.h>
42 
43 int str_ftnever = 0;
44 
45 static void mblk_free(mblk_t *);
46 static void esballoc_mblk_free(mblk_t *);
47 
48 /*
49  * A few things from os/strsubr.c
50  */
51 
52 int
strwaitbuf(size_t size,int pri)53 strwaitbuf(size_t size, int pri)
54 {
55 	return (0);
56 }
57 
58 /*
59  * Return size of message of block type (bp->b_datap->db_type)
60  */
61 size_t
xmsgsize(mblk_t * bp)62 xmsgsize(mblk_t *bp)
63 {
64 	unsigned char type;
65 	size_t count = 0;
66 
67 	type = bp->b_datap->db_type;
68 
69 	for (; bp; bp = bp->b_cont) {
70 		if (type != bp->b_datap->db_type)
71 			break;
72 		ASSERT(bp->b_wptr >= bp->b_rptr);
73 		count += bp->b_wptr - bp->b_rptr;
74 	}
75 	return (count);
76 }
77 
78 /* ARGSUSED */
79 bufcall_id_t
bufcall(size_t size,uint_t pri,void (* func)(void *),void * arg)80 bufcall(size_t size, uint_t pri, void (*func)(void *), void *arg)
81 {
82 	cmn_err(CE_NOTE, "bufcall() called!");
83 	return ("fake bufcall id");
84 }
85 
86 /* ARGSUSED */
87 void
unbufcall(bufcall_id_t id)88 unbufcall(bufcall_id_t id)
89 {
90 }
91 
92 /* ARGSUSED */
93 void
freebs_enqueue(mblk_t * mp,dblk_t * dbp)94 freebs_enqueue(mblk_t *mp, dblk_t *dbp)
95 {
96 	/*
97 	 * Won't bother with esb_queue_t async free here.
98 	 * Rather just free this mblk directly.
99 	 */
100 	esballoc_mblk_free(mp);
101 }
102 
103 static void
esballoc_mblk_free(mblk_t * mp)104 esballoc_mblk_free(mblk_t *mp)
105 {
106 	mblk_t	*nextmp;
107 
108 	for (; mp != NULL; mp = nextmp) {
109 		nextmp = mp->b_next;
110 		mp->b_next = NULL;
111 		mblk_free(mp);
112 	}
113 }
114 
115 static void
mblk_free(mblk_t * mp)116 mblk_free(mblk_t *mp)
117 {
118 	dblk_t *dbp = mp->b_datap;
119 	frtn_t *frp = dbp->db_frtnp;
120 
121 	mp->b_next = NULL;
122 	if (dbp->db_fthdr != NULL)
123 		str_ftfree(dbp);
124 
125 	ASSERT(dbp->db_fthdr == NULL);
126 	frp->free_func(frp->free_arg);
127 	ASSERT(dbp->db_mblk == mp);
128 
129 	if (dbp->db_credp != NULL) {
130 		crfree(dbp->db_credp);
131 		dbp->db_credp = NULL;
132 	}
133 	dbp->db_cpid = -1;
134 	dbp->db_struioflag = 0;
135 	dbp->db_struioun.cksum.flags = 0;
136 
137 	kmem_cache_free(dbp->db_cache, dbp);
138 }
139 
140 /*
141  * A little bit from os/streamio.c
142  */
143 
144 static volatile uint32_t ioc_id;
145 
146 int
getiocseqno(void)147 getiocseqno(void)
148 {
149 	uint32_t i;
150 
151 	i = atomic_inc_32_nv(&ioc_id);
152 
153 	return ((int)i);
154 }
155